Skip to content

Fix tools discovery by strictly following json data when available #5199

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

Merged
merged 7 commits into from
Aug 3, 2016
Merged
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
7 changes: 7 additions & 0 deletions arduino-core/src/cc/arduino/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ public abstract class ContributedTool {

public abstract List<HostDependentDownloadableContribution> 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
48 changes: 43 additions & 5 deletions arduino-core/src/processing/app/BaseNoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -160,6 +162,33 @@ static public PreferencesMap getBoardPreferences() {
}
}
prefs.put("name", extendedName);

// Resolve tools needed for this board
List<ContributedTool> 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;
}

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

Map<String, String> 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);
}
}

Expand Down