1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +01:00

Tools marked as installed but missing (as when you want to use a system installed avr-gcc) sets to "" the final build preference. Fixes #3074

This commit is contained in:
Federico Fissore 2015-07-09 15:16:19 +02:00
parent 2f3914eb97
commit 43f33d8220
5 changed files with 99 additions and 71 deletions

View File

@ -27,20 +27,21 @@
* the GNU General Public License.
*/
package cc.arduino.contributions;
package cc.arduino;
import java.util.Arrays;
import java.util.List;
public class Constants {
public static final String PREF_REMOVE_PLACEHOLDER = "___REMOVE___";
public static final String PREF_BOARDS_MANAGER_ADDITIONAL_URLS = "boardsmanager.additional.urls";
public static final String PREF_CONTRIBUTIONS_TRUST_ALL = "contributions.trust.all";
public static final String DEFAULT_INDEX_FILE_NAME = "package_index.json";
public static final List<String> PROTECTED_PACKAGE_NAMES = Arrays.asList("arduino", "Intel");
public static final String PACKAGE_INDEX_URL;
public static final String PREFERENCES_BOARDS_MANAGER_ADDITIONAL_URLS = "boardsmanager.additional.urls";
public static final String PREF_CONTRIBUTIONS_TRUST_ALL = "contributions.trust.all";
static {
String extenalPackageIndexUrl = System.getProperty("PACKAGE_INDEX_URL");
if (extenalPackageIndexUrl != null && !"".equals(extenalPackageIndexUrl)) {
@ -50,4 +51,5 @@ public class Constants {
}
}
}

View File

@ -29,8 +29,10 @@
package cc.arduino.contributions.packages;
import cc.arduino.contributions.*;
import cc.arduino.contributions.Constants;
import cc.arduino.Constants;
import cc.arduino.contributions.DownloadableContribution;
import cc.arduino.contributions.DownloadableContributionsDownloader;
import cc.arduino.contributions.SignatureVerifier;
import cc.arduino.filters.FileExecutablePredicate;
import cc.arduino.utils.ArchiveExtractor;
import cc.arduino.utils.MultiStepProgress;
@ -276,10 +278,10 @@ public class ContributionInstaller {
MultiStepProgress progress = new MultiStepProgress(1);
List<String> downloadedPackageIndexFilesAccumulator = new LinkedList<>();
downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, cc.arduino.contributions.Constants.PACKAGE_INDEX_URL);
downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, Constants.PACKAGE_INDEX_URL);
Set<String> packageIndexURLs = new HashSet<>();
String additionalURLs = PreferencesData.get(cc.arduino.contributions.Constants.PREFERENCES_BOARDS_MANAGER_ADDITIONAL_URLS, "");
String additionalURLs = PreferencesData.get(Constants.PREF_BOARDS_MANAGER_ADDITIONAL_URLS, "");
if (!"".equals(additionalURLs)) {
packageIndexURLs.addAll(Arrays.asList(additionalURLs.split(",")));
}
@ -339,7 +341,7 @@ public class ContributionInstaller {
public void deleteUnknownFiles(List<String> downloadedPackageIndexFiles) throws IOException {
File preferencesFolder = indexer.getIndexFile(".").getParentFile();
File[] additionalPackageIndexFiles = preferencesFolder.listFiles(new PackageIndexFilenameFilter(cc.arduino.contributions.Constants.DEFAULT_INDEX_FILE_NAME));
File[] additionalPackageIndexFiles = preferencesFolder.listFiles(new PackageIndexFilenameFilter(Constants.DEFAULT_INDEX_FILE_NAME));
if (additionalPackageIndexFiles == null) {
return;
}

View File

@ -29,7 +29,11 @@
package cc.arduino.contributions.packages;
import cc.arduino.contributions.*;
import cc.arduino.Constants;
import cc.arduino.contributions.DownloadableContribution;
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
import cc.arduino.contributions.SignatureVerificationFailedException;
import cc.arduino.contributions.SignatureVerifier;
import cc.arduino.contributions.filters.BuiltInPredicate;
import cc.arduino.contributions.filters.InstalledPredicate;
import com.fasterxml.jackson.databind.DeserializationFeature;
@ -79,14 +83,14 @@ public class ContributionsIndexer {
}
public void parseIndex() throws Exception {
File defaultIndexFile = getIndexFile(cc.arduino.contributions.Constants.DEFAULT_INDEX_FILE_NAME);
File defaultIndexFile = getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME);
if (!signatureVerifier.isSigned(defaultIndexFile)) {
throw new SignatureVerificationFailedException(cc.arduino.contributions.Constants.DEFAULT_INDEX_FILE_NAME);
throw new SignatureVerificationFailedException(Constants.DEFAULT_INDEX_FILE_NAME);
}
index = parseIndex(defaultIndexFile);
index.setTrusted();
File[] indexFiles = preferencesFolder.listFiles(new TestPackageIndexFilenameFilter(new PackageIndexFilenameFilter(cc.arduino.contributions.Constants.DEFAULT_INDEX_FILE_NAME)));
File[] indexFiles = preferencesFolder.listFiles(new TestPackageIndexFilenameFilter(new PackageIndexFilenameFilter(Constants.DEFAULT_INDEX_FILE_NAME)));
for (File indexFile : indexFiles) {
ContributionsIndex contributionsIndex = parseIndex(indexFile);
@ -163,7 +167,7 @@ public class ContributionsIndexer {
}
private boolean isPackageNameProtected(ContributedPackage contributedPackage) {
return cc.arduino.contributions.Constants.PROTECTED_PACKAGE_NAMES.contains(contributedPackage.getName());
return Constants.PROTECTED_PACKAGE_NAMES.contains(contributedPackage.getName());
}
private ContributionsIndex parseIndex(File indexFile) throws IOException {

View File

@ -1,5 +1,6 @@
package processing.app;
import cc.arduino.Constants;
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
import cc.arduino.contributions.SignatureVerificationFailedException;
import cc.arduino.contributions.libraries.LibrariesIndexer;
@ -837,10 +838,14 @@ public class BaseNoGui {
for (ContributedTool tool : installedTools) {
File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder();
String absolutePath;
if (installedFolder != null) {
PreferencesData.set(prefix + tool.getName() + ".path", installedFolder.getAbsolutePath());
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", installedFolder.getAbsolutePath());
absolutePath = installedFolder.getAbsolutePath();
} else {
absolutePath = Constants.PREF_REMOVE_PLACEHOLDER;
}
PreferencesData.set(prefix + tool.getName() + ".path", absolutePath);
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", absolutePath);
}
}

View File

@ -23,7 +23,31 @@
package processing.app.debug;
import static processing.app.I18n._;
import cc.arduino.Constants;
import cc.arduino.MyStreamPumper;
import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.packages.ContributedTool;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Uploader;
import cc.arduino.packages.UploaderFactory;
import cc.arduino.packages.uploaders.MergeSketchWithBooloader;
import cc.arduino.utils.Pair;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;
import processing.app.*;
import processing.app.helpers.FileUtils;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.PreferencesMapException;
import processing.app.helpers.StringReplacer;
import processing.app.helpers.filefilters.OnlyDirs;
import processing.app.legacy.PApplet;
import processing.app.packages.LegacyUserLibrary;
import processing.app.packages.LibraryList;
import processing.app.packages.UserLibrary;
import processing.app.preproc.PdePreprocessor;
import processing.app.tools.DoubleQuotedArgumentsOnWindowsCommandLine;
import java.io.*;
import java.nio.file.Files;
@ -31,32 +55,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import cc.arduino.MyStreamPumper;
import cc.arduino.contributions.packages.ContributedPlatform;
import cc.arduino.contributions.packages.ContributedTool;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.Uploader;
import cc.arduino.packages.UploaderFactory;
import cc.arduino.packages.uploaders.MergeSketchWithBooloader;
import cc.arduino.utils.Pair;
import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.exec.*;
import processing.app.BaseNoGui;
import processing.app.I18n;
import processing.app.PreferencesData;
import processing.app.SketchCode;
import processing.app.SketchData;
import processing.app.helpers.*;
import processing.app.helpers.filefilters.OnlyDirs;
import processing.app.packages.LibraryList;
import processing.app.preproc.PdePreprocessor;
import processing.app.legacy.PApplet;
import processing.app.packages.LegacyUserLibrary;
import processing.app.packages.UserLibrary;
import processing.app.tools.DoubleQuotedArgumentsOnWindowsCommandLine;
import static processing.app.I18n._;
public class Compiler implements MessageConsumer {
@ -561,28 +563,30 @@ public class Compiler implements MessageConsumer {
}
// Merge all the global preference configuration in order of priority
PreferencesMap p = new PreferencesMap();
p.putAll(PreferencesData.getMap());
if (corePlatform != null)
p.putAll(corePlatform.getPreferences());
p.putAll(targetPlatform.getPreferences());
p.putAll(BaseNoGui.getBoardPreferences());
for (String k : p.keySet()) {
if (p.get(k) == null)
p.put(k, "");
PreferencesMap buildPref = new PreferencesMap();
buildPref.putAll(PreferencesData.getMap());
if (corePlatform != null) {
buildPref.putAll(corePlatform.getPreferences());
}
buildPref.putAll(targetPlatform.getPreferences());
buildPref.putAll(BaseNoGui.getBoardPreferences());
for (String k : buildPref.keySet()) {
if (buildPref.get(k) == null) {
buildPref.put(k, "");
}
}
p.put("build.path", _buildPath);
p.put("build.project_name", _primaryClassName);
p.put("build.arch", targetPlatform.getId().toUpperCase());
buildPref.put("build.path", _buildPath);
buildPref.put("build.project_name", _primaryClassName);
buildPref.put("build.arch", targetPlatform.getId().toUpperCase());
// Platform.txt should define its own compiler.path. For
// compatibility with earlier 1.5 versions, we define a (ugly,
// avr-specific) default for it, but this should be removed at some
// point.
if (!p.containsKey("compiler.path")) {
if (!buildPref.containsKey("compiler.path")) {
System.err.println(_("Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer."));
p.put("compiler.path", BaseNoGui.getAvrBasePath());
buildPref.put("compiler.path", BaseNoGui.getAvrBasePath());
}
TargetPlatform referencePlatform = null;
@ -592,21 +596,21 @@ public class Compiler implements MessageConsumer {
referencePlatform = targetPlatform;
}
p.put("build.platform.path", referencePlatform.getFolder().getAbsolutePath());
buildPref.put("build.platform.path", referencePlatform.getFolder().getAbsolutePath());
// Core folder
File coreFolder = new File(referencePlatform.getFolder(), "cores");
coreFolder = new File(coreFolder, core);
p.put("build.core", core);
p.put("build.core.path", coreFolder.getAbsolutePath());
buildPref.put("build.core", core);
buildPref.put("build.core.path", coreFolder.getAbsolutePath());
// System Folder
File systemFolder = referencePlatform.getFolder();
systemFolder = new File(systemFolder, "system");
p.put("build.system.path", systemFolder.getAbsolutePath());
buildPref.put("build.system.path", systemFolder.getAbsolutePath());
// Variant Folder
String variant = p.get("build.variant");
String variant = buildPref.get("build.variant");
if (variant != null) {
TargetPlatform t;
if (!variant.contains(":")) {
@ -618,9 +622,9 @@ public class Compiler implements MessageConsumer {
}
File variantFolder = new File(t.getFolder(), "variants");
variantFolder = new File(variantFolder, variant);
p.put("build.variant.path", variantFolder.getAbsolutePath());
buildPref.put("build.variant.path", variantFolder.getAbsolutePath());
} else {
p.put("build.variant.path", "");
buildPref.put("build.variant.path", "");
}
ContributedPlatform installedPlatform = BaseNoGui.indexer.getInstalled(referencePlatform.getContainerPackage().getId(), referencePlatform.getId());
@ -630,17 +634,28 @@ public class Compiler implements MessageConsumer {
}
// Build Time
Date d = new Date();
GregorianCalendar cal = new GregorianCalendar();
long current = d.getTime()/1000;
long timezone = cal.get(cal.ZONE_OFFSET)/1000;
long daylight = cal.get(cal.DST_OFFSET)/1000;
p.put("extra.time.utc", Long.toString(current));
p.put("extra.time.local", Long.toString(current + timezone + daylight));
p.put("extra.time.zone", Long.toString(timezone));
p.put("extra.time.dst", Long.toString(daylight));
long current = new Date().getTime() / 1000;
long timezone = cal.get(Calendar.ZONE_OFFSET) / 1000;
long daylight = cal.get(Calendar.DST_OFFSET) / 1000;
buildPref.put("extra.time.utc", Long.toString(current));
buildPref.put("extra.time.local", Long.toString(current + timezone + daylight));
buildPref.put("extra.time.zone", Long.toString(timezone));
buildPref.put("extra.time.dst", Long.toString(daylight));
return p;
List<Map.Entry<String, String>> unsetPrefs = buildPref.entrySet().stream()
.filter(entry -> Constants.PREF_REMOVE_PLACEHOLDER.equals(entry.getValue()))
.collect(Collectors.toList());
buildPref.entrySet().stream()
.filter(entry -> {
return unsetPrefs.stream()
.filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey()))
.count() > 0;
})
.forEach(invalidEntry -> buildPref.put(invalidEntry.getKey(), ""));
return buildPref;
}
private List<File> compileFiles(File outputPath, File sourcePath,