Skip to content

Commit 51e0d4e

Browse files
author
jantje
committed
#1145 best thing I could come up with (and command line quote changes)
1 parent 2e86c82 commit 51e0d4e

File tree

1 file changed

+63
-45
lines changed

1 file changed

+63
-45
lines changed

io.sloeber.core/src/io/sloeber/core/tools/Helpers.java

+63-45
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.ArrayList;
1313
import java.util.Arrays;
1414
import java.util.Collections;
15+
import java.util.HashMap;
1516
import java.util.List;
1617
import java.util.Map;
1718
import java.util.Map.Entry;
@@ -64,10 +65,11 @@
6465
import io.sloeber.core.managers.ArduinoPlatform;
6566
import io.sloeber.core.managers.InternalPackageManager;
6667
import io.sloeber.core.managers.Library;
68+
import io.sloeber.core.managers.Package;
6769
import io.sloeber.core.managers.Tool;
6870
import io.sloeber.core.managers.ToolDependency;
6971

70-
@SuppressWarnings({"nls","unused"})
72+
@SuppressWarnings({"nls"})
7173
/**
7274
* ArduinoHelpers is a static class containing general purpose functions
7375
*
@@ -644,62 +646,80 @@ private static boolean isLocalKey(String key) {
644646

645647
private static void addPlatformFileTools(ArduinoPlatform platform, IContributedEnvironment contribEnv,
646648
ICConfigurationDescription confDesc, boolean reportToolNotFound) {
647-
if (platform.getToolsDependencies() != null) {
648-
for (ToolDependency tool : platform.getToolsDependencies()) {
649-
String keyString = MakeKeyString("runtime.tools." + tool.getName() + ".path");
650-
Tool theTool = tool.getTool();
651-
if (theTool == null) {
652-
if (reportToolNotFound) {
653-
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,
654-
"Error adding platformFileTools while processing tool " + tool.getName() + " version "
655-
+ tool.getVersion() + " Installpath is null"));
656-
}
657-
} else {
658-
String valueString = theTool.getInstallPath().toOSString();
659-
setBuildEnvironmentVariable(contribEnv, confDesc, keyString, valueString);
660-
keyString = MakeKeyString("runtime.tools." + tool.getName() + tool.getVersion() + ".path");
661-
setBuildEnvironmentVariable(contribEnv, confDesc, keyString, valueString);
662-
keyString = MakeKeyString("runtime.tools." + tool.getName() + '-' + tool.getVersion() + ".path");
663-
setBuildEnvironmentVariable(contribEnv, confDesc, keyString, valueString);
649+
if (platform.getToolsDependencies() == null) {
650+
return;
651+
}
652+
addDependentTools(platform.getToolsDependencies(), contribEnv, confDesc, reportToolNotFound);
653+
654+
}
655+
656+
private static void addDependentTools(Iterable<ToolDependency> tools, IContributedEnvironment contribEnv,
657+
ICConfigurationDescription confDesc, boolean reportToolNotFound) {
658+
659+
for (ToolDependency tool : tools) {
660+
String keyString = MakeKeyString("runtime.tools." + tool.getName() + ".path");
661+
Tool theTool = tool.getTool();
662+
if (theTool == null) {
663+
if (reportToolNotFound) {
664+
Common.log(new Status(IStatus.WARNING, Const.CORE_PLUGIN_ID,
665+
"Error adding platformFileTools while processing tool " + tool.getName() + " version "
666+
+ tool.getVersion() + " Installpath is null"));
664667
}
668+
} else {
669+
String valueString = theTool.getInstallPath().toOSString();
670+
setBuildEnvironmentVariable(contribEnv, confDesc, keyString, valueString);
671+
keyString = MakeKeyString("runtime.tools." + tool.getName() + tool.getVersion() + ".path");
672+
setBuildEnvironmentVariable(contribEnv, confDesc, keyString, valueString);
673+
keyString = MakeKeyString("runtime.tools." + tool.getName() + '-' + tool.getVersion() + ".path");
674+
setBuildEnvironmentVariable(contribEnv, confDesc, keyString, valueString);
665675
}
666676
}
677+
667678
}
668679

669680
private static void setTheEnvironmentVariablesAddThePlatformInfo(BoardDescriptor boardDescriptor,
670681
IContributedEnvironment contribEnv, ICConfigurationDescription confDesc) {
671-
File referencingPlatformFile = boardDescriptor.getReferencingPlatformFile();
672-
File referencedPlatformFile = boardDescriptor.getreferencedPlatformFile();
682+
673683
String architecture = boardDescriptor.getArchitecture();
684+
HashMap<String, ToolDependency> allTools = new HashMap<>();
674685
for (ArduinoPlatform curPlatform : InternalPackageManager.getInstalledPlatforms()) {
675686
addPlatformFileTools(curPlatform, contribEnv, confDesc, false);
676-
}
677-
ArduinoPlatform LatestArduinoPlatform = null;
678-
for (ArduinoPlatform curPlatform : InternalPackageManager.getLatestInstalledPlatforms()) {
679-
if (architecture.equalsIgnoreCase(curPlatform.getArchitecture())) {
680-
addPlatformFileTools(curPlatform, contribEnv, confDesc, false);
681-
if ("arduino".equalsIgnoreCase(curPlatform.getPackage().getMaintainer())) {
682-
LatestArduinoPlatform = curPlatform;
687+
if (architecture.equals(curPlatform.getArchitecture())) {
688+
Package pkg = curPlatform.getPackage();
689+
if (pkg != null) {
690+
if (curPlatform.getToolsDependencies() != null) {
691+
for (ToolDependency curDependency : curPlatform.getToolsDependencies()) {
692+
String name = curDependency.getName();
693+
ToolDependency previousDependency = allTools.get(name);
694+
if (previousDependency == null) {
695+
allTools.put(name, curDependency);
696+
} else {
697+
String prevVersion = previousDependency.getVersion().toLowerCase();
698+
String curVersion = curDependency.getVersion();
699+
if (Version.compare(curVersion, prevVersion) == 1) {
700+
allTools.put(name, curDependency);
701+
}
702+
}
703+
}
704+
}
683705
}
684706
}
685707
}
686-
// add the newest arduino avr platform again for the idiots wanting to
687-
// reference arduino without referencing it
688-
if (LatestArduinoPlatform != null) {
689-
addPlatformFileTools(LatestArduinoPlatform, contribEnv, confDesc, true);
690-
}
691-
// todo implement this jsonBasedPlatformManagement trigger
708+
addDependentTools(allTools.values(), contribEnv, confDesc, false);
709+
710+
// overrule the Arduino IDE way of working and use the json refereced tools
692711
boolean jsonBasedPlatformManagement = !Preferences.getUseArduinoToolSelection();
693712
if (jsonBasedPlatformManagement) {
713+
File referencingPlatformFile = boardDescriptor.getReferencingPlatformFile();
714+
File referencedPlatformFile = boardDescriptor.getreferencedPlatformFile();
694715
// add the referenced platform before the real platform
695716
ArduinoPlatform referencedPlatform = InternalPackageManager.getPlatform(referencedPlatformFile);
696-
if ((referencedPlatform != null) && (referencedPlatform != LatestArduinoPlatform)) {
717+
if (referencedPlatform != null) {
697718
addPlatformFileTools(referencedPlatform, contribEnv, confDesc, true);
698719
}
699720
// and the real platform
700721
ArduinoPlatform referencingPlatform = InternalPackageManager.getPlatform(referencingPlatformFile);
701-
if ((referencingPlatform != null) && (referencingPlatform != LatestArduinoPlatform)) {
702-
722+
if (referencingPlatform != null) {
703723
addPlatformFileTools(referencingPlatform, contribEnv, confDesc, false);
704724
}
705725
}
@@ -883,7 +903,7 @@ private static void setTheEnvironmentVariablesPostProcessing(IContributedEnviron
883903
// FQN
884904
if (name.startsWith("A.TOOLS.")) {
885905
String skipVars[]={"A.NETWORK.PASSWORD","A.NETWORK.PORT","A.UPLOAD.VERBOSE","A.NETWORK.AUTH"};
886-
List<String> skipVarslist=new ArrayList<String>(Arrays.asList(skipVars));
906+
List<String> skipVarslist=new ArrayList<>(Arrays.asList(skipVars));
887907
String toolID = curVariable.getName().split("\\.")[2];
888908
String recipe = curVariable.getValue();
889909
int indexOfVar = recipe.indexOf("${A.");
@@ -916,18 +936,16 @@ private static void setTheEnvironmentVariablesPostProcessing(IContributedEnviron
916936
String moddedValue=curVariable.getValue().replace("\"","\\\"");
917937
setBuildEnvironmentVariable(contribEnv, confDesc, name, moddedValue);
918938
}
919-
if("A.BUILD.USB_PRODUCT".equalsIgnoreCase(name)){
939+
else if("A.BUILD.USB_PRODUCT".equalsIgnoreCase(name)){
920940
String moddedValue=curVariable.getValue().replace("\"","\\\"");
921941
setBuildEnvironmentVariable(contribEnv, confDesc, name, moddedValue);
922942
}
923-
if("A.BUILD.USB_FLAGS".equalsIgnoreCase(name)){
924-
String moddedValue=curVariable.getValue().replace("'", "\"");
925-
setBuildEnvironmentVariable(contribEnv, confDesc, name, moddedValue);
926-
}
927-
if("A.BUILD.EXTRA_FLAGS".equalsIgnoreCase(name)){
928-
//for radino
929-
//radinoCC1101.build.extra_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_PRODUCT={build.usb_product}'
943+
else {
944+
//should use regular expressions or something else better here or right before execution
930945
String moddedValue=curVariable.getValue().replace("'-DUSB_PRODUCT=${A.BUILD.USB_PRODUCT}'","\"-DUSB_PRODUCT=${A.BUILD.USB_PRODUCT}\"");
946+
moddedValue=moddedValue.replace("'-DUSB_MANUFACTURER=${A.BUILD.USB_MANUFACTURER}'","\"-DUSB_MANUFACTURER=${A.BUILD.USB_MANUFACTURER}\"");
947+
moddedValue=moddedValue.replace("'-DUSB_PRODUCT=\"${A.BUILD.BOARD}\"'","\"-DUSB_PRODUCT=\\\"${A.BUILD.BOARD}\\\"\"");
948+
moddedValue=moddedValue.replace("'", "\"");
931949
setBuildEnvironmentVariable(contribEnv, confDesc, name, moddedValue);
932950
}
933951
}

0 commit comments

Comments
 (0)