Skip to content

Commit 910c602

Browse files
committed
Merge branch 'fix-tools'
2 parents 9e6c0a6 + 7233932 commit 910c602

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

arduino-core/src/cc/arduino/Compiler.java

+7
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.util.ArrayList;
5252
import java.util.Collections;
5353
import java.util.List;
54+
import java.util.Map;
5455
import java.util.regex.Pattern;
5556
import java.util.stream.Collectors;
5657
import java.util.stream.Stream;
@@ -235,6 +236,12 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
235236

236237
commandLine.addArgument("-prefs=build.warn_data_percentage=" + PreferencesData.get("build.warn_data_percentage"));
237238

239+
for (Map.Entry<String, String> entry : BaseNoGui.getBoardPreferences().entrySet()) {
240+
if (entry.getKey().startsWith("runtime.tools")) {
241+
commandLine.addArgument("-prefs=" + entry.getKey() + "=" + entry.getValue());
242+
}
243+
}
244+
238245
//commandLine.addArgument("-debug-level=10", false);
239246

240247
if (verbose) {

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

+14
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ public abstract class ContributedTool {
4242

4343
public abstract List<HostDependentDownloadableContribution> getSystems();
4444

45+
private ContributedPackage contributedPackage;
46+
47+
public ContributedPackage getPackage() {
48+
return contributedPackage;
49+
}
50+
51+
public void setPackage(ContributedPackage pack) {
52+
contributedPackage = pack;
53+
}
54+
55+
public String getPackager() {
56+
return contributedPackage.getName();
57+
}
58+
4559
public DownloadableContribution getDownloadableContribution(Platform platform) {
4660
for (HostDependentDownloadableContribution c : getSystems()) {
4761
if (c.isCompatible(platform))

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

+13
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public void parseIndex() throws Exception {
104104
.collect(Collectors.toList());
105105

106106
for (ContributedPackage pack : packages) {
107+
// Fill references to package in tools
108+
for (ContributedTool tool : pack.getTools()) {
109+
tool.setPackage(pack);
110+
}
111+
107112
for (ContributedPlatform platform : pack.getPlatforms()) {
108113
// Set a reference to parent packages
109114
platform.setParentPackage(pack);
@@ -434,4 +439,12 @@ public ContributedPlatform getPlatformByFolder(final File folder) {
434439

435440
return platformOptional.orElse(null);
436441
}
442+
443+
public ContributedPlatform getContributedPlaform(TargetPlatform targetPlatform) {
444+
for (ContributedPlatform plat : getInstalledPlatforms()) {
445+
if (plat.getInstalledFolder().equals(targetPlatform.getFolder()))
446+
return plat;
447+
}
448+
return null;
449+
}
437450
}

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

+43-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import cc.arduino.UploaderUtils;
66
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
77
import cc.arduino.contributions.SignatureVerificationFailedException;
8+
import cc.arduino.contributions.VersionComparator;
89
import cc.arduino.contributions.libraries.LibrariesIndexer;
10+
import cc.arduino.contributions.packages.ContributedPlatform;
911
import cc.arduino.contributions.packages.ContributedTool;
1012
import cc.arduino.contributions.packages.ContributionsIndexer;
1113
import cc.arduino.files.DeleteFilesOnShutdown;
@@ -160,6 +162,33 @@ static public PreferencesMap getBoardPreferences() {
160162
}
161163
}
162164
prefs.put("name", extendedName);
165+
166+
// Resolve tools needed for this board
167+
List<ContributedTool> requiredTools = new ArrayList<>();
168+
169+
// Add all tools dependencies specified in package index
170+
ContributedPlatform platform = indexer.getContributedPlaform(getTargetPlatform());
171+
if (platform != null)
172+
requiredTools.addAll(platform.getResolvedTools());
173+
174+
// Add all tools dependencies from the (possibily) referenced core
175+
String core = prefs.get("build.core");
176+
if (core.contains(":")) {
177+
String split[] = core.split(":");
178+
TargetPlatform referenced = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]);
179+
ContributedPlatform referencedPlatform = indexer.getContributedPlaform(referenced);
180+
if (referencedPlatform != null)
181+
requiredTools.addAll(referencedPlatform.getResolvedTools());
182+
}
183+
184+
String prefix = "runtime.tools.";
185+
for (ContributedTool tool : requiredTools) {
186+
File folder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder();
187+
String toolPath = folder.getAbsolutePath();
188+
prefs.put(prefix + tool.getName() + ".path", toolPath);
189+
PreferencesData.set(prefix + tool.getName() + ".path", toolPath);
190+
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", toolPath);
191+
}
163192
return prefs;
164193
}
165194

@@ -852,16 +881,25 @@ public static void createToolPreferences(Collection<ContributedTool> installedTo
852881
PreferencesData.removeAllKeysWithPrefix(prefix);
853882
}
854883

884+
Map<String, String> latestVersions = new HashMap<>();
885+
VersionComparator comparator = new VersionComparator();
855886
for (ContributedTool tool : installedTools) {
856887
File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder();
857-
String absolutePath;
888+
String toolPath;
858889
if (installedFolder != null) {
859-
absolutePath = installedFolder.getAbsolutePath();
890+
toolPath = installedFolder.getAbsolutePath();
860891
} else {
861-
absolutePath = Constants.PREF_REMOVE_PLACEHOLDER;
892+
toolPath = Constants.PREF_REMOVE_PLACEHOLDER;
893+
}
894+
String toolName = tool.getName();
895+
String toolVersion = tool.getVersion();
896+
PreferencesData.set(prefix + toolName + "-" + toolVersion + ".path", toolPath);
897+
PreferencesData.set(prefix + tool.getPackager() + "-" + toolName + "-" + toolVersion + ".path", toolPath);
898+
// In the generic tool property put the path of the latest version if more are available
899+
if (!latestVersions.containsKey(toolName) || comparator.greaterThan(toolVersion, latestVersions.get(toolName))) {
900+
latestVersions.put(toolName, toolVersion);
901+
PreferencesData.set(prefix + toolName + ".path", toolPath);
862902
}
863-
PreferencesData.set(prefix + tool.getName() + ".path", absolutePath);
864-
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", absolutePath);
865903
}
866904
}
867905

0 commit comments

Comments
 (0)