@@ -174,6 +174,7 @@ public static void addIncludeFolder(IProject project, IPath IncludePath) {
174
174
* This method creates a link folder in the project and add the folder as a source path to the project it also adds the path to the include folder
175
175
* if the includepath parameter points to a path that contains a subfolder named "utility" this subfolder will be added to the include path as
176
176
* well <br/>
177
+ * Forget about this. Arduino made this all so complicated I don't know anymore what needs to be added to what<br/>
177
178
* <br/>
178
179
*
179
180
* note Arduino has these subfolders in the libraries that need to be include.<br/>
@@ -212,9 +213,30 @@ public static void addCodeFolder(IProject project, String PathVarName, String Su
212
213
213
214
IPathVariableManager pathMan = project .getPathVariableManager ();
214
215
215
- File file = new File (new Path (pathMan .getURIValue (PathVarName ).getPath ()).append (SubFolder ).append ("utility" ).toString ());
216
+ String possibleIncludeFolder = "utility" ;
217
+ File file = new File (new Path (pathMan .getURIValue (PathVarName ).getPath ()).append (SubFolder ).append (possibleIncludeFolder ).toString ());
216
218
if (file .exists ()) {
217
- addIncludeFolder (configurationDescription , link .getFullPath ().append ("utility" ));
219
+ addIncludeFolder (configurationDescription , link .getFullPath ().append (possibleIncludeFolder ));
220
+ }
221
+
222
+ possibleIncludeFolder = "src" ;
223
+ file = new File (new Path (pathMan .getURIValue (PathVarName ).getPath ()).append (SubFolder ).append (possibleIncludeFolder ).toString ());
224
+ if (file .exists ()) {
225
+ addIncludeFolder (configurationDescription , link .getFullPath ().append (possibleIncludeFolder ));
226
+ // possibleIncludeFolder = "src/utility";
227
+ // file = new File(new Path(pathMan.getURIValue(PathVarName).getPath()).append(SubFolder).append(possibleIncludeFolder).toString());
228
+ // if (file.exists()) {
229
+ // addIncludeFolder(configurationDescription, link.getFullPath().append(possibleIncludeFolder));
230
+ // }
231
+ }
232
+
233
+ possibleIncludeFolder = "arch" ;
234
+ file = new File (new Path (pathMan .getURIValue (PathVarName ).getPath ()).append (SubFolder ).append (possibleIncludeFolder ).toString ());
235
+ if (file .exists ()) {
236
+ addIncludeFolder (configurationDescription ,
237
+ link .getFullPath ().append (possibleIncludeFolder ).append (makeEnvironmentVar (ENV_KEY_ARCHITECTURE )));
238
+ // addIncludeFolder(configurationDescription,
239
+ // link.getFullPath().append(possibleIncludeFolder).append(makeEnvironmentVar(ENV_KEY_ARCHITECTURE)).append("utility"));
218
240
}
219
241
220
242
// projectDescription.setActiveConfiguration(configurationDescription);
@@ -458,49 +480,54 @@ private static void RemoveAllArduinoEnvironmentVariables(IContributedEnvironment
458
480
* Used to define the hardware as different settings are needed for avr and sam
459
481
*/
460
482
private static void setTheEnvironmentVariablesSetTheDefaults (IContributedEnvironment contribEnv , ICConfigurationDescription confDesc ,
461
- IPath platformFile , boolean firstTime ) {
483
+ IPath platformFile ) {
462
484
// Set some default values because the platform.txt does not contain
463
485
// them
464
486
IEnvironmentVariable var = new EnvironmentVariable (ENV_KEY_ARDUINO_PATH , getArduinoPath ().toString ());
465
487
contribEnv .addVariable (var , confDesc );
466
488
467
- // I'm not sure why but till now arduino refused to put this in the
468
- // platform.txt file
489
+ // from 1.5.3 onwards 2 more enviroment variables need to be added
490
+ var = new EnvironmentVariable (ENV_KEY_ARCHITECTURE , platformFile .removeLastSegments (1 ).lastSegment ());
491
+ contribEnv .addVariable (var , confDesc );
492
+ var = new EnvironmentVariable (ENV_KEY_BUILD_ARCH , platformFile .removeLastSegments (1 ).lastSegment ().toUpperCase ());
493
+ contribEnv .addVariable (var , confDesc );
494
+
495
+ // I'm not sure why but till now arduino refused to put this in the platform.txt file
469
496
// I won't call them idiots for this but it is getting close
470
497
var = new EnvironmentVariable (ENV_KEY_SOFTWARE , "ARDUINO" );
471
498
contribEnv .addVariable (var , confDesc );
472
499
var = new EnvironmentVariable (ENV_KEY_runtime_ide_version , GetARDUINODefineValue ());
473
500
contribEnv .addVariable (var , confDesc );
474
- // End of section permitting denigrating remarks on arduino software
475
- // development team
501
+ // End of section permitting denigrating remarks on arduino software development team
476
502
477
503
// Arduino uses the board approach for the upload tool.
478
504
// as I'm not I create some special entries to work around it
479
- var = new EnvironmentVariable ("A.CMD" , "${ A.TOOLS.BOSSAC.CMD}" );
505
+ var = new EnvironmentVariable ("A.CMD" , makeEnvironmentVar ( " A.TOOLS.BOSSAC.CMD" ) );
480
506
contribEnv .addVariable (var , confDesc );
481
- var = new EnvironmentVariable ("A.PATH" , "${ A.TOOLS.BOSSAC.PATH}" );
507
+ var = new EnvironmentVariable ("A.PATH" , makeEnvironmentVar ( " A.TOOLS.BOSSAC.PATH" ) );
482
508
contribEnv .addVariable (var , confDesc );
483
- var = new EnvironmentVariable ("A.CMD.PATH" , "${ A.TOOLS.AVRDUDE.CMD.PATH}" );
509
+ var = new EnvironmentVariable ("A.CMD.PATH" , makeEnvironmentVar ( " A.TOOLS.AVRDUDE.CMD.PATH" ) );
484
510
contribEnv .addVariable (var , confDesc );
485
- var = new EnvironmentVariable ("A.CONFIG.PATH" , "${ A.TOOLS.AVRDUDE.CONFIG.PATH}" );
511
+ var = new EnvironmentVariable ("A.CONFIG.PATH" , makeEnvironmentVar ( " A.TOOLS.AVRDUDE.CONFIG.PATH" ) );
486
512
contribEnv .addVariable (var , confDesc ); // End of section Arduino uses
487
513
// the board approach for the
488
514
// upload tool.
489
515
490
516
// For Teensy I added a flag that allows to compile everything in one
491
517
// project not using the archiving functionality
492
- // I set the value to default to use the archiver
518
+ // I set the default value to: use the archiver
493
519
var = new EnvironmentVariable (ENV_KEY_use_archiver , "true" );
494
520
contribEnv .addVariable (var , confDesc );
495
521
// End of Teensy specific settings
496
522
497
523
if (platformFile .segment (platformFile .segmentCount () - 2 ).equals ("avr" )) {
498
- var = new EnvironmentVariable (ENV_KEY_compiler_path , "${ A.RUNTIME.IDE.PATH} /hardware/tools/avr/bin/" );
524
+ var = new EnvironmentVariable (ENV_KEY_compiler_path , makeEnvironmentVar ( " A.RUNTIME.IDE.PATH" ) + " /hardware/tools/avr/bin/" );
499
525
contribEnv .addVariable (var , confDesc );
500
526
} else if (platformFile .segment (platformFile .segmentCount () - 2 ).equals ("sam" )) {
501
- var = new EnvironmentVariable (ENV_KEY_build_system_path , "${ A.RUNTIME.IDE.PATH} /hardware/arduino/sam/system" );
527
+ var = new EnvironmentVariable (ENV_KEY_build_system_path , makeEnvironmentVar ( " A.RUNTIME.IDE.PATH" ) + " /hardware/arduino/sam/system" );
502
528
contribEnv .addVariable (var , confDesc );
503
- var = new EnvironmentVariable (ENV_KEY_build_generic_path , "${A.RUNTIME.IDE.PATH}/hardware/tools/g++_arm_none_eabi/arm-none-eabi/bin" );
529
+ var = new EnvironmentVariable (ENV_KEY_build_generic_path , makeEnvironmentVar ("A.RUNTIME.IDE.PATH" )
530
+ + "/hardware/tools/g++_arm_none_eabi/arm-none-eabi/bin" );
504
531
contribEnv .addVariable (var , confDesc );
505
532
}
506
533
@@ -516,12 +543,12 @@ private static void setTheEnvironmentVariablesSetTheDefaults(IContributedEnviron
516
543
var = new EnvironmentVariable (ENV_KEY_build_path , "${ProjDirPath}/${ConfigName}" );
517
544
contribEnv .addVariable (var , confDesc );
518
545
519
- var = new EnvironmentVariable (ENV_KEY_build_project_name , "${ ProjName}" );
546
+ var = new EnvironmentVariable (ENV_KEY_build_project_name , makeEnvironmentVar ( " ProjName" ) );
520
547
contribEnv .addVariable (var , confDesc );
521
548
522
549
// if (firstTime) {
523
550
if (getBuildEnvironmentVariable (confDesc , ENV_KEY_SIZE_SWITCH , "" ).isEmpty ()) {
524
- var = new EnvironmentVariable (ENV_KEY_SIZE_SWITCH , "${" + ENV_KEY_recipe_size_pattern + "}" );
551
+ var = new EnvironmentVariable (ENV_KEY_SIZE_SWITCH , makeEnvironmentVar ( ENV_KEY_recipe_size_pattern ) );
525
552
contribEnv .addVariable (var , confDesc );
526
553
}
527
554
if (getBuildEnvironmentVariable (confDesc , ENV_KEY_JANTJE_SIZE_COMMAND , "" ).isEmpty ()) {
@@ -585,16 +612,33 @@ private static void setTheEnvironmentVariablesAddtheBoardsTxt(IContributedEnviro
585
612
ArduinoBoards boardsFile = new ArduinoBoards (boardFileName .toOSString ());
586
613
String boardID = boardsFile .getBoardIDFromName (boardName );
587
614
588
- // Get the boards section and add all entries to the environment
589
- // variables
615
+ // Get the boards section and add all entries to the environment variables
590
616
Map <String , String > boardSectionMap = boardsFile .getSection (boardID );
591
617
for (Entry <String , String > currentPair : boardSectionMap .entrySet ()) {
592
- contribEnv .addVariable (new EnvironmentVariable (MakeKeyString (currentPair .getKey ()), MakeEnvironmentString (currentPair .getValue ())),
593
- confDesc );
618
+ // if it is not a menu item add it
619
+ if (!currentPair .getKey ().startsWith ("menu." )) {
620
+ String keyString = MakeKeyString (currentPair .getKey ());
621
+ String valueString = MakeEnvironmentString (currentPair .getValue ());
622
+ contribEnv .addVariable (new EnvironmentVariable (keyString , valueString ), confDesc );
623
+ } else {
624
+
625
+ String [] keySplit = currentPair .getKey ().split ("\\ ." );
626
+ String menuID = keySplit [1 ];
627
+ String menuItemID = keySplit [2 ];
628
+ if (isThisMenuItemSelected (boardsFile , confDesc , boardID , menuID , menuItemID )) {
629
+ // we also need to skip the name
630
+ String StartValue = "menu." + menuID + "." + menuItemID + "." ;
631
+ if (currentPair .getKey ().startsWith (StartValue )) {
632
+ String keyString = MakeKeyString (currentPair .getKey ().substring (StartValue .length ()));
633
+ String valueString = MakeEnvironmentString (currentPair .getValue ());
634
+ contribEnv .addVariable (new EnvironmentVariable (keyString , valueString ), confDesc );
635
+ }
636
+ }
637
+ }
594
638
}
595
639
596
640
Map <String , String > menuSectionMap = boardsFile .getSection ("menu" );
597
- String [] optionNames = boardsFile .getOptionNames ();
641
+ String [] optionNames = boardsFile .getMenuNames ();
598
642
for (int currentOption = 0 ; currentOption < optionNames .length ; currentOption ++) {
599
643
String optionName = optionNames [currentOption ];
600
644
String optionValue = getBuildEnvironmentVariable (confDesc , ArduinoConst .ENV_KEY_JANTJE_START + optionName , "" );
@@ -639,6 +683,22 @@ private static void setTheEnvironmentVariablesAddtheBoardsTxt(IContributedEnviro
639
683
}
640
684
}
641
685
686
+ private static boolean isThisMenuItemSelected (ArduinoBoards boardsFile , ICConfigurationDescription confDesc , String boardID , String menuID ,
687
+ String menuItemID ) {
688
+
689
+ String MenuName = boardsFile .getMenuNameFromID (menuID );
690
+ String MenuItemName = boardsFile .getMenuItemNameFromID (boardID , menuID , menuItemID );
691
+
692
+ String SelectedMenuItemName = getBuildEnvironmentVariable (confDesc , ArduinoConst .ENV_KEY_JANTJE_START + MenuName , "" );
693
+ if (SelectedMenuItemName .isEmpty ()) {
694
+ return false ; // This menu item has not been selected
695
+ // this should not happen
696
+ }
697
+ if (MenuItemName .equalsIgnoreCase (SelectedMenuItemName ))
698
+ return true ;
699
+ return false ;
700
+ }
701
+
642
702
/**
643
703
* This method creates environment variables based on the platform.txt and boards.txt platform.txt is processed first and then boards.txt. This
644
704
* way boards.txt settings can overwrite common settings in platform.txt The environment variables are only valid for the project given as
@@ -650,7 +710,7 @@ private static void setTheEnvironmentVariablesAddtheBoardsTxt(IContributedEnviro
650
710
* @param arduinoProperties
651
711
* the info of the selected board to set the variables for
652
712
*/
653
- public static void setTheEnvironmentVariables (IProject project , ICConfigurationDescription confDesc , boolean firstTime ) {
713
+ public static void setTheEnvironmentVariables (IProject project , ICConfigurationDescription confDesc ) {
654
714
IEnvironmentVariableManager envManager = CCorePlugin .getDefault ().getBuildEnvironmentManager ();
655
715
IContributedEnvironment contribEnv = envManager .getContributedEnvironment ();
656
716
@@ -666,7 +726,7 @@ public static void setTheEnvironmentVariables(IProject project, ICConfigurationD
666
726
// process the default env variables first. This way the platform.txt
667
727
// and boards.txt will
668
728
// overwrite the default settings
669
- setTheEnvironmentVariablesSetTheDefaults (contribEnv , confDesc , platformFilename , firstTime );
729
+ setTheEnvironmentVariablesSetTheDefaults (contribEnv , confDesc , platformFilename );
670
730
try {
671
731
// process the platform.txt file first. This way the boards.txt will
672
732
// overwrite the default settings
@@ -904,4 +964,7 @@ static public String GetIDEVersion(Path arduinoIDEPath) {
904
964
}
905
965
}
906
966
967
+ private static String makeEnvironmentVar (String string ) {
968
+ return "${" + string + "}" ;
969
+ }
907
970
}
0 commit comments