30
30
import org .eclipse .cdt .managedbuilder .makegen .IManagedDependencyInfo ;
31
31
import org .eclipse .core .resources .IFile ;
32
32
import org .eclipse .core .resources .IProject ;
33
+ import org .eclipse .core .runtime .IPath ;
33
34
34
35
public class MakeRule {
35
36
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
+ }
39
59
40
60
public HashSet <IFile > getPrerequisites () {
41
61
HashSet <IFile > ret = new HashSet <>();
42
- for (List <IFile > cur : prerequisites .values ()) {
62
+ for (List <IFile > cur : myPrerequisites .values ()) {
43
63
ret .addAll (cur );
44
64
}
45
65
return ret ;
46
66
}
47
67
48
68
public HashSet <IFile > getTargets () {
49
69
HashSet <IFile > ret = new HashSet <>();
50
- for (List <IFile > cur : targets .values ()) {
70
+ for (List <IFile > cur : myTargets .values ()) {
51
71
ret .addAll (cur );
52
72
}
53
73
return ret ;
54
74
}
55
75
56
76
public HashSet <String > getMacros () {
57
77
HashSet <String > ret = new HashSet <>();
58
- for (IOutputType cur : targets .keySet ()) {
78
+ for (IOutputType cur : myTargets .keySet ()) {
59
79
ret .add (cur .getBuildVariable ());
60
80
}
61
- for (IInputType cur : prerequisites .keySet ()) {
81
+ for (IInputType cur : myPrerequisites .keySet ()) {
62
82
ret .add (cur .getBuildVariable ());
63
83
}
84
+ for (String cur : myDependencies .keySet ()) {
85
+ ret .add (cur );
86
+ }
64
87
return ret ;
65
88
}
66
89
67
90
public HashSet <IFile > getMacroElements (String macroName ) {
68
91
HashSet <IFile > ret = new HashSet <>();
69
92
70
- for (Entry <IOutputType , List <IFile >> cur : targets .entrySet ()) {
93
+ for (Entry <IOutputType , List <IFile >> cur : myTargets .entrySet ()) {
71
94
if (macroName .equals (cur .getKey ().getBuildVariable ())) {
72
95
ret .addAll (cur .getValue ());
73
96
}
74
97
}
75
- for (Entry <IInputType , List <IFile >> cur : prerequisites .entrySet ()) {
98
+ for (Entry <IInputType , List <IFile >> cur : myPrerequisites .entrySet ()) {
76
99
if (macroName .equals (cur .getKey ().getBuildVariable ())) {
77
100
ret .addAll (cur .getValue ());
78
101
}
79
102
}
103
+ List <IFile > tmp = myDependencies .get (macroName );
104
+ if (tmp != null ) {
105
+ ret .addAll (tmp );
106
+ }
80
107
return ret ;
81
108
}
82
109
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 );
85
112
if (files == null ) {
86
113
files = new LinkedList <>();
87
114
files .add (file );
88
- targets .put (outputType , files );
115
+ myTargets .put (outputType , files );
89
116
} else {
90
117
files .add (file );
91
118
}
92
119
}
93
120
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 );
96
123
if (files == null ) {
97
124
files = new LinkedList <>();
98
125
files .add (file );
99
- prerequisites .put (inputType , files );
126
+ myPrerequisites .put (inputType , files );
100
127
} else {
101
128
files .add (file );
102
129
}
103
130
}
104
131
105
132
private String enumTargets (IFile buildFolder ) {
106
133
String ret = new String ();
107
- for (List <IFile > curFiles : targets .values ()) {
134
+ for (List <IFile > curFiles : myTargets .values ()) {
108
135
for (IFile curFile : curFiles ) {
109
136
ret = ret + GetNiceFileName (buildFolder , curFile ) + WHITESPACE ;
110
137
}
111
138
}
112
139
return ret ;
113
- //return StringUtils.join(targets.values(), WHITESPACE);
114
140
}
115
141
116
142
private String enumPrerequisites (IFile buildFolder ) {
117
143
String ret = new String ();
118
- for (List <IFile > curFiles : prerequisites .values ()) {
144
+ for (List <IFile > curFiles : myPrerequisites .values ()) {
119
145
for (IFile curFile : curFiles ) {
120
146
ret = ret + GetNiceFileName (buildFolder , curFile ) + WHITESPACE ;
121
147
}
122
148
}
123
149
return ret ;
124
- // return StringUtils.join(prerequisites.values(), WHITESPACE);
125
150
}
126
151
127
152
public StringBuffer getRule (IProject project , IFile niceBuildFolder , IConfiguration config ) {
128
153
129
- String cmd = tool .getToolCommand ();
154
+ String cmd = myTool .getToolCommand ();
130
155
//For now assume 1 target with 1 or more prerequisites
131
156
// if there is more than 1 prerequisite we take the flags of the first prerequisite only
132
157
HashSet <IFile > local_targets = getTargets ();
@@ -158,17 +183,17 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
158
183
boolean needExplicitDependencyCommands = false ;
159
184
boolean resourceNameRequiresExplicitRule = containsSpecialCharacters (sourceLocation .getLocation ().toOSString ());
160
185
needExplicitRuleForFile = resourceNameRequiresExplicitRule
161
- || BuildMacroProvider .getReferencedExplitFileMacros (tool ).length > 0
186
+ || BuildMacroProvider .getReferencedExplitFileMacros (myTool ).length > 0
162
187
|| BuildMacroProvider .getReferencedExplitFileMacros (cmd , IBuildMacroProvider .CONTEXT_FILE ,
163
188
new FileContextData (sourceLocation .getFullPath (), outputLocation .getFullPath (), null ,
164
- tool )).length > 0 ;
189
+ myTool )).length > 0 ;
165
190
166
- String outflag = tool .getOutputFlag ();
191
+ String outflag = myTool .getOutputFlag ();
167
192
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 ;
169
194
if (needExplicitRuleForFile || needExplicitDependencyCommands ) {
170
195
buildCmd = expandCommandLinePattern (cmd , flags , outflag , OUT_MACRO + otherPrimaryOutputs , niceNameList ,
171
- getToolCommandLinePattern (config , tool ));
196
+ getToolCommandLinePattern (config , myTool ));
172
197
} else {
173
198
buildCmd = expandCommandLinePattern (config , inputExtension , flags , outflag , OUT_MACRO + otherPrimaryOutputs ,
174
199
niceNameList , sourceLocation , outputLocation );
@@ -181,13 +206,13 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
181
206
if (!needExplicitRuleForFile ) {
182
207
resolvedCommand = provider .resolveValueToMakefileFormat (buildCmd , EMPTY_STRING , WHITESPACE ,
183
208
IBuildMacroProvider .CONTEXT_FILE ,
184
- new FileContextData (sourceLocation .getFullPath (), outputLocation .getFullPath (), null , tool ));
209
+ new FileContextData (sourceLocation .getFullPath (), outputLocation .getFullPath (), null , myTool ));
185
210
} else {
186
211
// if we need an explicit rule then don't use any builder
187
212
// variables, resolve everything to explicit strings
188
213
resolvedCommand = provider .resolveValue (buildCmd , EMPTY_STRING , WHITESPACE ,
189
214
IBuildMacroProvider .CONTEXT_FILE ,
190
- new FileContextData (sourceLocation .getFullPath (), outputLocation .getFullPath (), null , tool ));
215
+ new FileContextData (sourceLocation .getFullPath (), outputLocation .getFullPath (), null , myTool ));
191
216
}
192
217
if (!resolvedCommand .isBlank ())
193
218
buildCmd = resolvedCommand .trim ();
@@ -199,7 +224,7 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
199
224
buffer .append (enumTargets (niceBuildFolder )).append (COLON ).append (WHITESPACE );
200
225
buffer .append (enumPrerequisites (niceBuildFolder )).append (NEWLINE );
201
226
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 ()));
203
228
204
229
// JABA add sketch.prebuild and postbouild if needed
205
230
//TOFIX this should not be here
@@ -221,38 +246,6 @@ public StringBuffer getRule(IProject project, IFile niceBuildFolder, IConfigurat
221
246
}
222
247
// end JABA add sketch.prebuild and postbouild if needed
223
248
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
256
249
buffer .append (NEWLINE );
257
250
buffer .append (TAB ).append (AT ).append (escapedEcho (MESSAGE_FINISH_FILE + WHITESPACE + IN_MACRO ));
258
251
buffer .append (TAB ).append (AT ).append (ECHO_BLANK_LINE ).append (NEWLINE );
@@ -265,16 +258,16 @@ private Set<String> getBuildFlags(IFile buildFolder, IConfiguration config, IFil
265
258
try {
266
259
267
260
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 ())));
269
262
270
- IInputType [] inputTypes = tool .getInputTypes (); //.getDependencyGeneratorForExtension(inputExtension);
263
+ IInputType [] inputTypes = myTool .getInputTypes (); //.getDependencyGeneratorForExtension(inputExtension);
271
264
for (IInputType inputType : inputTypes ) {
272
265
IManagedDependencyGeneratorType t = inputType .getDependencyGenerator ();
273
266
if (t != null ) {
274
267
if (t .getCalculatorType () == IManagedDependencyGeneratorType .TYPE_BUILD_COMMANDS ) {
275
268
IManagedDependencyGenerator2 depGen = (IManagedDependencyGenerator2 ) t ;
276
269
IManagedDependencyInfo depInfo = depGen .getDependencySourceInfo (
277
- sourceFile .getProjectRelativePath (), sourceFile , buildContext , tool ,
270
+ sourceFile .getProjectRelativePath (), sourceFile , buildContext , myTool ,
278
271
buildFolder .getFullPath ());
279
272
IManagedDependencyCommands depCommands = (IManagedDependencyCommands ) depInfo ;
280
273
if (depCommands != null ) {
@@ -294,27 +287,27 @@ private Set<String> getBuildFlags(IFile buildFolder, IConfiguration config, IFil
294
287
private String expandCommandLinePattern (IConfiguration config , String sourceExtension , Set <String > flags ,
295
288
String outputFlag , String outputName , Set <String > inputResources , IFile inputLocation ,
296
289
IFile outputLocation ) {
297
- String cmd = tool .getToolCommand ();
290
+ String cmd = myTool .getToolCommand ();
298
291
// try to resolve the build macros in the tool command
299
292
try {
300
293
String resolvedCommand = null ;
301
294
if ((inputLocation != null && inputLocation .toString ().indexOf (WHITESPACE ) != -1 )
302
295
|| (outputLocation != null && outputLocation .toString ().indexOf (WHITESPACE ) != -1 )) {
303
296
resolvedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValue (cmd , EMPTY_STRING ,
304
297
WHITESPACE , IBuildMacroProvider .CONTEXT_FILE ,
305
- new FileContextData (inputLocation .getFullPath (), outputLocation .getFullPath (), null , tool ));
298
+ new FileContextData (inputLocation .getFullPath (), outputLocation .getFullPath (), null , myTool ));
306
299
} else {
307
300
resolvedCommand = ManagedBuildManager .getBuildMacroProvider ().resolveValueToMakefileFormat (cmd ,
308
301
EMPTY_STRING , WHITESPACE , IBuildMacroProvider .CONTEXT_FILE ,
309
- new FileContextData (inputLocation .getFullPath (), outputLocation .getFullPath (), null , tool ));
302
+ new FileContextData (inputLocation .getFullPath (), outputLocation .getFullPath (), null , myTool ));
310
303
}
311
304
if ((resolvedCommand = resolvedCommand .trim ()).length () > 0 )
312
305
cmd = resolvedCommand ;
313
306
} catch (BuildMacroException e ) {
314
307
/* JABA is not going to write this code */
315
308
}
316
309
return expandCommandLinePattern (cmd , flags , outputFlag , outputName , inputResources ,
317
- getToolCommandLinePattern (config , tool ));
310
+ getToolCommandLinePattern (config , myTool ));
318
311
}
319
312
320
313
// /**
@@ -465,7 +458,7 @@ private String expandCommandLinePattern(String commandName, Set<String> flags, S
465
458
command = command .replace (makeVariable (CMD_LINE_PRM_NAME ), commandName );
466
459
command = command .replace (makeVariable (FLAGS_PRM_NAME ), flagsStr );
467
460
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 ());
469
462
command = command .replace (makeVariable (OUTPUT_PRM_NAME ), quotedOutputName );
470
463
command = command .replace (makeVariable (INPUTS_PRM_NAME ), inputsStr );
471
464
0 commit comments