Skip to content

Commit 74d9ca8

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 42ff604 commit 74d9ca8

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

Diff for: 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
}

Diff for: 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))

Diff for: 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;

Diff for: arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
9696
boolean uploadResult;
9797
try {
9898
String pattern = prefs.getOrExcept("upload.pattern");
99-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
99+
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
100+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
100101
uploadResult = executeUploadCommand(cmd);
101102
} catch (Exception e) {
102103
throw new RunnerException(e);
@@ -175,8 +176,10 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
175176

176177
boolean uploadResult;
177178
try {
179+
// Architecture field formatted as "arduino.avr" to prepend runtime vars
178180
String pattern = prefs.getOrExcept("upload.pattern");
179-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
181+
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
182+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
180183
uploadResult = executeUploadCommand(cmd);
181184
} catch (RunnerException e) {
182185
throw e;
@@ -304,7 +307,8 @@ private boolean uploadUsingProgrammer(String buildPath, String className) throws
304307
// }
305308

306309
String pattern = prefs.getOrExcept("program.pattern");
307-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
310+
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
311+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
308312
return executeUploadCommand(cmd);
309313
} catch (RunnerException e) {
310314
throw e;
@@ -367,12 +371,13 @@ public boolean burnBootloader() throws Exception {
367371
new LoadVIDPIDSpecificPreferences().load(prefs);
368372

369373
String pattern = prefs.getOrExcept("erase.pattern");
370-
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
374+
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
375+
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
371376
if (!executeUploadCommand(cmd))
372377
return false;
373378

374379
pattern = prefs.getOrExcept("bootloader.pattern");
375-
cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
380+
cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
376381
return executeUploadCommand(cmd);
377382
}
378383
}

Diff for: arduino-core/src/processing/app/BaseNoGui.java

+4
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,10 @@ public static void createToolPreferences(Collection<ContributedTool> installedTo
857857
}
858858
PreferencesData.set(prefix + tool.getName() + ".path", absolutePath);
859859
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", absolutePath);
860+
for (String userArch : tool.ugetUserArchitectures()) {
861+
PreferencesData.set(prefix + tool.getName() + ".path." + userArch, absolutePath);
862+
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path." + userArch, absolutePath);
863+
}
860864
}
861865
}
862866

Diff for: 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)