Skip to content

Commit 43f33d8

Browse files
author
Federico Fissore
committed
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
1 parent 2f3914e commit 43f33d8

File tree

5 files changed

+97
-69
lines changed

5 files changed

+97
-69
lines changed

arduino-core/src/cc/arduino/contributions/Constants.java renamed to arduino-core/src/cc/arduino/Constants.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,21 @@
2727
* the GNU General Public License.
2828
*/
2929

30-
package cc.arduino.contributions;
30+
package cc.arduino;
3131

3232
import java.util.Arrays;
3333
import java.util.List;
3434

3535
public class Constants {
3636

37+
public static final String PREF_REMOVE_PLACEHOLDER = "___REMOVE___";
38+
public static final String PREF_BOARDS_MANAGER_ADDITIONAL_URLS = "boardsmanager.additional.urls";
39+
public static final String PREF_CONTRIBUTIONS_TRUST_ALL = "contributions.trust.all";
40+
3741
public static final String DEFAULT_INDEX_FILE_NAME = "package_index.json";
3842
public static final List<String> PROTECTED_PACKAGE_NAMES = Arrays.asList("arduino", "Intel");
3943
public static final String PACKAGE_INDEX_URL;
4044

41-
public static final String PREFERENCES_BOARDS_MANAGER_ADDITIONAL_URLS = "boardsmanager.additional.urls";
42-
public static final String PREF_CONTRIBUTIONS_TRUST_ALL = "contributions.trust.all";
43-
4445
static {
4546
String extenalPackageIndexUrl = System.getProperty("PACKAGE_INDEX_URL");
4647
if (extenalPackageIndexUrl != null && !"".equals(extenalPackageIndexUrl)) {
@@ -50,4 +51,5 @@ public class Constants {
5051
}
5152
}
5253

54+
5355
}

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929

3030
package cc.arduino.contributions.packages;
3131

32-
import cc.arduino.contributions.*;
33-
import cc.arduino.contributions.Constants;
32+
import cc.arduino.Constants;
33+
import cc.arduino.contributions.DownloadableContribution;
34+
import cc.arduino.contributions.DownloadableContributionsDownloader;
35+
import cc.arduino.contributions.SignatureVerifier;
3436
import cc.arduino.filters.FileExecutablePredicate;
3537
import cc.arduino.utils.ArchiveExtractor;
3638
import cc.arduino.utils.MultiStepProgress;
@@ -276,10 +278,10 @@ public List<String> updateIndex() throws Exception {
276278
MultiStepProgress progress = new MultiStepProgress(1);
277279

278280
List<String> downloadedPackageIndexFilesAccumulator = new LinkedList<>();
279-
downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, cc.arduino.contributions.Constants.PACKAGE_INDEX_URL);
281+
downloadIndexAndSignature(progress, downloadedPackageIndexFilesAccumulator, Constants.PACKAGE_INDEX_URL);
280282

281283
Set<String> packageIndexURLs = new HashSet<>();
282-
String additionalURLs = PreferencesData.get(cc.arduino.contributions.Constants.PREFERENCES_BOARDS_MANAGER_ADDITIONAL_URLS, "");
284+
String additionalURLs = PreferencesData.get(Constants.PREF_BOARDS_MANAGER_ADDITIONAL_URLS, "");
283285
if (!"".equals(additionalURLs)) {
284286
packageIndexURLs.addAll(Arrays.asList(additionalURLs.split(",")));
285287
}
@@ -339,7 +341,7 @@ protected void onProgress(Progress progress) {
339341

340342
public void deleteUnknownFiles(List<String> downloadedPackageIndexFiles) throws IOException {
341343
File preferencesFolder = indexer.getIndexFile(".").getParentFile();
342-
File[] additionalPackageIndexFiles = preferencesFolder.listFiles(new PackageIndexFilenameFilter(cc.arduino.contributions.Constants.DEFAULT_INDEX_FILE_NAME));
344+
File[] additionalPackageIndexFiles = preferencesFolder.listFiles(new PackageIndexFilenameFilter(Constants.DEFAULT_INDEX_FILE_NAME));
343345
if (additionalPackageIndexFiles == null) {
344346
return;
345347
}

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929

3030
package cc.arduino.contributions.packages;
3131

32-
import cc.arduino.contributions.*;
32+
import cc.arduino.Constants;
33+
import cc.arduino.contributions.DownloadableContribution;
34+
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
35+
import cc.arduino.contributions.SignatureVerificationFailedException;
36+
import cc.arduino.contributions.SignatureVerifier;
3337
import cc.arduino.contributions.filters.BuiltInPredicate;
3438
import cc.arduino.contributions.filters.InstalledPredicate;
3539
import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -79,14 +83,14 @@ public ContributionsIndexer(File preferencesFolder, Platform platform, Signature
7983
}
8084

8185
public void parseIndex() throws Exception {
82-
File defaultIndexFile = getIndexFile(cc.arduino.contributions.Constants.DEFAULT_INDEX_FILE_NAME);
86+
File defaultIndexFile = getIndexFile(Constants.DEFAULT_INDEX_FILE_NAME);
8387
if (!signatureVerifier.isSigned(defaultIndexFile)) {
84-
throw new SignatureVerificationFailedException(cc.arduino.contributions.Constants.DEFAULT_INDEX_FILE_NAME);
88+
throw new SignatureVerificationFailedException(Constants.DEFAULT_INDEX_FILE_NAME);
8589
}
8690
index = parseIndex(defaultIndexFile);
8791
index.setTrusted();
8892

89-
File[] indexFiles = preferencesFolder.listFiles(new TestPackageIndexFilenameFilter(new PackageIndexFilenameFilter(cc.arduino.contributions.Constants.DEFAULT_INDEX_FILE_NAME)));
93+
File[] indexFiles = preferencesFolder.listFiles(new TestPackageIndexFilenameFilter(new PackageIndexFilenameFilter(Constants.DEFAULT_INDEX_FILE_NAME)));
9094

9195
for (File indexFile : indexFiles) {
9296
ContributionsIndex contributionsIndex = parseIndex(indexFile);
@@ -163,7 +167,7 @@ private void mergeContributions(ContributionsIndex contributionsIndex, File inde
163167
}
164168

165169
private boolean isPackageNameProtected(ContributedPackage contributedPackage) {
166-
return cc.arduino.contributions.Constants.PROTECTED_PACKAGE_NAMES.contains(contributedPackage.getName());
170+
return Constants.PROTECTED_PACKAGE_NAMES.contains(contributedPackage.getName());
167171
}
168172

169173
private ContributionsIndex parseIndex(File indexFile) throws IOException {

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package processing.app;
22

3+
import cc.arduino.Constants;
34
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
45
import cc.arduino.contributions.SignatureVerificationFailedException;
56
import cc.arduino.contributions.libraries.LibrariesIndexer;
@@ -837,10 +838,14 @@ public static void createToolPreferences(Collection<ContributedTool> installedTo
837838

838839
for (ContributedTool tool : installedTools) {
839840
File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder();
841+
String absolutePath;
840842
if (installedFolder != null) {
841-
PreferencesData.set(prefix + tool.getName() + ".path", installedFolder.getAbsolutePath());
842-
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", installedFolder.getAbsolutePath());
843+
absolutePath = installedFolder.getAbsolutePath();
844+
} else {
845+
absolutePath = Constants.PREF_REMOVE_PLACEHOLDER;
843846
}
847+
PreferencesData.set(prefix + tool.getName() + ".path", absolutePath);
848+
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", absolutePath);
844849
}
845850
}
846851

arduino-core/src/processing/app/debug/Compiler.java

+68-53
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,43 @@
2323

2424
package processing.app.debug;
2525

26-
import static processing.app.I18n._;
27-
28-
import java.io.*;
29-
import java.nio.file.Files;
30-
import java.nio.file.Path;
31-
import java.nio.file.Paths;
32-
import java.nio.file.StandardCopyOption;
33-
import java.util.*;
34-
import java.util.stream.Stream;
35-
26+
import cc.arduino.Constants;
3627
import cc.arduino.MyStreamPumper;
3728
import cc.arduino.contributions.packages.ContributedPlatform;
3829
import cc.arduino.contributions.packages.ContributedTool;
3930
import cc.arduino.packages.BoardPort;
4031
import cc.arduino.packages.Uploader;
4132
import cc.arduino.packages.UploaderFactory;
42-
4333
import cc.arduino.packages.uploaders.MergeSketchWithBooloader;
4434
import cc.arduino.utils.Pair;
4535
import org.apache.commons.compress.utils.IOUtils;
46-
import org.apache.commons.exec.*;
47-
import processing.app.BaseNoGui;
48-
import processing.app.I18n;
49-
import processing.app.PreferencesData;
50-
import processing.app.SketchCode;
51-
import processing.app.SketchData;
52-
import processing.app.helpers.*;
36+
import org.apache.commons.exec.CommandLine;
37+
import org.apache.commons.exec.DefaultExecutor;
38+
import org.apache.commons.exec.PumpStreamHandler;
39+
import processing.app.*;
40+
import processing.app.helpers.FileUtils;
41+
import processing.app.helpers.PreferencesMap;
42+
import processing.app.helpers.PreferencesMapException;
43+
import processing.app.helpers.StringReplacer;
5344
import processing.app.helpers.filefilters.OnlyDirs;
54-
import processing.app.packages.LibraryList;
55-
import processing.app.preproc.PdePreprocessor;
5645
import processing.app.legacy.PApplet;
5746
import processing.app.packages.LegacyUserLibrary;
47+
import processing.app.packages.LibraryList;
5848
import processing.app.packages.UserLibrary;
49+
import processing.app.preproc.PdePreprocessor;
5950
import processing.app.tools.DoubleQuotedArgumentsOnWindowsCommandLine;
6051

52+
import java.io.*;
53+
import java.nio.file.Files;
54+
import java.nio.file.Path;
55+
import java.nio.file.Paths;
56+
import java.nio.file.StandardCopyOption;
57+
import java.util.*;
58+
import java.util.stream.Collectors;
59+
import java.util.stream.Stream;
60+
61+
import static processing.app.I18n._;
62+
6163
public class Compiler implements MessageConsumer {
6264

6365
/**
@@ -561,28 +563,30 @@ private PreferencesMap createBuildPreferences(String _buildPath,
561563
}
562564

563565
// Merge all the global preference configuration in order of priority
564-
PreferencesMap p = new PreferencesMap();
565-
p.putAll(PreferencesData.getMap());
566-
if (corePlatform != null)
567-
p.putAll(corePlatform.getPreferences());
568-
p.putAll(targetPlatform.getPreferences());
569-
p.putAll(BaseNoGui.getBoardPreferences());
570-
for (String k : p.keySet()) {
571-
if (p.get(k) == null)
572-
p.put(k, "");
573-
}
574-
575-
p.put("build.path", _buildPath);
576-
p.put("build.project_name", _primaryClassName);
577-
p.put("build.arch", targetPlatform.getId().toUpperCase());
566+
PreferencesMap buildPref = new PreferencesMap();
567+
buildPref.putAll(PreferencesData.getMap());
568+
if (corePlatform != null) {
569+
buildPref.putAll(corePlatform.getPreferences());
570+
}
571+
buildPref.putAll(targetPlatform.getPreferences());
572+
buildPref.putAll(BaseNoGui.getBoardPreferences());
573+
for (String k : buildPref.keySet()) {
574+
if (buildPref.get(k) == null) {
575+
buildPref.put(k, "");
576+
}
577+
}
578+
579+
buildPref.put("build.path", _buildPath);
580+
buildPref.put("build.project_name", _primaryClassName);
581+
buildPref.put("build.arch", targetPlatform.getId().toUpperCase());
578582

579583
// Platform.txt should define its own compiler.path. For
580584
// compatibility with earlier 1.5 versions, we define a (ugly,
581585
// avr-specific) default for it, but this should be removed at some
582586
// point.
583-
if (!p.containsKey("compiler.path")) {
587+
if (!buildPref.containsKey("compiler.path")) {
584588
System.err.println(_("Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer."));
585-
p.put("compiler.path", BaseNoGui.getAvrBasePath());
589+
buildPref.put("compiler.path", BaseNoGui.getAvrBasePath());
586590
}
587591

588592
TargetPlatform referencePlatform = null;
@@ -592,21 +596,21 @@ private PreferencesMap createBuildPreferences(String _buildPath,
592596
referencePlatform = targetPlatform;
593597
}
594598

595-
p.put("build.platform.path", referencePlatform.getFolder().getAbsolutePath());
599+
buildPref.put("build.platform.path", referencePlatform.getFolder().getAbsolutePath());
596600

597601
// Core folder
598602
File coreFolder = new File(referencePlatform.getFolder(), "cores");
599603
coreFolder = new File(coreFolder, core);
600-
p.put("build.core", core);
601-
p.put("build.core.path", coreFolder.getAbsolutePath());
604+
buildPref.put("build.core", core);
605+
buildPref.put("build.core.path", coreFolder.getAbsolutePath());
602606

603607
// System Folder
604608
File systemFolder = referencePlatform.getFolder();
605609
systemFolder = new File(systemFolder, "system");
606-
p.put("build.system.path", systemFolder.getAbsolutePath());
610+
buildPref.put("build.system.path", systemFolder.getAbsolutePath());
607611

608612
// Variant Folder
609-
String variant = p.get("build.variant");
613+
String variant = buildPref.get("build.variant");
610614
if (variant != null) {
611615
TargetPlatform t;
612616
if (!variant.contains(":")) {
@@ -618,9 +622,9 @@ private PreferencesMap createBuildPreferences(String _buildPath,
618622
}
619623
File variantFolder = new File(t.getFolder(), "variants");
620624
variantFolder = new File(variantFolder, variant);
621-
p.put("build.variant.path", variantFolder.getAbsolutePath());
625+
buildPref.put("build.variant.path", variantFolder.getAbsolutePath());
622626
} else {
623-
p.put("build.variant.path", "");
627+
buildPref.put("build.variant.path", "");
624628
}
625629

626630
ContributedPlatform installedPlatform = BaseNoGui.indexer.getInstalled(referencePlatform.getContainerPackage().getId(), referencePlatform.getId());
@@ -630,17 +634,28 @@ private PreferencesMap createBuildPreferences(String _buildPath,
630634
}
631635

632636
// Build Time
633-
Date d = new Date();
634637
GregorianCalendar cal = new GregorianCalendar();
635-
long current = d.getTime()/1000;
636-
long timezone = cal.get(cal.ZONE_OFFSET)/1000;
637-
long daylight = cal.get(cal.DST_OFFSET)/1000;
638-
p.put("extra.time.utc", Long.toString(current));
639-
p.put("extra.time.local", Long.toString(current + timezone + daylight));
640-
p.put("extra.time.zone", Long.toString(timezone));
641-
p.put("extra.time.dst", Long.toString(daylight));
642-
643-
return p;
638+
long current = new Date().getTime() / 1000;
639+
long timezone = cal.get(Calendar.ZONE_OFFSET) / 1000;
640+
long daylight = cal.get(Calendar.DST_OFFSET) / 1000;
641+
buildPref.put("extra.time.utc", Long.toString(current));
642+
buildPref.put("extra.time.local", Long.toString(current + timezone + daylight));
643+
buildPref.put("extra.time.zone", Long.toString(timezone));
644+
buildPref.put("extra.time.dst", Long.toString(daylight));
645+
646+
List<Map.Entry<String, String>> unsetPrefs = buildPref.entrySet().stream()
647+
.filter(entry -> Constants.PREF_REMOVE_PLACEHOLDER.equals(entry.getValue()))
648+
.collect(Collectors.toList());
649+
650+
buildPref.entrySet().stream()
651+
.filter(entry -> {
652+
return unsetPrefs.stream()
653+
.filter(unsetPrefEntry -> entry.getValue().contains(unsetPrefEntry.getKey()))
654+
.count() > 0;
655+
})
656+
.forEach(invalidEntry -> buildPref.put(invalidEntry.getKey(), ""));
657+
658+
return buildPref;
644659
}
645660

646661
private List<File> compileFiles(File outputPath, File sourcePath,

0 commit comments

Comments
 (0)