@@ -621,7 +621,8 @@ private static void setTheEnvironmentVariablesAddAFile(IContributedEnvironment c
621
621
} else if (value .contains (BUILD_PATH_SYSCALLS_MTK )) {
622
622
value = value .replace (BUILD_PATH_SYSCALLS_MTK , BUILD_PATH_ARDUINO_SYSCALLS_MTK );
623
623
}
624
- IEnvironmentVariable envVar = new EnvironmentVariable (MakeKeyString (var [0 ]), MakeEnvironmentString (value ));
624
+ IEnvironmentVariable envVar = new EnvironmentVariable (MakeKeyString (var [0 ]), MakeEnvironmentString (value ,
625
+ ArduinoConst .ENV_KEY_ARDUINO_START ));
625
626
contribEnv .addVariable (envVar , confDesc );
626
627
}
627
628
}
@@ -660,7 +661,7 @@ private static void setTheEnvironmentVariablesAddtheBoardsTxt(IContributedEnviro
660
661
// if it is not a menu item add it
661
662
if (!currentPair .getKey ().startsWith ("menu." )) {
662
663
String keyString = MakeKeyString (currentPair .getKey ());
663
- String valueString = MakeEnvironmentString (currentPair .getValue ());
664
+ String valueString = MakeEnvironmentString (currentPair .getValue (), ArduinoConst . ENV_KEY_ARDUINO_START );
664
665
contribEnv .addVariable (new EnvironmentVariable (keyString , valueString ), confDesc );
665
666
} else {
666
667
@@ -672,7 +673,7 @@ private static void setTheEnvironmentVariablesAddtheBoardsTxt(IContributedEnviro
672
673
String StartValue = "menu." + menuID + "." + menuItemID + "." ;
673
674
if (currentPair .getKey ().startsWith (StartValue )) {
674
675
String keyString = MakeKeyString (currentPair .getKey ().substring (StartValue .length ()));
675
- String valueString = MakeEnvironmentString (currentPair .getValue ());
676
+ String valueString = MakeEnvironmentString (currentPair .getValue (), ArduinoConst . ENV_KEY_ARDUINO_START );
676
677
contribEnv .addVariable (new EnvironmentVariable (keyString , valueString ), confDesc );
677
678
}
678
679
}
@@ -714,8 +715,9 @@ private static void setTheEnvironmentVariablesAddtheBoardsTxt(IContributedEnviro
714
715
for (Entry <String , String > curOption : menuSectionMap .entrySet ()) {
715
716
if (curOption .getKey ().startsWith (keyStartsWithValue )) {
716
717
String key = curOption .getKey ().substring (keyStartsWithValue .length ());
717
- contribEnv
718
- .addVariable (new EnvironmentVariable (MakeKeyString (key ), MakeEnvironmentString (curOption .getValue ())), confDesc );
718
+ contribEnv .addVariable (
719
+ new EnvironmentVariable (MakeKeyString (key ), MakeEnvironmentString (curOption .getValue (),
720
+ ArduinoConst .ENV_KEY_ARDUINO_START )), confDesc );
719
721
}
720
722
}
721
723
@@ -760,83 +762,44 @@ private static boolean isThisMenuItemSelected(ArduinoBoards boardsFile, ICConfig
760
762
761
763
public static void setTheEnvironmentVariables (IProject project , ICConfigurationDescription confDesc , boolean debugCompilerSettings ) {
762
764
765
+ // first get all the data we need
763
766
IEnvironmentVariableManager envManager = CCorePlugin .getDefault ().getBuildEnvironmentManager ();
764
767
IContributedEnvironment contribEnv = envManager .getContributedEnvironment ();
765
768
766
769
IPath boardFileName = new Path (Common .getBuildEnvironmentVariable (confDesc , ArduinoConst .ENV_KEY_JANTJE_BOARDS_FILE ,
767
770
ArduinoInstancePreferences .getLastUsedBoardsFile ()));
768
771
IPath localPlatformFilename = new Path (Common .getBuildEnvironmentVariable (confDesc , ArduinoConst .ENV_KEY_JANTJE_PLATFORM_FILE , "" ));
769
772
770
- /*
771
- * Trying to find the file in the plugin as described here :http://blog.vogella.com/2010/07/06/reading-resources-from-plugin/
772
- */
773
- // Bundle bundle = Platform.getBundle(ArduinoConst.CORE_PLUGIN_ID);
774
- // URL fileURL = bundle.getEntry("config/arduino_eclipse_plugin.txt");
775
- // File file = null;
776
- // try {
777
- // file = new File(FileLocator.resolve(fileURL).toURI());
778
- // } catch (URISyntaxException e1) {
779
- // e1.printStackTrace();
780
- // } catch (IOException e1) {
781
- // e1.printStackTrace();
782
- // }
783
- // if (file == null) {
784
- // Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID,
785
- // "Your setup has gotten corrupt. Missing config/arduino_eclipse_plugin.txt file."));
786
- // return;
787
- // }
788
- // IPath arduinoEclipsePluginFile = new Path(file.getAbsolutePath());
789
-
790
- /*
791
- * try the second method as the first method fails
792
- */
793
- // URL url;
794
- // try {
795
- // url = new URL("platform:/plugin/it.baeyens.arduino.core/config/arduino_eclipse_plugin.txt");
796
- // } catch (MalformedURLException e) {
797
- // // TODO Auto-generated catch block
798
- // e.printStackTrace();
799
- // return;
800
- // }
801
- // File file = null;
802
- // try {
803
- // URL resolved_url = FileLocator.resolve(url);
804
- // URI resolverdURI = resolved_url.toURI();
805
- // file = new File(resolverdURI);
806
- // } catch (URISyntaxException e1) {
807
- // e1.printStackTrace();
808
- // } catch (IOException e1) {
809
- // e1.printStackTrace();
810
- // } catch (Exception e1) {
811
- // e1.printStackTrace();
812
- // }
813
- // if (file == null) {
814
- // Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID,
815
- // "Your setup has gotten corrupt. Missing config/arduino_eclipse_plugin.txt file."));
816
- // return;
817
- // }
818
- // IPath arduinoEclipsePluginFile = new Path(file.getAbsolutePath());
819
-
820
773
String boardID = Common .getBuildEnvironmentVariable (confDesc , ArduinoConst .ENV_KEY_JANTJE_BOARD_ID , "" );
821
774
String architecture = Common .getBuildEnvironmentVariable (confDesc , ArduinoConst .ENV_KEY_JANTJE_ARCITECTURE_ID , "" );
822
775
String packageName = Common .getBuildEnvironmentVariable (confDesc , ArduinoConst .ENV_KEY_JANTJE_PACKAGE_ID , "" );
823
776
File anduinoIDEEnvNamesFile = Common .getArduinoIdeDumpName (packageName , architecture , boardID );
824
777
IPath anduinoIDEEnvNamesPath = new Path (anduinoIDEEnvNamesFile .toString ());
825
778
architecture = architecture .toUpperCase ();
779
+ IPath workspacePath = new Path (Common .getWorkspaceRoot ().getAbsolutePath ());
780
+ ArduinoBoards pluginPreProcessingBoardsTxt = new ArduinoBoards (workspacePath .append (ArduinoConst .PRE_PROCESSING_BOARDS_TXT ).toString ());
781
+ ArduinoBoards pluginPostProcessingBoardsTxt = new ArduinoBoards (workspacePath .append (ArduinoConst .POST_PROCESSING_BOARDS_TXT ).toString ());
782
+ IPath pluginPreProcessingPlatformTxt = new Path (workspacePath .append (ArduinoConst .PRE_PROCESSING_PLATFORM_TXT ).toString ());
783
+ IPath pluginPostProcessingPlatformTxt = new Path (workspacePath .append (ArduinoConst .POST_PROCESSING_PLATFORM_TXT ).toString ());
784
+ ArduinoBoards boardsFile = new ArduinoBoards (boardFileName .toOSString ());
785
+ if (!(pluginPreProcessingBoardsTxt .exists () && pluginPostProcessingBoardsTxt .exists ())) {
786
+ Common .log (new Status (IStatus .ERROR , ArduinoConst .CORE_PLUGIN_ID , "Plugin is not properly configured. Please reconfigure plugin." ));
787
+ return ;
788
+ }
789
+
790
+ // Now we have all info we can start processing
826
791
827
792
// first remove all Arduino Variables so there is no memory effect
828
793
RemoveAllArduinoEnvironmentVariables (contribEnv , confDesc );
829
794
830
- // process the default env variables first. This way the platform.txt
831
- // and boards.txt will
832
- // overwrite the default settings
833
795
setTheEnvironmentVariablesSetTheDefaults (contribEnv , confDesc , localPlatformFilename );
834
796
797
+ setTheEnvironmentVariablesAddAFile (contribEnv , confDesc , pluginPreProcessingPlatformTxt );
798
+ setTheEnvironmentVariablesAddtheBoardsTxt (contribEnv , confDesc , pluginPreProcessingBoardsTxt , boardID , true );
799
+
835
800
// Do some magic for the arduino:arduino stuff
836
- ArduinoBoards boardsFile = new ArduinoBoards (boardFileName .toOSString ());
837
801
setTheEnvironmentVariablesRedirectToOtherVendors (contribEnv , confDesc , boardsFile , boardID , architecture .toLowerCase ());// TOFIX again some
838
802
// dirty thing
839
-
840
803
// process the dump file from the arduino IDE
841
804
if (anduinoIDEEnvNamesFile .exists ()) {
842
805
setTheEnvironmentVariablesAddAFile (contribEnv , confDesc , anduinoIDEEnvNamesPath );
@@ -856,19 +819,15 @@ public static void setTheEnvironmentVariables(IProject project, ICConfigurationD
856
819
// now process the boards file
857
820
setTheEnvironmentVariablesAddtheBoardsTxt (contribEnv , confDesc , boardsFile , boardID , true );
858
821
859
- // also process the file as part of the plugin
860
- // if (arduinoEclipsePluginFile.toFile().exists()) {
861
- // ArduinoBoards myBoardsFile = new ArduinoBoards(arduinoEclipsePluginFile.toOSString());
862
- // setTheEnvironmentVariablesAddtheBoardsTxt(contribEnv, confDesc, myBoardsFile, boardID, false);
863
- // }
822
+ setTheEnvironmentVariablesAddAFile (contribEnv , confDesc , pluginPostProcessingPlatformTxt );
823
+ setTheEnvironmentVariablesAddtheBoardsTxt (contribEnv , confDesc , pluginPostProcessingBoardsTxt , boardID , true );
864
824
865
- // Do some post processing
825
+ // Do some coded post processing
866
826
setTheEnvironmentVariablesPostProcessing (contribEnv , confDesc );
867
827
868
828
// If this is a debug config we modify the environment variables for compilation
869
829
if (debugCompilerSettings ) {
870
830
setTheEnvironmentVariablesModifyDebugCompilerSettings (confDesc , envManager , contribEnv );
871
-
872
831
}
873
832
874
833
}
@@ -1083,12 +1042,12 @@ private static void setTheEnvironmentVariablesModifyDebugCompilerSettings(ICConf
1083
1042
* the value string as read from the file
1084
1043
* @return the string to be stored as value for the environment variable
1085
1044
*/
1086
- public static String MakeEnvironmentString (String inputString ) {
1045
+ public static String MakeEnvironmentString (String inputString , String keyPrefix ) {
1087
1046
// String ret = inputString.replaceAll("-o \"\\{object_file}\"",
1088
1047
// "").replaceAll("\"\\{object_file}\"",
1089
1048
// "").replaceAll("\"\\{source_file}\"", "")
1090
1049
// .replaceAll("\\{", "\\${" + ArduinoConst.ENV_KEY_START);
1091
- String ret = inputString .replaceAll ("\\ {(?!\\ {)" , "\\ ${" + ArduinoConst . ENV_KEY_ARDUINO_START );
1050
+ String ret = inputString .replaceAll ("\\ {(?!\\ {)" , "\\ ${" + keyPrefix );
1092
1051
StringBuilder sb = new StringBuilder (ret );
1093
1052
String regex = "\\ {[^}]*\\ }" ;
1094
1053
Pattern p = Pattern .compile (regex ); // Create the pattern.
0 commit comments