From 8efed7f2d20428a7abe970627b79cbae2f508089 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2016 10:45:48 +0200 Subject: [PATCH 1/7] Add reference to packager in tools --- .../contributions/packages/ContributedTool.java | 14 ++++++++++++++ .../packages/ContributionsIndexer.java | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributedTool.java b/arduino-core/src/cc/arduino/contributions/packages/ContributedTool.java index 28d817717..db63cdb73 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 0ec945358..660b6a972 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 class ContributionsIndexer { .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); From 2c6f6e76c4b538c1175e047355c1bb3466e003e2 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2016 12:12:00 +0200 Subject: [PATCH 2/7] Boards tools are resolved using informations from package_index.json --- .../packages/ContributionsIndexer.java | 8 ++++++++ arduino-core/src/processing/app/BaseNoGui.java | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java index 660b6a972..5e8fb03ab 100644 --- a/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java +++ b/arduino-core/src/cc/arduino/contributions/packages/ContributionsIndexer.java @@ -439,4 +439,12 @@ public class ContributionsIndexer { 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 8ddb29cdc..41cf541b5 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -6,6 +6,7 @@ import cc.arduino.UploaderUtils; import cc.arduino.contributions.GPGDetachedSignatureVerifier; import cc.arduino.contributions.SignatureVerificationFailedException; 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 +161,18 @@ public class BaseNoGui { } } prefs.put("name", extendedName); + + // Resolve tools needed for this board + ContributedPlatform platform = indexer.getContributedPlaform(getTargetPlatform()); + if (platform != null) { + String prefix = "runtime.tools."; + for (ContributedTool tool : platform.getResolvedTools()) { + File folder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder(); + String toolPath = folder.getAbsolutePath(); + PreferencesData.set(prefix + tool.getName() + ".path", toolPath); + PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", toolPath); + } + } return prefs; } From fa0678f5b704adff941b917fab13c361c1f341df Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2016 12:13:31 +0200 Subject: [PATCH 3/7] added 'runtime.tools.packager-name-version.path' property in the global properties map --- arduino-core/src/processing/app/BaseNoGui.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 41cf541b5..d6137e7db 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -867,14 +867,16 @@ public class BaseNoGui { 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; } - PreferencesData.set(prefix + tool.getName() + ".path", absolutePath); - PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", absolutePath); + PreferencesData.set(prefix + tool.getName() + ".path", toolPath); + PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", toolPath); + PreferencesData.set(prefix + tool.getPackager() + "-" + tool.getName() + "-" + tool.getVersion() + ".path", + toolPath); } } From 6f24fa6cecd9d0e3a650ff8ed109cbc121c1ceab Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 2 Aug 2016 12:53:49 +0200 Subject: [PATCH 4/7] Pass runtime tools to arduino-builder --- arduino-core/src/cc/arduino/Compiler.java | 7 +++++++ arduino-core/src/processing/app/BaseNoGui.java | 1 + 2 files changed, 8 insertions(+) diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java index 858bd1586..29ca80dad 100644 --- a/arduino-core/src/cc/arduino/Compiler.java +++ b/arduino-core/src/cc/arduino/Compiler.java @@ -51,6 +51,7 @@ import java.nio.file.StandardCopyOption; 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 @@ public class Compiler implements MessageConsumer { 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/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index d6137e7db..bfe808332 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -169,6 +169,7 @@ public class BaseNoGui { for (ContributedTool tool : platform.getResolvedTools()) { 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); } From 3b574622817ed6b9ed84b7e7744d44e713965040 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2016 14:11:12 +0200 Subject: [PATCH 5/7] Use latest tools version for generic tool.paths properties --- arduino-core/src/processing/app/BaseNoGui.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index bfe808332..027c60a84 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -5,6 +5,7 @@ import cc.arduino.Constants; 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; @@ -866,6 +867,8 @@ public class BaseNoGui { PreferencesData.removeAllKeysWithPrefix(prefix); } + Map latestVersions = new HashMap<>(); + VersionComparator comparator = new VersionComparator(); for (ContributedTool tool : installedTools) { File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder(); String toolPath; @@ -874,10 +877,15 @@ public class BaseNoGui { } else { toolPath = Constants.PREF_REMOVE_PLACEHOLDER; } - PreferencesData.set(prefix + tool.getName() + ".path", toolPath); - PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", toolPath); - PreferencesData.set(prefix + tool.getPackager() + "-" + tool.getName() + "-" + tool.getVersion() + ".path", - toolPath); + 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); + } } } From 4f1b584e71dd2977abe3e9a09195c8988ccedb42 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2016 14:57:42 +0200 Subject: [PATCH 6/7] Slightly refactored tool resolution This helps the understanding of next commits --- .../src/processing/app/BaseNoGui.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 027c60a84..5aa0c1895 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -164,16 +164,20 @@ public class BaseNoGui { 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) { - String prefix = "runtime.tools."; - for (ContributedTool tool : platform.getResolvedTools()) { - 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); - } + if (platform != null) + requiredTools.addAll(platform.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; } From 723393227cc274746a1023c8f22e306875e25fb0 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 2 Aug 2016 15:09:09 +0200 Subject: [PATCH 7/7] Require tools from referenced core platform if used --- arduino-core/src/processing/app/BaseNoGui.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 5aa0c1895..28826070e 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -171,6 +171,16 @@ public class BaseNoGui { 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();