Skip to content

Add specifier to generated tool property keys #4795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void resolveToolsDependencies(Collection<ContributedPackage> packages) {
if (tool == null) {
System.err.println("Index error: could not find referenced tool " + dep);
} else {
tool.usetUserArchitecture(this.getParentPackage().getName()+"."+this.getArchitecture());
resolvedToolReferences.put(dep, tool);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import cc.arduino.contributions.DownloadableContribution;
import processing.app.Platform;

import java.util.LinkedList;
import java.util.List;

public abstract class ContributedTool {
Expand All @@ -42,6 +43,20 @@ public abstract class ContributedTool {

public abstract List<HostDependentDownloadableContribution> getSystems();

private LinkedList<String> users = null;
public void usetUserArchitecture(String vendorAndArch) {
if (users == null) {
users = new LinkedList<>();
}
if (!users.contains(vendorAndArch)) {
users.add(vendorAndArch);
}
}

public List<String> ugetUserArchitectures() {
return users;
}

public DownloadableContribution getDownloadableContribution(Platform platform) {
for (HostDependentDownloadableContribution c : getSystems()) {
if (c.isCompatible(platform))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
pattern = prefs.get("upload.network_pattern");
if(pattern == null)
pattern = prefs.getOrExcept("upload.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
uploadResult = executeUploadCommand(cmd);
} catch (RunnerException e) {
throw e;
Expand Down
15 changes: 10 additions & 5 deletions arduino-core/src/cc/arduino/packages/uploaders/SerialUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
boolean uploadResult;
try {
String pattern = prefs.getOrExcept("upload.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
uploadResult = executeUploadCommand(cmd);
} catch (Exception e) {
throw new RunnerException(e);
Expand Down Expand Up @@ -204,8 +205,10 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String

boolean uploadResult;
try {
// Architecture field formatted as "arduino.avr" to prepend runtime vars
String pattern = prefs.getOrExcept("upload.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
uploadResult = executeUploadCommand(cmd);
} catch (RunnerException e) {
throw e;
Expand Down Expand Up @@ -341,7 +344,8 @@ private boolean uploadUsingProgrammer(String buildPath, String className) throws
// }

String pattern = prefs.getOrExcept("program.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
return executeUploadCommand(cmd);
} catch (RunnerException e) {
throw e;
Expand Down Expand Up @@ -404,12 +408,13 @@ public boolean burnBootloader() throws Exception {
new LoadVIDPIDSpecificPreferences().load(prefs);

String pattern = prefs.getOrExcept("erase.pattern");
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
String arch = targetPlatform.getContainerPackage().getId()+"."+targetPlatform.getId();
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
if (!executeUploadCommand(cmd))
return false;

pattern = prefs.getOrExcept("bootloader.pattern");
cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
cmd = StringReplacer.formatAndSplit(pattern, prefs, arch, true);
return executeUploadCommand(cmd);
}
}
4 changes: 4 additions & 0 deletions arduino-core/src/processing/app/BaseNoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,10 @@ public static void createToolPreferences(Collection<ContributedTool> installedTo
}
PreferencesData.set(prefix + tool.getName() + ".path", absolutePath);
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", absolutePath);
for (String userArch : tool.ugetUserArchitectures()) {
PreferencesData.set(prefix + tool.getName() + ".path." + userArch, absolutePath);
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path." + userArch, absolutePath);
}
}
}

Expand Down
27 changes: 23 additions & 4 deletions arduino-core/src/processing/app/helpers/StringReplacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ public class StringReplacer {

public static String[] formatAndSplit(String src, Map<String, String> dict,
boolean recursive) throws Exception {
return formatAndSplit(src, dict, "", recursive);
}

public static String[] formatAndSplit(String src, Map<String, String> dict, String arch,
boolean recursive) throws Exception {
String res;

// Recursive replace with a max depth of 10 levels.
for (int i = 0; i < 10; i++) {
// Do a replace with dictionary
res = StringReplacer.replaceFromMapping(src, dict);
res = StringReplacer.replaceFromMapping(src, dict, arch);
if (!recursive)
break;
if (res.equals(src))
Expand Down Expand Up @@ -85,16 +90,30 @@ public static String[] quotedSplit(String src, String quoteChars,
return res.toArray(new String[0]);
}

public static String replaceFromMapping(String src, Map<String, String> map, String arch) {
return replaceFromMapping(src, map, "{", "}", arch);
}

public static String replaceFromMapping(String src, Map<String, String> map) {
return replaceFromMapping(src, map, "{", "}");
return replaceFromMapping(src, map, "{", "}", "");
}

public static String replaceFromMapping(String src, Map<String, String> map,
String leftDelimiter,
String rightDelimiter) {
String rightDelimiter,
String footer) {
for (Map.Entry<String, String> entry : map.entrySet()) {
String keyword = leftDelimiter + entry.getKey() + rightDelimiter;
if (entry.getValue() != null && keyword != null) {
String value = null;

// if {entry.getKey()+"."+footer} key exists, use it instead
if (map.containsKey(entry.getKey()+"."+footer)) {
value = map.get(entry.getKey()+"."+footer);
} else {
value = entry.getValue();
}

if (value != null && keyword != null) {
src = src.replace(keyword, entry.getValue());
}
}
Expand Down