Skip to content

Commit 57258a6

Browse files
authored
Merge pull request #646 from Sloeber/fix_upload_problems
#639 making all files os dependent
2 parents cf101dc + c2a1b63 commit 57258a6

File tree

2 files changed

+1036
-998
lines changed

2 files changed

+1036
-998
lines changed

io.sloeber.core/src/io/sloeber/core/toolchain/ArduinoGnuMakefileGenerator.java

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
public class ArduinoGnuMakefileGenerator implements IManagedBuilderMakefileGenerator2 {
100100
private static final String DOTSLASH = "." + File.separator;
101101
private static final IPath DOT_SLASH_PATH = new Path(DOTSLASH);
102+
private static final String FILE_SEPARATOR = File.separator;
102103

103104
/**
104105
* This class walks the delta supplied by the build system to determine what
@@ -1068,12 +1069,12 @@ public boolean visit(PathSettingsContainer container) {
10681069
});
10691070
// Add the macros to the makefile
10701071
for (Entry<String, List<IPath>> entry : this.buildSrcVars.entrySet()) {
1071-
String macroName = entry.getKey();
1072+
String macroName = new Path(entry.getKey()).toOSString();
10721073
builder1.append(macroName + WHITESPACE + ":=" + WHITESPACE + NEWLINE);
10731074
}
10741075
Set<Entry<String, List<IPath>>> set = this.buildOutVars.entrySet();
10751076
for (Entry<String, List<IPath>> entry : set) {
1076-
String macroName = entry.getKey();
1077+
String macroName = new Path(entry.getKey()).toOSString();
10771078
builder1.append(macroName + WHITESPACE + ":=" + WHITESPACE + NEWLINE);
10781079
}
10791080
// Add a list of subdirectories to the makefile
@@ -1124,7 +1125,7 @@ protected StringBuilder addTopHeader() {
11241125
*/
11251126
private StringBuffer addMacros() {
11261127
StringBuffer buffer = new StringBuffer();
1127-
buffer.append("-include " + ROOT + SEPARATOR + MAKEFILE_INIT + NEWLINE);
1128+
buffer.append("-include " + ROOT + FILE_SEPARATOR + MAKEFILE_INIT + NEWLINE);
11281129
buffer.append(NEWLINE);
11291130
// Get the clean command from the build model
11301131
buffer.append("RM := ");
@@ -1153,7 +1154,7 @@ private StringBuffer addMacros() {
11531154
}
11541155
Collections.sort(subDirList, Collections.reverseOrder());
11551156
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);
11571158
}
11581159
// Change the include of the "root" (our sketch) folder to be before
11591160
// libraries and other files
@@ -1177,7 +1178,7 @@ private StringBuffer addMacros() {
11771178
buffer.append("endif" + NEWLINE + NEWLINE);
11781179
}
11791180
// Include makefile.defs supplemental makefile
1180-
buffer.append("-include " + ROOT + SEPARATOR + MAKEFILE_DEFS + NEWLINE); //
1181+
buffer.append("-include " + ROOT + FILE_SEPARATOR + MAKEFILE_DEFS + NEWLINE); //
11811182
return (buffer.append(NEWLINE));
11821183
}
11831184

@@ -1287,13 +1288,13 @@ private StringBuffer addTargets(List<String> outputVarsAdditionsList, boolean re
12871288
buffer.append("dependents:" + NEWLINE);
12881289
addDeps = false;
12891290
}
1290-
String buildDir = depCfg.getOwner().getLocation().toString();
1291+
String buildDir = depCfg.getOwner().getLocation().toOSString();
12911292
String depTargets = targets;
12921293
// if (ManagedBuildManager.manages(dep)) {
12931294
// Add the current configuration to the makefile path
12941295
// IManagedBuildInfo depInfo =
12951296
// ManagedBuildManager.getBuildInfo(dep);
1296-
buildDir += SEPARATOR + depCfg.getName();
1297+
buildDir += FILE_SEPARATOR + depCfg.getName();
12971298
// Extract the build artifact to add to the dependency list
12981299
String depTarget = depCfg.getArtifactName();
12991300
String depExt = depCfg.getArtifactExtension();
@@ -1317,7 +1318,7 @@ private StringBuffer addTargets(List<String> outputVarsAdditionsList, boolean re
13171318
if (depCfg.needsRebuild()) {
13181319
depTargets = "clean all";
13191320
}
1320-
String dependency = buildDir + SEPARATOR + depPrefix + depTarget;
1321+
String dependency = buildDir + FILE_SEPARATOR + depPrefix + depTarget;
13211322
if (depExt.length() > 0) {
13221323
dependency += DOT + depExt;
13231324
}
@@ -1375,7 +1376,7 @@ private StringBuffer addTargets(List<String> outputVarsAdditionsList, boolean re
13751376
}
13761377
buffer.append(NEWLINE);
13771378
// Include makefile.targets supplemental makefile
1378-
buffer.append("-include " + ROOT + SEPARATOR + MAKEFILE_TARGETS + NEWLINE);
1379+
buffer.append("-include " + ROOT + FILE_SEPARATOR + MAKEFILE_TARGETS + NEWLINE);
13791380
return buffer;
13801381
}
13811382

@@ -1521,8 +1522,8 @@ protected boolean addRuleForTool(ITool tool, StringBuffer buffer, boolean bTarge
15211522
primaryOutputsQuoted += WHITESPACE;
15221523
}
15231524
first = false;
1524-
primaryOutputs += output;
1525-
primaryOutputsQuoted += ensurePathIsGNUMakeTargetRuleCompatibleSyntax(output);
1525+
primaryOutputs += new Path(output).toOSString();
1526+
primaryOutputsQuoted += ensurePathIsGNUMakeTargetRuleCompatibleSyntax(new Path(output).toOSString());
15261527
}
15271528
buildRule += (primaryOutputsQuoted + COLON + WHITESPACE);
15281529
first = true;
@@ -1787,7 +1788,7 @@ private StringBuffer addSubdirectories() {
17871788
// Get all the module names
17881789
for (IResource container : getSubdirList()) {
17891790
updateMonitor(ManagedMakeMessages.getFormattedString("MakefileGenerator.message.adding.source.folder",
1790-
container.getFullPath().toString()));
1791+
container.getFullPath().toOSString()));
17911792
// Check the special case where the module is the project root
17921793
if (container.getFullPath() == this.project.getFullPath()) {
17931794
buffer.append(DOT + WHITESPACE + LINEBREAK);
@@ -1824,8 +1825,8 @@ protected StringBuilder addFragmentMakefileHeader() {
18241825
protected StringBuffer addSources(IContainer module) throws CoreException {
18251826
// Calculate the new directory relative to the build output
18261827
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;
18291830
// For build macros in the configuration, create a map which will map
18301831
// them
18311832
// to a string which holds its list of sources.
@@ -1839,7 +1840,7 @@ protected StringBuffer addSources(IContainer module) throws CoreException {
18391840
}
18401841
for (Entry<String, List<IPath>> entry : this.buildOutVars.entrySet()) {
18411842
String macroName = entry.getKey();
1842-
addMacroAdditionPrefix(buildVarToRuleStringMap, macroName, "./" + relativePath, false);
1843+
addMacroAdditionPrefix(buildVarToRuleStringMap, macroName, DOTSLASH + relativePath, false);
18431844
}
18441845
// String buffers
18451846
StringBuffer buffer = new StringBuffer(); // Return buffer
@@ -2274,13 +2275,13 @@ protected void addRuleForSource(String relativePath, StringBuffer buffer, IResou
22742275
enumeratedOutputs.addAll(enumeratedSecondaryOutputs);
22752276
String primaryOutputName = null;
22762277
if (enumeratedPrimaryOutputs.size() > 0) {
2277-
primaryOutputName = escapeWhitespaces(enumeratedPrimaryOutputs.get(0).toString());
2278+
primaryOutputName = escapeWhitespaces(enumeratedPrimaryOutputs.get(0).toOSString());
22782279
} else {
22792280
primaryOutputName = escapeWhitespaces(relativePath + fileName + optDotExt);
22802281
}
22812282
String otherPrimaryOutputs = EMPTY_STRING;
22822283
for (int i = 1; i < enumeratedPrimaryOutputs.size(); i++) {
2283-
otherPrimaryOutputs += WHITESPACE + escapeWhitespaces(enumeratedPrimaryOutputs.get(i).toString());
2284+
otherPrimaryOutputs += WHITESPACE + escapeWhitespaces(enumeratedPrimaryOutputs.get(i).toOSString());
22842285
}
22852286
// Output file location needed for the file-specific build macros
22862287
IPath outputLocation = Path.fromOSString(primaryOutputName);
@@ -2298,8 +2299,8 @@ protected void addRuleForSource(String relativePath, StringBuffer buffer, IResou
22982299
* but its project relative path contains special characters
22992300
*/
23002301
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()));
23032304
boolean needExplicitRuleForFile = resourceNameRequiresExplicitRule
23042305
|| BuildMacroProvider.getReferencedExplitFileMacros(tool).length > 0
23052306
|| BuildMacroProvider.getReferencedExplitFileMacros(tool.getToolCommand(),
@@ -2336,7 +2337,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
23362337
if (resource.isLinked(IResource.CHECK_ANCESTORS)) {
23372338
// it IS linked, so use the actual location
23382339
isItLinked = true;
2339-
resourcePath = sourceLocation.toString();
2340+
resourcePath = sourceLocation.toOSString();
23402341
// Need a hardcoded rule, not a pattern rule, as a linked file
23412342
// can reside in any path
23422343
defaultOutputName = escapeWhitespaces(relativePath + fileName + optDotExt);
@@ -2355,8 +2356,8 @@ && containsSpecialCharacters(sourceLocation.toString()))
23552356
defaultOutputName = relativePath + WILDCARD + optDotExt;
23562357
}
23572358
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;
23602361
} // end fix for PR 70491
23612362
// If the tool specifies a dependency calculator of
23622363
// TYPE_BUILD_COMMANDS,
@@ -2373,7 +2374,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
23732374
patternRule = false;
23742375
// Make sure that at least one of the rule outputs contains a %.
23752376
for (int i = 0; i < ruleOutputs.size(); i++) {
2376-
String ruleOutput = ruleOutputs.get(i).toString();
2377+
String ruleOutput = ruleOutputs.get(i).toOSString();
23772378
if (ruleOutput.indexOf('%') >= 0) {
23782379
patternRule = true;
23792380
break;
@@ -2391,7 +2392,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
23912392
} else {
23922393
boolean first = true;
23932394
for (int i = 0; i < ruleOutputs.size(); i++) {
2394-
String ruleOutput = ruleOutputs.get(i).toString();
2395+
String ruleOutput = ruleOutputs.get(i).toOSString();
23952396
if (ruleOutput.indexOf('%') >= 0) {
23962397
if (first) {
23972398
first = false;
@@ -2423,7 +2424,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
24232424
}
24242425
}
24252426
}
2426-
String suitablePath = ensurePathIsGNUMakeTargetRuleCompatibleSyntax(addlPath.toString());
2427+
String suitablePath = ensurePathIsGNUMakeTargetRuleCompatibleSyntax(addlPath.toOSString());
24272428
buildRuleDependencies += WHITESPACE + suitablePath;
24282429
patternBuildRuleDependencies += WHITESPACE + suitablePath;
24292430
}
@@ -2488,7 +2489,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
24882489
}
24892490
}
24902491
}
2491-
inputs.add(addlPath.toString());
2492+
inputs.add(addlPath.toOSString());
24922493
}
24932494
String[] inputStrings = inputs.toArray(new String[inputs.size()]);
24942495
String[] flags = null;
@@ -2622,7 +2623,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
26222623
if (addlDeps != null && addlDeps.length > 0) {
26232624
calculatedDependencies = new String();
26242625
for (IPath addlDep : addlDeps) {
2625-
calculatedDependencies += WHITESPACE + escapeWhitespaces(addlDep.toString());
2626+
calculatedDependencies += WHITESPACE + escapeWhitespaces(addlDep.toOSString());
26262627
}
26272628
}
26282629
if (calculatedDependencies != null) {
@@ -2647,7 +2648,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
26472648
addlOutputs.add(addlTarget);
26482649
}
26492650
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;
26512652
if (calculatedDependencies != null)
26522653
depLine += calculatedDependencies;
26532654
depLine += NEWLINE;
@@ -2681,7 +2682,7 @@ && containsSpecialCharacters(sourceLocation.toString()))
26812682
optDotExt = DOT + depExt;
26822683
depLine += escapeWhitespaces(relativePath + WILDCARD + optDotExt);
26832684
} else {
2684-
depLine += escapeWhitespaces((depFiles[i]).toString());
2685+
depLine += escapeWhitespaces((depFiles[i]).toOSString());
26852686
}
26862687
}
26872688
depLine += COLON + WHITESPACE + (patternRule ? patternBuildRuleDependencies : buildRuleDependencies);
@@ -2921,7 +2922,7 @@ protected void calculateOutputsForSource(ITool tool, String relativePath, IResou
29212922
// }
29222923
// if (config != null) {
29232924
try {
2924-
if (containsSpecialCharacters(sourceLocation.toString())) {
2925+
if (containsSpecialCharacters(sourceLocation.toOSString())) {
29252926
outputPrefix = ManagedBuildManager.getBuildMacroProvider().resolveValue(outputPrefix,
29262927
new String(), " ", IBuildMacroProvider.CONTEXT_CONFIGURATION, this.config);
29272928
} else {
@@ -2969,7 +2970,7 @@ outputPrefix, new String(), " ", IBuildMacroProvider.CONTEXT_CONFIGURATION,
29692970
// names
29702971
try {
29712972
String resolved = null;
2972-
if (containsSpecialCharacters(sourceLocation.toString())) {
2973+
if (containsSpecialCharacters(sourceLocation.toOSString())) {
29732974
resolved = ManagedBuildManager.getBuildMacroProvider().resolveValue(outputName,
29742975
new String(), " ", IBuildMacroProvider.CONTEXT_FILE,
29752976
new FileContextData(sourceLocation, null, option, tool));
@@ -3030,7 +3031,7 @@ outputName, new String(), " ", IBuildMacroProvider.CONTEXT_FILE,
30303031
// names
30313032
try {
30323033
String resolved = null;
3033-
if (containsSpecialCharacters(sourceLocation.toString())) {
3034+
if (containsSpecialCharacters(sourceLocation.toOSString())) {
30343035
resolved = ManagedBuildManager.getBuildMacroProvider().resolveValue(outputName, "",
30353036
" ", IBuildMacroProvider.CONTEXT_FILE,
30363037
new FileContextData(sourceLocation, null, option, tool));
@@ -3080,7 +3081,7 @@ outputName, new String(), " ", IBuildMacroProvider.CONTEXT_FILE,
30803081
// If only a file name is specified, add the relative
30813082
// path of this output directory
30823083
if (outPath.segmentCount() == 1) {
3083-
outPath = Path.fromOSString(relativePath + outPath.toString());
3084+
outPath = Path.fromOSString(relativePath + outPath.toOSString());
30843085
}
30853086
if (primaryOutput) {
30863087
ruleOutputs.add(j, outPath);
@@ -3118,7 +3119,7 @@ outputName, new String(), " ", IBuildMacroProvider.CONTEXT_FILE,
31183119
// If only a file name is specified, add the
31193120
// relative path of this output directory
31203121
if (namePatternPath.segmentCount() == 1) {
3121-
namePatternPath = Path.fromOSString(relativePath + namePatternPath.toString());
3122+
namePatternPath = Path.fromOSString(relativePath + namePatternPath.toOSString());
31223123
}
31233124
}
31243125
if (primaryOutput) {
@@ -3568,7 +3569,8 @@ protected void addMacroAdditionPrefix(LinkedHashMap<String, String> map, String
35683569
StringBuffer tempBuffer = new StringBuffer();
35693570
tempBuffer.append(macroName + WHITESPACE + MACRO_ADDITION_PREFIX_SUFFIX);
35703571
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());
35723574
}
35733575
// have to store the buffer in String form as StringBuffer is not a
35743576
// sublcass of Object
@@ -3606,17 +3608,17 @@ protected void addMacroAdditionFile(HashMap<String, String> map, String macroNam
36063608
if (dirLocation.isPrefixOf(sourceLocation)) {
36073609
IPath srcPath = sourceLocation.removeFirstSegments(dirLocation.segmentCount()).setDevice(null);
36083610
if (generatedSource) {
3609-
srcName = "./" + srcPath.toString();
3611+
srcName = DOTSLASH + srcPath.toOSString();
36103612
} else {
3611-
srcName = ROOT + "/" + srcPath.toString();
3613+
srcName = ROOT + FILE_SEPARATOR + srcPath.toOSString();
36123614
}
36133615
} else {
36143616
if (generatedSource && !sourceLocation.isAbsolute()) {
3615-
srcName = "./" + relativePath + sourceLocation.lastSegment().toString();
3617+
srcName = DOTSLASH + relativePath + sourceLocation.lastSegment().toString();
36163618
} else {
36173619
// TODO: Should we use relative paths when possible (e.g., see
36183620
// MbsMacroSupplier.calculateRelPath)
3619-
srcName = sourceLocation.toString();
3621+
srcName = sourceLocation.toOSString();
36203622
}
36213623
}
36223624
addMacroAdditionFile(map, macroName, srcName);
@@ -3633,7 +3635,7 @@ public void addMacroAdditionFiles(HashMap<String, String> map, String macroName,
36333635
for (int i = 0; i < filenames.size(); i++) {
36343636
String filename = filenames.get(i);
36353637
if (filename.length() > 0) {
3636-
buffer.append(filename + WHITESPACE + LINEBREAK);
3638+
buffer.append(new Path(filename).toOSString() + WHITESPACE + LINEBREAK);
36373639
}
36383640
}
36393641
// re-insert string in the map

0 commit comments

Comments
 (0)