Skip to content

Commit 5a97bdb

Browse files
committed
add specifier to generated tool property keys
by doing so, runtime variable are resolved by using the board specific tools real life example: - Intel i585 defines sketchUploader (version 1.6.2) - Intel arc32 defines sketchUploader (version 1.6.4) - runtime.tools.sketchUploader.path gets the value of the last one processed with this PR runtime.tools.sketchUploader.path.Intel.arc32 and runtime.tools.sketchUploader.path.Intel.i586 get created when resolving {runtime.tools.sketchUploader}, the routine searches for a key runtime.tools.sketchUploader.Vendor.Architecture If found, the value is obtained by {runtime.tools.sketchUploader.Vendor.Architecture}.getKey(), which always contains the required value. If no value is found, the old methos is applied
1 parent 25fe4f4 commit 5a97bdb

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

arduino-core/src/cc/arduino/contributions/packages/ContributedPlatform.java

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public void resolveToolsDependencies(Collection<ContributedPackage> packages) {
8080
if (tool == null) {
8181
System.err.println("Index error: could not find referenced tool " + dep);
8282
} else {
83+
tool.usetUserArchitecture(this.getParentPackage().getName()+"."+this.getArchitecture());
8384
resolvedToolReferences.put(dep, tool);
8485
}
8586
}

arduino-core/src/cc/arduino/contributions/packages/ContributedTool.java

+15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import cc.arduino.contributions.DownloadableContribution;
3333
import processing.app.Platform;
3434

35+
import java.util.LinkedList;
3536
import java.util.List;
3637

3738
public abstract class ContributedTool {
@@ -42,6 +43,20 @@ public abstract class ContributedTool {
4243

4344
public abstract List<HostDependentDownloadableContribution> getSystems();
4445

46+
private LinkedList<String> users = null;
47+
public void usetUserArchitecture(String vendorAndArch) {
48+
if (users == null) {
49+
users = new LinkedList<>();
50+
}
51+
if (!users.contains(vendorAndArch)) {
52+
users.add(vendorAndArch);
53+
}
54+
}
55+
56+
public List<String> ugetUserArchitectures() {
57+
return users;
58+
}
59+
4560
public DownloadableContribution getDownloadableContribution(Platform platform) {
4661
for (HostDependentDownloadableContribution c : getSystems()) {
4762
if (c.isCompatible(platform))

arduino-core/src/cc/arduino/packages/uploaders/GenericNetworkUploader.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
9393
pattern = prefs.get("upload.network_pattern");
9494
if(pattern == null)
9595
pattern = prefs.getOrExcept("upload.pattern");
96-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
96+
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
97+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
9798
uploadResult = executeUploadCommand(cmd);
9899
} catch (RunnerException e) {
99100
throw e;

arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
110110
boolean uploadResult;
111111
try {
112112
String pattern = prefs.getOrExcept("upload.pattern");
113-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
113+
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
114+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
114115
uploadResult = executeUploadCommand(cmd);
115116
} catch (Exception e) {
116117
throw new RunnerException(e);
@@ -204,8 +205,10 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
204205

205206
boolean uploadResult;
206207
try {
208+
// Architecture field formatted as "arduino.avr" to prepend runtime vars
207209
String pattern = prefs.getOrExcept("upload.pattern");
208-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
210+
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
211+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
209212
uploadResult = executeUploadCommand(cmd);
210213
} catch (RunnerException e) {
211214
throw e;
@@ -341,7 +344,8 @@ private boolean uploadUsingProgrammer(String buildPath, String className) throws
341344
// }
342345

343346
String pattern = prefs.getOrExcept("program.pattern");
344-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
347+
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
348+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
345349
return executeUploadCommand(cmd);
346350
} catch (RunnerException e) {
347351
throw e;
@@ -404,12 +408,13 @@ public boolean burnBootloader() throws Exception {
404408
new LoadVIDPIDSpecificPreferences().load(prefs);
405409

406410
String pattern = prefs.getOrExcept("erase.pattern");
407-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
411+
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
412+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
408413
if (!executeUploadCommand(cmd))
409414
return false;
410415

411416
pattern = prefs.getOrExcept("bootloader.pattern");
412-
cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
417+
cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
413418
return executeUploadCommand(cmd);
414419
}
415420
}

arduino-core/src/processing/app/BaseNoGui.java

+4
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,10 @@ public static void createToolPreferences(Collection<ContributedTool> installedTo
859859
}
860860
PreferencesData.set(prefix + tool.getName() + ".path", absolutePath);
861861
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", absolutePath);
862+
for (String userArch : tool.ugetUserArchitectures()) {
863+
PreferencesData.set(prefix + tool.getName() + ".path." + userArch, absolutePath);
864+
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path." + userArch, absolutePath);
865+
}
862866
}
863867
}
864868

arduino-core/src/processing/app/helpers/StringReplacer.java

+23-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ public class StringReplacer {
2929

3030
public static String[] formatAndSplit(String src, Map<String, String> dict,
3131
boolean recursive) throws Exception {
32+
return formatAndSplit(src, dict, "", recursive);
33+
}
34+
35+
public static String[] formatAndSplit(String src, Map<String, String> dict, String arch,
36+
boolean recursive) throws Exception {
3237
String res;
3338

3439
// Recursive replace with a max depth of 10 levels.
3540
for (int i = 0; i < 10; i++) {
3641
// Do a replace with dictionary
37-
res = StringReplacer.replaceFromMapping(src, dict);
42+
res = StringReplacer.replaceFromMapping(src, dict, arch);
3843
if (!recursive)
3944
break;
4045
if (res.equals(src))
@@ -85,16 +90,30 @@ public static String[] quotedSplit(String src, String quoteChars,
8590
return res.toArray(new String[0]);
8691
}
8792

93+
public static String replaceFromMapping(String src, Map<String, String> map, String arch) {
94+
return replaceFromMapping(src, map, "{", "}", arch);
95+
}
96+
8897
public static String replaceFromMapping(String src, Map<String, String> map) {
89-
return replaceFromMapping(src, map, "{", "}");
98+
return replaceFromMapping(src, map, "{", "}", "");
9099
}
91100

92101
public static String replaceFromMapping(String src, Map<String, String> map,
93102
String leftDelimiter,
94-
String rightDelimiter) {
103+
String rightDelimiter,
104+
String footer) {
95105
for (Map.Entry<String, String> entry : map.entrySet()) {
96106
String keyword = leftDelimiter + entry.getKey() + rightDelimiter;
97-
if (entry.getValue() != null && keyword != null) {
107+
String value = null;
108+
109+
// if {entry.getKey()+"."+footer} key exists, use it instead
110+
if (map.containsKey(entry.getKey()+"."+footer)) {
111+
value = map.get(entry.getKey()+"."+footer);
112+
} else {
113+
value = entry.getValue();
114+
}
115+
116+
if (value != null && keyword != null) {
98117
src = src.replace(keyword, entry.getValue());
99118
}
100119
}

0 commit comments

Comments
 (0)