diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java index 858bd1586d4..29ca80daddd 100644 --- a/arduino-core/src/cc/arduino/Compiler.java +++ b/arduino-core/src/cc/arduino/Compiler.java @@ -51,6 +51,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -235,6 +236,12 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ commandLine.addArgument("-prefs=build.warn_data_percentage=" + PreferencesData.get("build.warn_data_percentage")); + for (Map.Entry entry : BaseNoGui.getBoardPreferences().entrySet()) { + if (entry.getKey().startsWith("runtime.tools")) { + commandLine.addArgument("-prefs=" + entry.getKey() + "=" + entry.getValue()); + } + } + //commandLine.addArgument("-debug-level=10", false); if (verbose) { diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributedTool.java b/arduino-core/src/cc/arduino/contributions/packages/ContributedTool.java index 28d81771722..db63cdb7358 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributedTool.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributedTool.java @@ -42,6 +42,20 @@ public abstract class ContributedTool { public abstract List getSystems(); + private ContributedPackage contributedPackage; + + public ContributedPackage getPackage() { + return contributedPackage; + } + + public void setPackage(ContributedPackage pack) { + contributedPackage = pack; + } + + public String getPackager() { + return contributedPackage.getName(); + } + public DownloadableContribution getDownloadableContribution(Platform platform) { for (HostDependentDownloadableContribution c : getSystems()) { if (c.isCompatible(platform)) diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java index 0ec94535846..5e8fb03ab95 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java @@ -104,6 +104,11 @@ public void parseIndex() throws Exception { .collect(Collectors.toList()); for (ContributedPackage pack : packages) { + // Fill references to package in tools + for (ContributedTool tool : pack.getTools()) { + tool.setPackage(pack); + } + for (ContributedPlatform platform : pack.getPlatforms()) { // Set a reference to parent packages platform.setParentPackage(pack); @@ -434,4 +439,12 @@ public ContributedPlatform getPlatformByFolder(final File folder) { return platformOptional.orElse(null); } + + public ContributedPlatform getContributedPlaform(TargetPlatform targetPlatform) { + for (ContributedPlatform plat : getInstalledPlatforms()) { + if (plat.getInstalledFolder().equals(targetPlatform.getFolder())) + return plat; + } + return null; + } } diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 8ddb29cdc5c..28826070eec 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -5,7 +5,9 @@ import cc.arduino.UploaderUtils; import cc.arduino.contributions.GPGDetachedSignatureVerifier; import cc.arduino.contributions.SignatureVerificationFailedException; +import cc.arduino.contributions.VersionComparator; import cc.arduino.contributions.libraries.LibrariesIndexer; +import cc.arduino.contributions.packages.ContributedPlatform; import cc.arduino.contributions.packages.ContributedTool; import cc.arduino.contributions.packages.ContributionsIndexer; import cc.arduino.files.DeleteFilesOnShutdown; @@ -160,6 +162,33 @@ static public PreferencesMap getBoardPreferences() { } } prefs.put("name", extendedName); + + // Resolve tools needed for this board + List requiredTools = new ArrayList<>(); + + // Add all tools dependencies specified in package index + ContributedPlatform platform = indexer.getContributedPlaform(getTargetPlatform()); + if (platform != null) + requiredTools.addAll(platform.getResolvedTools()); + + // Add all tools dependencies from the (possibily) referenced core + String core = prefs.get("build.core"); + if (core.contains(":")) { + String split[] = core.split(":"); + TargetPlatform referenced = BaseNoGui.getCurrentTargetPlatformFromPackage(split[0]); + ContributedPlatform referencedPlatform = indexer.getContributedPlaform(referenced); + if (referencedPlatform != null) + requiredTools.addAll(referencedPlatform.getResolvedTools()); + } + + String prefix = "runtime.tools."; + for (ContributedTool tool : requiredTools) { + File folder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder(); + String toolPath = folder.getAbsolutePath(); + prefs.put(prefix + tool.getName() + ".path", toolPath); + PreferencesData.set(prefix + tool.getName() + ".path", toolPath); + PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", toolPath); + } return prefs; } @@ -852,16 +881,25 @@ public static void createToolPreferences(Collection installedTo PreferencesData.removeAllKeysWithPrefix(prefix); } + Map latestVersions = new HashMap<>(); + VersionComparator comparator = new VersionComparator(); for (ContributedTool tool : installedTools) { File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder(); - String absolutePath; + String toolPath; if (installedFolder != null) { - absolutePath = installedFolder.getAbsolutePath(); + toolPath = installedFolder.getAbsolutePath(); } else { - absolutePath = Constants.PREF_REMOVE_PLACEHOLDER; + toolPath = Constants.PREF_REMOVE_PLACEHOLDER; + } + String toolName = tool.getName(); + String toolVersion = tool.getVersion(); + PreferencesData.set(prefix + toolName + "-" + toolVersion + ".path", toolPath); + PreferencesData.set(prefix + tool.getPackager() + "-" + toolName + "-" + toolVersion + ".path", toolPath); + // In the generic tool property put the path of the latest version if more are available + if (!latestVersions.containsKey(toolName) || comparator.greaterThan(toolVersion, latestVersions.get(toolName))) { + latestVersions.put(toolName, toolVersion); + PreferencesData.set(prefix + toolName + ".path", toolPath); } - PreferencesData.set(prefix + tool.getName() + ".path", absolutePath); - PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", absolutePath); } }