99
99
public class ArduinoGnuMakefileGenerator implements IManagedBuilderMakefileGenerator2 {
100
100
private static final String DOTSLASH = "." + File .separator ;
101
101
private static final IPath DOT_SLASH_PATH = new Path (DOTSLASH );
102
+ private static final String FILE_SEPARATOR = File .separator ;
102
103
103
104
/**
104
105
* This class walks the delta supplied by the build system to determine what
@@ -1068,12 +1069,12 @@ public boolean visit(PathSettingsContainer container) {
1068
1069
});
1069
1070
// Add the macros to the makefile
1070
1071
for (Entry <String , List <IPath >> entry : this .buildSrcVars .entrySet ()) {
1071
- String macroName = entry .getKey ();
1072
+ String macroName = new Path ( entry .getKey ()). toOSString ();
1072
1073
builder1 .append (macroName + WHITESPACE + ":=" + WHITESPACE + NEWLINE );
1073
1074
}
1074
1075
Set <Entry <String , List <IPath >>> set = this .buildOutVars .entrySet ();
1075
1076
for (Entry <String , List <IPath >> entry : set ) {
1076
- String macroName = entry .getKey ();
1077
+ String macroName = new Path ( entry .getKey ()). toOSString ();
1077
1078
builder1 .append (macroName + WHITESPACE + ":=" + WHITESPACE + NEWLINE );
1078
1079
}
1079
1080
// Add a list of subdirectories to the makefile
@@ -1124,7 +1125,7 @@ protected StringBuilder addTopHeader() {
1124
1125
*/
1125
1126
private StringBuffer addMacros () {
1126
1127
StringBuffer buffer = new StringBuffer ();
1127
- buffer .append ("-include " + ROOT + SEPARATOR + MAKEFILE_INIT + NEWLINE );
1128
+ buffer .append ("-include " + ROOT + FILE_SEPARATOR + MAKEFILE_INIT + NEWLINE );
1128
1129
buffer .append (NEWLINE );
1129
1130
// Get the clean command from the build model
1130
1131
buffer .append ("RM := " );
@@ -1153,7 +1154,7 @@ private StringBuffer addMacros() {
1153
1154
}
1154
1155
Collections .sort (subDirList , Collections .reverseOrder ());
1155
1156
for (String dir : subDirList ) {
1156
- buffer .append ("-include " + escapeWhitespaces (dir ) + SEPARATOR + "subdir.mk" + NEWLINE );
1157
+ buffer .append ("-include " + escapeWhitespaces (dir ) + FILE_SEPARATOR + "subdir.mk" + NEWLINE );
1157
1158
}
1158
1159
// Change the include of the "root" (our sketch) folder to be before
1159
1160
// libraries and other files
@@ -1177,7 +1178,7 @@ private StringBuffer addMacros() {
1177
1178
buffer .append ("endif" + NEWLINE + NEWLINE );
1178
1179
}
1179
1180
// Include makefile.defs supplemental makefile
1180
- buffer .append ("-include " + ROOT + SEPARATOR + MAKEFILE_DEFS + NEWLINE ); //
1181
+ buffer .append ("-include " + ROOT + FILE_SEPARATOR + MAKEFILE_DEFS + NEWLINE ); //
1181
1182
return (buffer .append (NEWLINE ));
1182
1183
}
1183
1184
@@ -1287,13 +1288,13 @@ private StringBuffer addTargets(List<String> outputVarsAdditionsList, boolean re
1287
1288
buffer .append ("dependents:" + NEWLINE );
1288
1289
addDeps = false ;
1289
1290
}
1290
- String buildDir = depCfg .getOwner ().getLocation ().toString ();
1291
+ String buildDir = depCfg .getOwner ().getLocation ().toOSString ();
1291
1292
String depTargets = targets ;
1292
1293
// if (ManagedBuildManager.manages(dep)) {
1293
1294
// Add the current configuration to the makefile path
1294
1295
// IManagedBuildInfo depInfo =
1295
1296
// ManagedBuildManager.getBuildInfo(dep);
1296
- buildDir += SEPARATOR + depCfg .getName ();
1297
+ buildDir += FILE_SEPARATOR + depCfg .getName ();
1297
1298
// Extract the build artifact to add to the dependency list
1298
1299
String depTarget = depCfg .getArtifactName ();
1299
1300
String depExt = depCfg .getArtifactExtension ();
@@ -1317,7 +1318,7 @@ private StringBuffer addTargets(List<String> outputVarsAdditionsList, boolean re
1317
1318
if (depCfg .needsRebuild ()) {
1318
1319
depTargets = "clean all" ;
1319
1320
}
1320
- String dependency = buildDir + SEPARATOR + depPrefix + depTarget ;
1321
+ String dependency = buildDir + FILE_SEPARATOR + depPrefix + depTarget ;
1321
1322
if (depExt .length () > 0 ) {
1322
1323
dependency += DOT + depExt ;
1323
1324
}
@@ -1375,7 +1376,7 @@ private StringBuffer addTargets(List<String> outputVarsAdditionsList, boolean re
1375
1376
}
1376
1377
buffer .append (NEWLINE );
1377
1378
// Include makefile.targets supplemental makefile
1378
- buffer .append ("-include " + ROOT + SEPARATOR + MAKEFILE_TARGETS + NEWLINE );
1379
+ buffer .append ("-include " + ROOT + FILE_SEPARATOR + MAKEFILE_TARGETS + NEWLINE );
1379
1380
return buffer ;
1380
1381
}
1381
1382
@@ -1521,8 +1522,8 @@ protected boolean addRuleForTool(ITool tool, StringBuffer buffer, boolean bTarge
1521
1522
primaryOutputsQuoted += WHITESPACE ;
1522
1523
}
1523
1524
first = false ;
1524
- primaryOutputs += output ;
1525
- primaryOutputsQuoted += ensurePathIsGNUMakeTargetRuleCompatibleSyntax (output );
1525
+ primaryOutputs += new Path ( output ). toOSString () ;
1526
+ primaryOutputsQuoted += ensurePathIsGNUMakeTargetRuleCompatibleSyntax (new Path ( output ). toOSString () );
1526
1527
}
1527
1528
buildRule += (primaryOutputsQuoted + COLON + WHITESPACE );
1528
1529
first = true ;
@@ -1787,7 +1788,7 @@ private StringBuffer addSubdirectories() {
1787
1788
// Get all the module names
1788
1789
for (IResource container : getSubdirList ()) {
1789
1790
updateMonitor (ManagedMakeMessages .getFormattedString ("MakefileGenerator.message.adding.source.folder" ,
1790
- container .getFullPath ().toString ()));
1791
+ container .getFullPath ().toOSString ()));
1791
1792
// Check the special case where the module is the project root
1792
1793
if (container .getFullPath () == this .project .getFullPath ()) {
1793
1794
buffer .append (DOT + WHITESPACE + LINEBREAK );
@@ -1824,8 +1825,8 @@ protected StringBuilder addFragmentMakefileHeader() {
1824
1825
protected StringBuffer addSources (IContainer module ) throws CoreException {
1825
1826
// Calculate the new directory relative to the build output
1826
1827
IPath moduleRelativePath = module .getProjectRelativePath ();
1827
- String relativePath = moduleRelativePath .toString ();
1828
- relativePath += relativePath .length () == 0 ? "" : SEPARATOR ;
1828
+ String relativePath = moduleRelativePath .toOSString ();
1829
+ relativePath += relativePath .length () == 0 ? "" : FILE_SEPARATOR ;
1829
1830
// For build macros in the configuration, create a map which will map
1830
1831
// them
1831
1832
// to a string which holds its list of sources.
@@ -1839,7 +1840,7 @@ protected StringBuffer addSources(IContainer module) throws CoreException {
1839
1840
}
1840
1841
for (Entry <String , List <IPath >> entry : this .buildOutVars .entrySet ()) {
1841
1842
String macroName = entry .getKey ();
1842
- addMacroAdditionPrefix (buildVarToRuleStringMap , macroName , "./" + relativePath , false );
1843
+ addMacroAdditionPrefix (buildVarToRuleStringMap , macroName , DOTSLASH + relativePath , false );
1843
1844
}
1844
1845
// String buffers
1845
1846
StringBuffer buffer = new StringBuffer (); // Return buffer
@@ -2274,13 +2275,13 @@ protected void addRuleForSource(String relativePath, StringBuffer buffer, IResou
2274
2275
enumeratedOutputs .addAll (enumeratedSecondaryOutputs );
2275
2276
String primaryOutputName = null ;
2276
2277
if (enumeratedPrimaryOutputs .size () > 0 ) {
2277
- primaryOutputName = escapeWhitespaces (enumeratedPrimaryOutputs .get (0 ).toString ());
2278
+ primaryOutputName = escapeWhitespaces (enumeratedPrimaryOutputs .get (0 ).toOSString ());
2278
2279
} else {
2279
2280
primaryOutputName = escapeWhitespaces (relativePath + fileName + optDotExt );
2280
2281
}
2281
2282
String otherPrimaryOutputs = EMPTY_STRING ;
2282
2283
for (int i = 1 ; i < enumeratedPrimaryOutputs .size (); i ++) {
2283
- otherPrimaryOutputs += WHITESPACE + escapeWhitespaces (enumeratedPrimaryOutputs .get (i ).toString ());
2284
+ otherPrimaryOutputs += WHITESPACE + escapeWhitespaces (enumeratedPrimaryOutputs .get (i ).toOSString ());
2284
2285
}
2285
2286
// Output file location needed for the file-specific build macros
2286
2287
IPath outputLocation = Path .fromOSString (primaryOutputName );
@@ -2298,8 +2299,8 @@ protected void addRuleForSource(String relativePath, StringBuffer buffer, IResou
2298
2299
* but its project relative path contains special characters
2299
2300
*/
2300
2301
boolean resourceNameRequiresExplicitRule = (resource .isLinked ()
2301
- && containsSpecialCharacters (sourceLocation .toString ()))
2302
- || (!resource .isLinked () && containsSpecialCharacters (resource .getProjectRelativePath ().toString ()));
2302
+ && containsSpecialCharacters (sourceLocation .toOSString ()))
2303
+ || (!resource .isLinked () && containsSpecialCharacters (resource .getProjectRelativePath ().toOSString ()));
2303
2304
boolean needExplicitRuleForFile = resourceNameRequiresExplicitRule
2304
2305
|| BuildMacroProvider .getReferencedExplitFileMacros (tool ).length > 0
2305
2306
|| BuildMacroProvider .getReferencedExplitFileMacros (tool .getToolCommand (),
@@ -2336,7 +2337,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2336
2337
if (resource .isLinked (IResource .CHECK_ANCESTORS )) {
2337
2338
// it IS linked, so use the actual location
2338
2339
isItLinked = true ;
2339
- resourcePath = sourceLocation .toString ();
2340
+ resourcePath = sourceLocation .toOSString ();
2340
2341
// Need a hardcoded rule, not a pattern rule, as a linked file
2341
2342
// can reside in any path
2342
2343
defaultOutputName = escapeWhitespaces (relativePath + fileName + optDotExt );
@@ -2355,8 +2356,8 @@ && containsSpecialCharacters(sourceLocation.toString()))
2355
2356
defaultOutputName = relativePath + WILDCARD + optDotExt ;
2356
2357
}
2357
2358
primaryDependencyName = escapeWhitespaces (
2358
- home + SEPARATOR + resourcePath + fileName + DOT + inputExtension );
2359
- patternPrimaryDependencyName = home + SEPARATOR + resourcePath + WILDCARD + DOT + inputExtension ;
2359
+ home + FILE_SEPARATOR + resourcePath + fileName + DOT + inputExtension );
2360
+ patternPrimaryDependencyName = home + FILE_SEPARATOR + resourcePath + WILDCARD + DOT + inputExtension ;
2360
2361
} // end fix for PR 70491
2361
2362
// If the tool specifies a dependency calculator of
2362
2363
// TYPE_BUILD_COMMANDS,
@@ -2373,7 +2374,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2373
2374
patternRule = false ;
2374
2375
// Make sure that at least one of the rule outputs contains a %.
2375
2376
for (int i = 0 ; i < ruleOutputs .size (); i ++) {
2376
- String ruleOutput = ruleOutputs .get (i ).toString ();
2377
+ String ruleOutput = ruleOutputs .get (i ).toOSString ();
2377
2378
if (ruleOutput .indexOf ('%' ) >= 0 ) {
2378
2379
patternRule = true ;
2379
2380
break ;
@@ -2391,7 +2392,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2391
2392
} else {
2392
2393
boolean first = true ;
2393
2394
for (int i = 0 ; i < ruleOutputs .size (); i ++) {
2394
- String ruleOutput = ruleOutputs .get (i ).toString ();
2395
+ String ruleOutput = ruleOutputs .get (i ).toOSString ();
2395
2396
if (ruleOutput .indexOf ('%' ) >= 0 ) {
2396
2397
if (first ) {
2397
2398
first = false ;
@@ -2423,7 +2424,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2423
2424
}
2424
2425
}
2425
2426
}
2426
- String suitablePath = ensurePathIsGNUMakeTargetRuleCompatibleSyntax (addlPath .toString ());
2427
+ String suitablePath = ensurePathIsGNUMakeTargetRuleCompatibleSyntax (addlPath .toOSString ());
2427
2428
buildRuleDependencies += WHITESPACE + suitablePath ;
2428
2429
patternBuildRuleDependencies += WHITESPACE + suitablePath ;
2429
2430
}
@@ -2488,7 +2489,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2488
2489
}
2489
2490
}
2490
2491
}
2491
- inputs .add (addlPath .toString ());
2492
+ inputs .add (addlPath .toOSString ());
2492
2493
}
2493
2494
String [] inputStrings = inputs .toArray (new String [inputs .size ()]);
2494
2495
String [] flags = null ;
@@ -2622,7 +2623,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2622
2623
if (addlDeps != null && addlDeps .length > 0 ) {
2623
2624
calculatedDependencies = new String ();
2624
2625
for (IPath addlDep : addlDeps ) {
2625
- calculatedDependencies += WHITESPACE + escapeWhitespaces (addlDep .toString ());
2626
+ calculatedDependencies += WHITESPACE + escapeWhitespaces (addlDep .toOSString ());
2626
2627
}
2627
2628
}
2628
2629
if (calculatedDependencies != null ) {
@@ -2647,7 +2648,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2647
2648
addlOutputs .add (addlTarget );
2648
2649
}
2649
2650
for (int i = 0 ; i < addlOutputs .size (); i ++) {
2650
- depLine = escapeWhitespaces (addlOutputs .get (i ).toString ()) + COLON + WHITESPACE + primaryOutputName ;
2651
+ depLine = escapeWhitespaces (addlOutputs .get (i ).toOSString ()) + COLON + WHITESPACE + primaryOutputName ;
2651
2652
if (calculatedDependencies != null )
2652
2653
depLine += calculatedDependencies ;
2653
2654
depLine += NEWLINE ;
@@ -2681,7 +2682,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
2681
2682
optDotExt = DOT + depExt ;
2682
2683
depLine += escapeWhitespaces (relativePath + WILDCARD + optDotExt );
2683
2684
} else {
2684
- depLine += escapeWhitespaces ((depFiles [i ]).toString ());
2685
+ depLine += escapeWhitespaces ((depFiles [i ]).toOSString ());
2685
2686
}
2686
2687
}
2687
2688
depLine += COLON + WHITESPACE + (patternRule ? patternBuildRuleDependencies : buildRuleDependencies );
@@ -2921,7 +2922,7 @@ protected void calculateOutputsForSource(ITool tool, String relativePath, IResou
2921
2922
// }
2922
2923
// if (config != null) {
2923
2924
try {
2924
- if (containsSpecialCharacters (sourceLocation .toString ())) {
2925
+ if (containsSpecialCharacters (sourceLocation .toOSString ())) {
2925
2926
outputPrefix = ManagedBuildManager .getBuildMacroProvider ().resolveValue (outputPrefix ,
2926
2927
new String (), " " , IBuildMacroProvider .CONTEXT_CONFIGURATION , this .config );
2927
2928
} else {
@@ -2969,7 +2970,7 @@ outputPrefix, new String(), " ", IBuildMacroProvider.CONTEXT_CONFIGURATION,
2969
2970
// names
2970
2971
try {
2971
2972
String resolved = null ;
2972
- if (containsSpecialCharacters (sourceLocation .toString ())) {
2973
+ if (containsSpecialCharacters (sourceLocation .toOSString ())) {
2973
2974
resolved = ManagedBuildManager .getBuildMacroProvider ().resolveValue (outputName ,
2974
2975
new String (), " " , IBuildMacroProvider .CONTEXT_FILE ,
2975
2976
new FileContextData (sourceLocation , null , option , tool ));
@@ -3030,7 +3031,7 @@ outputName, new String(), " ", IBuildMacroProvider.CONTEXT_FILE,
3030
3031
// names
3031
3032
try {
3032
3033
String resolved = null ;
3033
- if (containsSpecialCharacters (sourceLocation .toString ())) {
3034
+ if (containsSpecialCharacters (sourceLocation .toOSString ())) {
3034
3035
resolved = ManagedBuildManager .getBuildMacroProvider ().resolveValue (outputName , "" ,
3035
3036
" " , IBuildMacroProvider .CONTEXT_FILE ,
3036
3037
new FileContextData (sourceLocation , null , option , tool ));
@@ -3080,7 +3081,7 @@ outputName, new String(), " ", IBuildMacroProvider.CONTEXT_FILE,
3080
3081
// If only a file name is specified, add the relative
3081
3082
// path of this output directory
3082
3083
if (outPath .segmentCount () == 1 ) {
3083
- outPath = Path .fromOSString (relativePath + outPath .toString ());
3084
+ outPath = Path .fromOSString (relativePath + outPath .toOSString ());
3084
3085
}
3085
3086
if (primaryOutput ) {
3086
3087
ruleOutputs .add (j , outPath );
@@ -3118,7 +3119,7 @@ outputName, new String(), " ", IBuildMacroProvider.CONTEXT_FILE,
3118
3119
// If only a file name is specified, add the
3119
3120
// relative path of this output directory
3120
3121
if (namePatternPath .segmentCount () == 1 ) {
3121
- namePatternPath = Path .fromOSString (relativePath + namePatternPath .toString ());
3122
+ namePatternPath = Path .fromOSString (relativePath + namePatternPath .toOSString ());
3122
3123
}
3123
3124
}
3124
3125
if (primaryOutput ) {
@@ -3568,7 +3569,8 @@ protected void addMacroAdditionPrefix(LinkedHashMap<String, String> map, String
3568
3569
StringBuffer tempBuffer = new StringBuffer ();
3569
3570
tempBuffer .append (macroName + WHITESPACE + MACRO_ADDITION_PREFIX_SUFFIX );
3570
3571
if (addPrefix ) {
3571
- tempBuffer .append (MACRO_ADDITION_ADDPREFIX_HEADER + relativePath + MACRO_ADDITION_ADDPREFIX_SUFFIX );
3572
+ tempBuffer .append (new Path (MACRO_ADDITION_ADDPREFIX_HEADER + relativePath + MACRO_ADDITION_ADDPREFIX_SUFFIX )
3573
+ .toOSString ());
3572
3574
}
3573
3575
// have to store the buffer in String form as StringBuffer is not a
3574
3576
// sublcass of Object
@@ -3606,17 +3608,17 @@ protected void addMacroAdditionFile(HashMap<String, String> map, String macroNam
3606
3608
if (dirLocation .isPrefixOf (sourceLocation )) {
3607
3609
IPath srcPath = sourceLocation .removeFirstSegments (dirLocation .segmentCount ()).setDevice (null );
3608
3610
if (generatedSource ) {
3609
- srcName = "./" + srcPath .toString ();
3611
+ srcName = DOTSLASH + srcPath .toOSString ();
3610
3612
} else {
3611
- srcName = ROOT + "/" + srcPath .toString ();
3613
+ srcName = ROOT + FILE_SEPARATOR + srcPath .toOSString ();
3612
3614
}
3613
3615
} else {
3614
3616
if (generatedSource && !sourceLocation .isAbsolute ()) {
3615
- srcName = "./" + relativePath + sourceLocation .lastSegment ().toString ();
3617
+ srcName = DOTSLASH + relativePath + sourceLocation .lastSegment ().toString ();
3616
3618
} else {
3617
3619
// TODO: Should we use relative paths when possible (e.g., see
3618
3620
// MbsMacroSupplier.calculateRelPath)
3619
- srcName = sourceLocation .toString ();
3621
+ srcName = sourceLocation .toOSString ();
3620
3622
}
3621
3623
}
3622
3624
addMacroAdditionFile (map , macroName , srcName );
@@ -3633,7 +3635,7 @@ public void addMacroAdditionFiles(HashMap<String, String> map, String macroName,
3633
3635
for (int i = 0 ; i < filenames .size (); i ++) {
3634
3636
String filename = filenames .get (i );
3635
3637
if (filename .length () > 0 ) {
3636
- buffer .append (filename + WHITESPACE + LINEBREAK );
3638
+ buffer .append (new Path ( filename ). toOSString () + WHITESPACE + LINEBREAK );
3637
3639
}
3638
3640
}
3639
3641
// re-insert string in the map
0 commit comments