|
12 | 12 | import java.util.ArrayList;
|
13 | 13 | import java.util.Arrays;
|
14 | 14 | import java.util.Collections;
|
| 15 | +import java.util.HashMap; |
15 | 16 | import java.util.List;
|
16 | 17 | import java.util.Map;
|
17 | 18 | import java.util.Map.Entry;
|
|
64 | 65 | import io.sloeber.core.managers.ArduinoPlatform;
|
65 | 66 | import io.sloeber.core.managers.InternalPackageManager;
|
66 | 67 | import io.sloeber.core.managers.Library;
|
| 68 | +import io.sloeber.core.managers.Package; |
67 | 69 | import io.sloeber.core.managers.Tool;
|
68 | 70 | import io.sloeber.core.managers.ToolDependency;
|
69 | 71 |
|
70 |
| -@SuppressWarnings({"nls","unused"}) |
| 72 | +@SuppressWarnings({"nls"}) |
71 | 73 | /**
|
72 | 74 | * ArduinoHelpers is a static class containing general purpose functions
|
73 | 75 | *
|
@@ -644,62 +646,80 @@ private static boolean isLocalKey(String key) {
|
644 | 646 |
|
645 | 647 | private static void addPlatformFileTools(ArduinoPlatform platform, IContributedEnvironment contribEnv,
|
646 | 648 | 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")); |
664 | 667 | }
|
| 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); |
665 | 675 | }
|
666 | 676 | }
|
| 677 | + |
667 | 678 | }
|
668 | 679 |
|
669 | 680 | private static void setTheEnvironmentVariablesAddThePlatformInfo(BoardDescriptor boardDescriptor,
|
670 | 681 | IContributedEnvironment contribEnv, ICConfigurationDescription confDesc) {
|
671 |
| - File referencingPlatformFile = boardDescriptor.getReferencingPlatformFile(); |
672 |
| - File referencedPlatformFile = boardDescriptor.getreferencedPlatformFile(); |
| 682 | + |
673 | 683 | String architecture = boardDescriptor.getArchitecture();
|
| 684 | + HashMap<String, ToolDependency> allTools = new HashMap<>(); |
674 | 685 | for (ArduinoPlatform curPlatform : InternalPackageManager.getInstalledPlatforms()) {
|
675 | 686 | 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 | + } |
683 | 705 | }
|
684 | 706 | }
|
685 | 707 | }
|
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 |
692 | 711 | boolean jsonBasedPlatformManagement = !Preferences.getUseArduinoToolSelection();
|
693 | 712 | if (jsonBasedPlatformManagement) {
|
| 713 | + File referencingPlatformFile = boardDescriptor.getReferencingPlatformFile(); |
| 714 | + File referencedPlatformFile = boardDescriptor.getreferencedPlatformFile(); |
694 | 715 | // add the referenced platform before the real platform
|
695 | 716 | ArduinoPlatform referencedPlatform = InternalPackageManager.getPlatform(referencedPlatformFile);
|
696 |
| - if ((referencedPlatform != null) && (referencedPlatform != LatestArduinoPlatform)) { |
| 717 | + if (referencedPlatform != null) { |
697 | 718 | addPlatformFileTools(referencedPlatform, contribEnv, confDesc, true);
|
698 | 719 | }
|
699 | 720 | // and the real platform
|
700 | 721 | ArduinoPlatform referencingPlatform = InternalPackageManager.getPlatform(referencingPlatformFile);
|
701 |
| - if ((referencingPlatform != null) && (referencingPlatform != LatestArduinoPlatform)) { |
702 |
| - |
| 722 | + if (referencingPlatform != null) { |
703 | 723 | addPlatformFileTools(referencingPlatform, contribEnv, confDesc, false);
|
704 | 724 | }
|
705 | 725 | }
|
@@ -883,7 +903,7 @@ private static void setTheEnvironmentVariablesPostProcessing(IContributedEnviron
|
883 | 903 | // FQN
|
884 | 904 | if (name.startsWith("A.TOOLS.")) {
|
885 | 905 | 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)); |
887 | 907 | String toolID = curVariable.getName().split("\\.")[2];
|
888 | 908 | String recipe = curVariable.getValue();
|
889 | 909 | int indexOfVar = recipe.indexOf("${A.");
|
@@ -916,18 +936,16 @@ private static void setTheEnvironmentVariablesPostProcessing(IContributedEnviron
|
916 | 936 | String moddedValue=curVariable.getValue().replace("\"","\\\"");
|
917 | 937 | setBuildEnvironmentVariable(contribEnv, confDesc, name, moddedValue);
|
918 | 938 | }
|
919 |
| - if("A.BUILD.USB_PRODUCT".equalsIgnoreCase(name)){ |
| 939 | + else if("A.BUILD.USB_PRODUCT".equalsIgnoreCase(name)){ |
920 | 940 | String moddedValue=curVariable.getValue().replace("\"","\\\"");
|
921 | 941 | setBuildEnvironmentVariable(contribEnv, confDesc, name, moddedValue);
|
922 | 942 | }
|
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 |
930 | 945 | 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("'", "\""); |
931 | 949 | setBuildEnvironmentVariable(contribEnv, confDesc, name, moddedValue);
|
932 | 950 | }
|
933 | 951 | }
|
|
0 commit comments