Skip to content

Commit 7d81113

Browse files
author
jantje
committed
#1126 only deps need to be added to output file
1 parent c10c4eb commit 7d81113

File tree

4 files changed

+74
-79
lines changed

4 files changed

+74
-79
lines changed

io.sloeber.core/plugin.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
dependencyContentType="org.eclipse.cdt.core.cxxHeader"
187187
id="io.sloeber.compiler.cpp.sketch.input"
188188
name="%inputType.CPP.name"
189-
primaryInput="false"
189+
primaryInput="true"
190190
sourceContentType="org.eclipse.cdt.core.cxxSource">
191191
</inputType>
192192
<outputType
@@ -234,7 +234,7 @@
234234
id="io.sloeber.compiler.c.sketch.input"
235235
multipleOfType="false"
236236
name="%inputType.C.name"
237-
primaryInput="false"
237+
primaryInput="true"
238238
sourceContentType="org.eclipse.cdt.core.cSource">
239239
</inputType>
240240
<outputType
@@ -317,7 +317,6 @@
317317
primaryOutput="true">
318318
</outputType>
319319
<inputType
320-
assignToOption="OBJECT_FILE"
321320
buildVariable="AR_OBJ"
322321
id="io.sloeber.tool.archiver.input"
323322
multipleOfType="true"

io.sloeber.core/src/io/sloeber/managedBuild/Internal/MakeRule.java

+61-68
Original file line numberDiff line numberDiff line change
@@ -30,103 +30,128 @@
3030
import org.eclipse.cdt.managedbuilder.makegen.IManagedDependencyInfo;
3131
import org.eclipse.core.resources.IFile;
3232
import org.eclipse.core.resources.IProject;
33+
import org.eclipse.core.runtime.IPath;
3334

3435
public class MakeRule {
3536

36-
Map<IOutputType, List<IFile>> targets = new HashMap<>(); //Macro file target map
37-
Map<IInputType, List<IFile>> prerequisites = new HashMap<>();//Macro file prerequisites map
38-
ITool tool = null;
37+
private Map<IOutputType, List<IFile>> myTargets = new HashMap<>(); //Macro file target map
38+
private Map<IInputType, List<IFile>> myPrerequisites = new HashMap<>();//Macro file prerequisites map
39+
private Map<String, List<IFile>> myDependencies = new HashMap<>(); //Macro file target map
40+
private ITool myTool = null;
41+
42+
public MakeRule(ITool tool, IInputType inputType, IFile inputFile, IOutputType outputType, IFile outFile) {
43+
addPrerequisite(inputType, inputFile);
44+
addTarget(outputType, outFile);
45+
myTool = tool;
46+
calculateDependencies();
47+
}
48+
49+
private void calculateDependencies() {
50+
myDependencies.clear();
51+
//TOFIX the stuff below should be calculated
52+
boolean toolGeneratesDependencyFiles = true;
53+
if (!toolGeneratesDependencyFiles) {
54+
return;
55+
}
56+
IPath[] deps = myTool.getAdditionalDependencies();
57+
58+
}
3959

4060
public HashSet<IFile> getPrerequisites() {
4161
HashSet<IFile> ret = new HashSet<>();
42-
for (List<IFile> cur : prerequisites.values()) {
62+
for (List<IFile> cur : myPrerequisites.values()) {
4363
ret.addAll(cur);
4464
}
4565
return ret;
4666
}
4767

4868
public HashSet<IFile> getTargets() {
4969
HashSet<IFile> ret = new HashSet<>();
50-
for (List<IFile> cur : targets.values()) {
70+
for (List<IFile> cur : myTargets.values()) {
5171
ret.addAll(cur);
5272
}
5373
return ret;
5474
}
5575

5676
public HashSet<String> getMacros() {
5777
HashSet<String> ret = new HashSet<>();
58-
for (IOutputType cur : targets.keySet()) {
78+
for (IOutputType cur : myTargets.keySet()) {
5979
ret.add(cur.getBuildVariable());
6080
}
61-
for (IInputType cur : prerequisites.keySet()) {
81+
for (IInputType cur : myPrerequisites.keySet()) {
6282
ret.add(cur.getBuildVariable());
6383
}
84+
for (String cur : myDependencies.keySet()) {
85+
ret.add(cur);
86+
}
6487
return ret;
6588
}
6689

6790
public HashSet<IFile> getMacroElements(String macroName) {
6891
HashSet<IFile> ret = new HashSet<>();
6992

70-
for (Entry<IOutputType, List<IFile>> cur : targets.entrySet()) {
93+
for (Entry<IOutputType, List<IFile>> cur : myTargets.entrySet()) {
7194
if (macroName.equals(cur.getKey().getBuildVariable())) {
7295
ret.addAll(cur.getValue());
7396
}
7497
}
75-
for (Entry<IInputType, List<IFile>> cur : prerequisites.entrySet()) {
98+
for (Entry<IInputType, List<IFile>> cur : myPrerequisites.entrySet()) {
7699
if (macroName.equals(cur.getKey().getBuildVariable())) {
77100
ret.addAll(cur.getValue());
78101
}
79102
}
103+
List<IFile> tmp = myDependencies.get(macroName);
104+
if (tmp != null) {
105+
ret.addAll(tmp);
106+
}
80107
return ret;
81108
}
82109

83-
public void addTarget(IOutputType outputType, IFile file) {
84-
List<IFile> files = targets.get(outputType);
110+
private void addTarget(IOutputType outputType, IFile file) {
111+
List<IFile> files = myTargets.get(outputType);
85112
if (files == null) {
86113
files = new LinkedList<>();
87114
files.add(file);
88-
targets.put(outputType, files);
115+
myTargets.put(outputType, files);
89116
} else {
90117
files.add(file);
91118
}
92119
}
93120

94-
public void addPrerequisite(IInputType inputType, IFile file) {
95-
List<IFile> files = prerequisites.get(inputType);
121+
private void addPrerequisite(IInputType inputType, IFile file) {
122+
List<IFile> files = myPrerequisites.get(inputType);
96123
if (files == null) {
97124
files = new LinkedList<>();
98125
files.add(file);
99-
prerequisites.put(inputType, files);
126+
myPrerequisites.put(inputType, files);
100127
} else {
101128
files.add(file);
102129
}
103130
}
104131

105132
private String enumTargets(IFile buildFolder) {
106133
String ret = new String();
107-
for (List<IFile> curFiles : targets.values()) {
134+
for (List<IFile> curFiles : myTargets.values()) {
108135
for (IFile curFile : curFiles) {
109136
ret = ret + GetNiceFileName(buildFolder, curFile) + WHITESPACE;
110137
}
111138
}
112139
return ret;
113-
//return StringUtils.join(targets.values(), WHITESPACE);
114140
}
115141

116142
private String enumPrerequisites(IFile buildFolder) {
117143
String ret = new String();
118-
for (List<IFile> curFiles : prerequisites.values()) {
144+
for (List<IFile> curFiles : myPrerequisites.values()) {
119145
for (IFile curFile : curFiles) {
120146
ret = ret + GetNiceFileName(buildFolder, curFile) + WHITESPACE;
121147
}
122148
}
123149
return ret;
124-
// return StringUtils.join(prerequisites.values(), WHITESPACE);
125150
}
126151

127152
public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfiguration config) {
128153

129-
String cmd = tool.getToolCommand();
154+
String cmd = myTool.getToolCommand();
130155
//For now assume 1 target with 1 or more prerequisites
131156
// if there is more than 1 prerequisite we take the flags of the first prerequisite only
132157
HashSet<IFile> local_targets = getTargets();
@@ -158,17 +183,17 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
158183
boolean needExplicitDependencyCommands = false;
159184
boolean resourceNameRequiresExplicitRule = containsSpecialCharacters(sourceLocation.getLocation().toOSString());
160185
needExplicitRuleForFile = resourceNameRequiresExplicitRule
161-
|| BuildMacroProvider.getReferencedExplitFileMacros(tool).length > 0
186+
|| BuildMacroProvider.getReferencedExplitFileMacros(myTool).length > 0
162187
|| BuildMacroProvider.getReferencedExplitFileMacros(cmd, IBuildMacroProvider.CONTEXT_FILE,
163188
new FileContextData(sourceLocation.getFullPath(), outputLocation.getFullPath(), null,
164-
tool)).length > 0;
189+
myTool)).length > 0;
165190

166-
String outflag = tool.getOutputFlag();
191+
String outflag = myTool.getOutputFlag();
167192
String buildCmd = cmd + WHITESPACE + flags.toString().trim() + WHITESPACE + outflag + WHITESPACE
168-
+ tool.getOutputPrefix() + OUT_MACRO + otherPrimaryOutputs + WHITESPACE + IN_MACRO;
193+
+ myTool.getOutputPrefix() + OUT_MACRO + otherPrimaryOutputs + WHITESPACE + IN_MACRO;
169194
if (needExplicitRuleForFile || needExplicitDependencyCommands) {
170195
buildCmd = expandCommandLinePattern(cmd, flags, outflag, OUT_MACRO + otherPrimaryOutputs, niceNameList,
171-
getToolCommandLinePattern(config, tool));
196+
getToolCommandLinePattern(config, myTool));
172197
} else {
173198
buildCmd = expandCommandLinePattern(config, inputExtension, flags, outflag, OUT_MACRO + otherPrimaryOutputs,
174199
niceNameList, sourceLocation, outputLocation);
@@ -181,13 +206,13 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
181206
if (!needExplicitRuleForFile) {
182207
resolvedCommand = provider.resolveValueToMakefileFormat(buildCmd, EMPTY_STRING, WHITESPACE,
183208
IBuildMacroProvider.CONTEXT_FILE,
184-
new FileContextData(sourceLocation.getFullPath(), outputLocation.getFullPath(), null, tool));
209+
new FileContextData(sourceLocation.getFullPath(), outputLocation.getFullPath(), null, myTool));
185210
} else {
186211
// if we need an explicit rule then don't use any builder
187212
// variables, resolve everything to explicit strings
188213
resolvedCommand = provider.resolveValue(buildCmd, EMPTY_STRING, WHITESPACE,
189214
IBuildMacroProvider.CONTEXT_FILE,
190-
new FileContextData(sourceLocation.getFullPath(), outputLocation.getFullPath(), null, tool));
215+
new FileContextData(sourceLocation.getFullPath(), outputLocation.getFullPath(), null, myTool));
191216
}
192217
if (!resolvedCommand.isBlank())
193218
buildCmd = resolvedCommand.trim();
@@ -199,7 +224,7 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
199224
buffer.append(enumTargets(niceBuildFolder)).append(COLON).append(WHITESPACE);
200225
buffer.append(enumPrerequisites(niceBuildFolder)).append(NEWLINE);
201226
buffer.append(TAB).append(AT).append(escapedEcho(MESSAGE_START_FILE + WHITESPACE + IN_MACRO));
202-
buffer.append(TAB).append(AT).append(escapedEcho(tool.getAnnouncement()));
227+
buffer.append(TAB).append(AT).append(escapedEcho(myTool.getAnnouncement()));
203228

204229
// JABA add sketch.prebuild and postbouild if needed
205230
//TOFIX this should not be here
@@ -221,38 +246,6 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
221246
}
222247
// end JABA add sketch.prebuild and postbouild if needed
223248

224-
// Determine if there are any dependencies to calculate
225-
// if (doDepGen) {
226-
// // Get the dependency rule out of the generator
227-
// String[] depCmds = null;
228-
// if (depCommands != null) {
229-
// depCmds = depCommands.getPostToolDependencyCommands();
230-
// }
231-
// if (depCmds != null) {
232-
// for (String depCmd : depCmds) {
233-
// // Resolve any macros in the dep command after it has
234-
// // been generated.
235-
// // Note: do not trim the result because it will strip
236-
// // out necessary tab characters.
237-
// buffer.append(WHITESPACE).append(LOGICAL_AND).append(WHITESPACE).append(LINEBREAK);
238-
// try {
239-
// if (!needExplicitRuleForFile) {
240-
// depCmd = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(depCmd,
241-
// EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE,
242-
// new FileContextData(sourceLocation, outputLocation, null, tool));
243-
// } else {
244-
// depCmd = ManagedBuildManager.getBuildMacroProvider().resolveValue(depCmd, EMPTY_STRING,
245-
// WHITESPACE, IBuildMacroProvider.CONTEXT_FILE,
246-
// new FileContextData(sourceLocation, outputLocation, null, tool));
247-
// }
248-
// } catch (BuildMacroException e) {
249-
// /* JABA is not going to do this */
250-
// }
251-
// buffer.append(depCmd);
252-
// }
253-
// }
254-
// }
255-
// Echo finished message
256249
buffer.append(NEWLINE);
257250
buffer.append(TAB).append(AT).append(escapedEcho(MESSAGE_FINISH_FILE + WHITESPACE + IN_MACRO));
258251
buffer.append(TAB).append(AT).append(ECHO_BLANK_LINE).append(NEWLINE);
@@ -265,16 +258,16 @@ private Set<String> getBuildFlags(IFile buildFolder, IConfiguration config, IFil
265258
try {
266259

267260
IResourceInfo buildContext = config.getResourceInfo(sourceFile.getFullPath().removeLastSegments(1), false);
268-
flags.addAll(Arrays.asList(tool.getToolCommandFlags(sourceFile.getLocation(), outputFile.getLocation())));
261+
flags.addAll(Arrays.asList(myTool.getToolCommandFlags(sourceFile.getLocation(), outputFile.getLocation())));
269262

270-
IInputType[] inputTypes = tool.getInputTypes(); //.getDependencyGeneratorForExtension(inputExtension);
263+
IInputType[] inputTypes = myTool.getInputTypes(); //.getDependencyGeneratorForExtension(inputExtension);
271264
for (IInputType inputType : inputTypes) {
272265
IManagedDependencyGeneratorType t = inputType.getDependencyGenerator();
273266
if (t != null) {
274267
if (t.getCalculatorType() == IManagedDependencyGeneratorType.TYPE_BUILD_COMMANDS) {
275268
IManagedDependencyGenerator2 depGen = (IManagedDependencyGenerator2) t;
276269
IManagedDependencyInfo depInfo = depGen.getDependencySourceInfo(
277-
sourceFile.getProjectRelativePath(), sourceFile, buildContext, tool,
270+
sourceFile.getProjectRelativePath(), sourceFile, buildContext, myTool,
278271
buildFolder.getFullPath());
279272
IManagedDependencyCommands depCommands = (IManagedDependencyCommands) depInfo;
280273
if (depCommands != null) {
@@ -294,27 +287,27 @@ private Set<String> getBuildFlags(IFile buildFolder, IConfiguration config, IFil
294287
private String expandCommandLinePattern(IConfiguration config, String sourceExtension, Set<String> flags,
295288
String outputFlag, String outputName, Set<String> inputResources, IFile inputLocation,
296289
IFile outputLocation) {
297-
String cmd = tool.getToolCommand();
290+
String cmd = myTool.getToolCommand();
298291
// try to resolve the build macros in the tool command
299292
try {
300293
String resolvedCommand = null;
301294
if ((inputLocation != null && inputLocation.toString().indexOf(WHITESPACE) != -1)
302295
|| (outputLocation != null && outputLocation.toString().indexOf(WHITESPACE) != -1)) {
303296
resolvedCommand = ManagedBuildManager.getBuildMacroProvider().resolveValue(cmd, EMPTY_STRING,
304297
WHITESPACE, IBuildMacroProvider.CONTEXT_FILE,
305-
new FileContextData(inputLocation.getFullPath(), outputLocation.getFullPath(), null, tool));
298+
new FileContextData(inputLocation.getFullPath(), outputLocation.getFullPath(), null, myTool));
306299
} else {
307300
resolvedCommand = ManagedBuildManager.getBuildMacroProvider().resolveValueToMakefileFormat(cmd,
308301
EMPTY_STRING, WHITESPACE, IBuildMacroProvider.CONTEXT_FILE,
309-
new FileContextData(inputLocation.getFullPath(), outputLocation.getFullPath(), null, tool));
302+
new FileContextData(inputLocation.getFullPath(), outputLocation.getFullPath(), null, myTool));
310303
}
311304
if ((resolvedCommand = resolvedCommand.trim()).length() > 0)
312305
cmd = resolvedCommand;
313306
} catch (BuildMacroException e) {
314307
/* JABA is not going to write this code */
315308
}
316309
return expandCommandLinePattern(cmd, flags, outputFlag, outputName, inputResources,
317-
getToolCommandLinePattern(config, tool));
310+
getToolCommandLinePattern(config, myTool));
318311
}
319312

320313
// /**
@@ -465,7 +458,7 @@ private String expandCommandLinePattern(String commandName, Set<String> flags, S
465458
command = command.replace(makeVariable(CMD_LINE_PRM_NAME), commandName);
466459
command = command.replace(makeVariable(FLAGS_PRM_NAME), flagsStr);
467460
command = command.replace(makeVariable(OUTPUT_FLAG_PRM_NAME), outputFlag);
468-
command = command.replace(makeVariable(OUTPUT_PREFIX_PRM_NAME), tool.getOutputPrefix());
461+
command = command.replace(makeVariable(OUTPUT_PREFIX_PRM_NAME), myTool.getOutputPrefix());
469462
command = command.replace(makeVariable(OUTPUT_PRM_NAME), quotedOutputName);
470463
command = command.replace(makeVariable(INPUTS_PRM_NAME), inputsStr);
471464

io.sloeber.core/src/io/sloeber/managedBuild/Internal/ManagebBuildCommon.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,8 @@ static public String GetNiceFileName(IFile buildPath, IFile path) {
609609
IPath buildLocation = buildPath.getLocation();
610610
IPath fileLocation = path.getLocation();
611611
if (buildLocation.isPrefixOf(path.getLocation())) {
612-
return DOT_SLASH_PATH.append(fileLocation.makeRelativeTo(buildLocation)).toOSString();
612+
return fileLocation.makeRelativeTo(buildLocation).toOSString();
613+
//return DOT_SLASH_PATH.append(fileLocation.makeRelativeTo(buildLocation)).toOSString();
613614
}
614615
if (buildLocation.removeLastSegments(1).isPrefixOf(fileLocation)) {
615616
return fileLocation.makeRelativeTo(buildLocation).toOSString();

0 commit comments

Comments
 (0)