@@ -88,29 +88,29 @@ public boolean compile(boolean _verbose) throws RunnerException {
88
88
89
89
// 0. include paths for core + all libraries
90
90
sketch .setCompilingProgress (20 );
91
- List <String > includePaths = new ArrayList <String >();
92
- includePaths .add (prefs .get ("build.core.path" ));
93
- if (prefs .get ("build.variant.path" ). length () != 0 )
94
- includePaths .add (prefs .get ("build.variant.path" ));
91
+ List <File > includeFolders = new ArrayList <File >();
92
+ includeFolders .add (prefs .getFile ("build.core.path" ));
93
+ if (prefs .getFile ("build.variant.path" ) != null )
94
+ includeFolders .add (prefs .getFile ("build.variant.path" ));
95
95
for (Library lib : sketch .getImportedLibraries ()) {
96
96
if (verbose )
97
97
System .out .println (I18n
98
98
.format (_ ("Using library {0} in folder: {1} {2}" ), lib .getName (),
99
99
lib .getFolder (), lib .isLegacy () ? "(legacy)" : "" ));
100
- includePaths .add (lib .getSrcFolder (). getPath ());
100
+ includeFolders .add (lib .getSrcFolder ());
101
101
}
102
102
if (verbose )
103
103
System .out .println ();
104
104
105
105
// 1. compile the sketch (already in the buildPath)
106
106
sketch .setCompilingProgress (30 );
107
- compileSketch (includePaths );
107
+ compileSketch (includeFolders );
108
108
sketchIsCompiled = true ;
109
109
110
110
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
111
111
// Doesn't really use configPreferences
112
112
sketch .setCompilingProgress (40 );
113
- compileLibraries (includePaths );
113
+ compileLibraries (includeFolders );
114
114
115
115
// 3. compile the core, outputting .o files to <buildPath> and then
116
116
// collecting them into the core.a library file.
@@ -119,15 +119,15 @@ public boolean compile(boolean _verbose) throws RunnerException {
119
119
120
120
// 4. link it all together into the .elf file
121
121
sketch .setCompilingProgress (60 );
122
- compileLink (includePaths );
122
+ compileLink ();
123
123
124
124
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
125
125
sketch .setCompilingProgress (70 );
126
- compileEep (includePaths );
126
+ compileEep ();
127
127
128
128
// 6. build the .hex file
129
129
sketch .setCompilingProgress (80 );
130
- compileHex (includePaths );
130
+ compileHex ();
131
131
132
132
sketch .setCompilingProgress (90 );
133
133
return true ;
@@ -217,45 +217,38 @@ private PreferencesMap createBuildPreferences(String _buildPath,
217
217
return p ;
218
218
}
219
219
220
- private List <File > compileFiles (String outputPath , File sourcePath ,
221
- boolean recurse , List <String > includePaths )
220
+ private List <File > compileFiles (File outputPath , File sourcePath ,
221
+ boolean recurse , List <File > includeFolders )
222
222
throws RunnerException {
223
223
List <File > sSources = findFilesInFolder (sourcePath , "S" , recurse );
224
224
List <File > cSources = findFilesInFolder (sourcePath , "c" , recurse );
225
225
List <File > cppSources = findFilesInFolder (sourcePath , "cpp" , recurse );
226
226
List <File > objectPaths = new ArrayList <File >();
227
227
228
228
for (File file : sSources ) {
229
- String objectPath = outputPath + File .separator + file .getName () + ".o" ;
230
- objectPaths .add (new File (objectPath ));
231
- String [] cmd = getCommandCompilerS (includePaths , file .getAbsolutePath (),
232
- objectPath );
229
+ File objectFile = new File (outputPath , file .getName () + ".o" );
230
+ objectPaths .add (objectFile );
231
+ String [] cmd = getCommandCompilerS (includeFolders , file , objectFile );
233
232
execAsynchronously (cmd );
234
233
}
235
234
236
235
for (File file : cSources ) {
237
- String objectPath = outputPath + File .separator + file .getName () + ".o" ;
238
- String dependPath = outputPath + File .separator + file .getName () + ".d" ;
239
- File objectFile = new File (objectPath );
240
- File dependFile = new File (dependPath );
236
+ File objectFile = new File (outputPath , file .getName () + ".o" );
237
+ File dependFile = new File (outputPath , file .getName () + ".d" );
241
238
objectPaths .add (objectFile );
242
239
if (isAlreadyCompiled (file , objectFile , dependFile , prefs ))
243
240
continue ;
244
- String [] cmd = getCommandCompilerC (includePaths , file .getAbsolutePath (),
245
- objectPath );
241
+ String [] cmd = getCommandCompilerC (includeFolders , file , objectFile );
246
242
execAsynchronously (cmd );
247
243
}
248
244
249
245
for (File file : cppSources ) {
250
- String objectPath = outputPath + File .separator + file .getName () + ".o" ;
251
- String dependPath = outputPath + File .separator + file .getName () + ".d" ;
252
- File objectFile = new File (objectPath );
253
- File dependFile = new File (dependPath );
246
+ File objectFile = new File (outputPath , file .getName () + ".o" );
247
+ File dependFile = new File (outputPath , file .getName () + ".d" );
254
248
objectPaths .add (objectFile );
255
249
if (isAlreadyCompiled (file , objectFile , dependFile , prefs ))
256
250
continue ;
257
- String [] cmd = getCommandCompilerCPP (includePaths ,
258
- file .getAbsolutePath (), objectPath );
251
+ String [] cmd = getCommandCompilerCPP (includeFolders , file , objectFile );
259
252
execAsynchronously (cmd );
260
253
}
261
254
@@ -510,15 +503,15 @@ public void message(String s) {
510
503
System .err .print (s );
511
504
}
512
505
513
- private String [] getCommandCompilerS (List <String > includePaths ,
514
- String sourceName , String objectName )
506
+ private String [] getCommandCompilerS (List <File > includeFolders ,
507
+ File sourceFile , File objectFile )
515
508
throws RunnerException {
516
- String includes = preparePaths ( includePaths );
509
+ String includes = prepareIncludes ( includeFolders );
517
510
PreferencesMap dict = new PreferencesMap (prefs );
518
511
dict .put ("ide_version" , "" + Base .REVISION );
519
512
dict .put ("includes" , includes );
520
- dict .put ("source_file" , sourceName );
521
- dict .put ("object_file" , objectName );
513
+ dict .put ("source_file" , sourceFile . getAbsolutePath () );
514
+ dict .put ("object_file" , objectFile . getAbsolutePath () );
522
515
523
516
try {
524
517
String cmd = prefs .get ("recipe.S.o.pattern" );
@@ -528,16 +521,16 @@ private String[] getCommandCompilerS(List<String> includePaths,
528
521
}
529
522
}
530
523
531
- private String [] getCommandCompilerC (List <String > includePaths ,
532
- String sourceName , String objectName )
524
+ private String [] getCommandCompilerC (List <File > includeFolders ,
525
+ File sourceFile , File objectFile )
533
526
throws RunnerException {
534
- String includes = preparePaths ( includePaths );
527
+ String includes = prepareIncludes ( includeFolders );
535
528
536
529
PreferencesMap dict = new PreferencesMap (prefs );
537
530
dict .put ("ide_version" , "" + Base .REVISION );
538
531
dict .put ("includes" , includes );
539
- dict .put ("source_file" , sourceName );
540
- dict .put ("object_file" , objectName );
532
+ dict .put ("source_file" , sourceFile . getAbsolutePath () );
533
+ dict .put ("object_file" , objectFile . getAbsolutePath () );
541
534
542
535
String cmd = prefs .get ("recipe.c.o.pattern" );
543
536
try {
@@ -547,16 +540,16 @@ private String[] getCommandCompilerC(List<String> includePaths,
547
540
}
548
541
}
549
542
550
- private String [] getCommandCompilerCPP (List <String > includePaths ,
551
- String sourceName , String objectName )
543
+ private String [] getCommandCompilerCPP (List <File > includeFolders ,
544
+ File sourceFile , File objectFile )
552
545
throws RunnerException {
553
- String includes = preparePaths ( includePaths );
546
+ String includes = prepareIncludes ( includeFolders );
554
547
555
548
PreferencesMap dict = new PreferencesMap (prefs );
556
549
dict .put ("ide_version" , "" + Base .REVISION );
557
550
dict .put ("includes" , includes );
558
- dict .put ("source_file" , sourceName );
559
- dict .put ("object_file" , objectName );
551
+ dict .put ("source_file" , sourceFile . getAbsolutePath () );
552
+ dict .put ("object_file" , objectFile . getAbsolutePath () );
560
553
561
554
String cmd = prefs .get ("recipe.cpp.o.pattern" );
562
555
try {
@@ -605,29 +598,28 @@ static public List<File> findFilesInFolder(File folder, String extension,
605
598
}
606
599
607
600
// 1. compile the sketch (already in the buildPath)
608
- void compileSketch (List <String > includePaths ) throws RunnerException {
609
- String buildPath = prefs .get ("build.path" );
610
- objectFiles .addAll (compileFiles (buildPath , new File (buildPath ), false ,
611
- includePaths ));
601
+ void compileSketch (List <File > includeFolders ) throws RunnerException {
602
+ File buildPath = prefs .getFile ("build.path" );
603
+ objectFiles .addAll (compileFiles (buildPath , buildPath , false , includeFolders ));
612
604
}
613
605
614
606
// 2. compile the libraries, outputting .o files to:
615
607
// <buildPath>/<library>/
616
- void compileLibraries (List <String > includePaths ) throws RunnerException {
608
+ void compileLibraries (List <File > includeFolders ) throws RunnerException {
617
609
for (Library lib : sketch .getImportedLibraries ()) {
618
- compileLibrary (lib , includePaths );
610
+ compileLibrary (lib , includeFolders );
619
611
}
620
612
}
621
613
622
- private void compileLibrary (Library lib , List <String > includePaths )
614
+ private void compileLibrary (Library lib , List <File > includeFolders )
623
615
throws RunnerException {
624
616
File libFolder = lib .getSrcFolder ();
625
- File libBuildFolder = new File ( prefs .get ("build.path" ), lib .getName ());
617
+ File libBuildFolder = prefs .getFile ( ("build.path" ), lib .getName ());
626
618
627
619
if (lib .useRecursion ()) {
628
620
// libBuildFolder == {build.path}/LibName
629
621
// libFolder == {lib.path}/src
630
- recursiveCompileFilesInFolder (libBuildFolder , libFolder , includePaths );
622
+ recursiveCompileFilesInFolder (libBuildFolder , libFolder , includeFolders );
631
623
632
624
} else {
633
625
// libFolder == {lib.path}/
@@ -637,26 +629,26 @@ private void compileLibrary(Library lib, List<String> includePaths)
637
629
File utilityFolder = new File (libFolder , "utility" );
638
630
File utilityBuildFolder = new File (libBuildFolder , "utility" );
639
631
640
- includePaths .add (utilityFolder . getAbsolutePath () );
641
- compileFilesInFolder (libBuildFolder , libFolder , includePaths );
642
- compileFilesInFolder (utilityBuildFolder , utilityFolder , includePaths );
632
+ includeFolders .add (utilityFolder );
633
+ compileFilesInFolder (libBuildFolder , libFolder , includeFolders );
634
+ compileFilesInFolder (utilityBuildFolder , utilityFolder , includeFolders );
643
635
644
636
// other libraries should not see this library's utility/ folder
645
- includePaths .remove (utilityFolder . getAbsolutePath () );
637
+ includeFolders .remove (utilityFolder );
646
638
}
647
639
}
648
640
649
- private void recursiveCompileFilesInFolder (File srcBuildFolder , File srcFolder , List <String > includePaths ) throws RunnerException {
650
- compileFilesInFolder (srcBuildFolder , srcFolder , includePaths );
641
+ private void recursiveCompileFilesInFolder (File srcBuildFolder , File srcFolder , List <File > includeFolders ) throws RunnerException {
642
+ compileFilesInFolder (srcBuildFolder , srcFolder , includeFolders );
651
643
for (File subFolder : srcFolder .listFiles (new OnlyDirs ())) {
652
644
File subBuildFolder = new File (srcBuildFolder , subFolder .getName ());
653
- recursiveCompileFilesInFolder (subBuildFolder , subFolder , includePaths );
645
+ recursiveCompileFilesInFolder (subBuildFolder , subFolder , includeFolders );
654
646
}
655
647
}
656
648
657
- private void compileFilesInFolder (File buildFolder , File srcFolder , List <String > includePaths ) throws RunnerException {
649
+ private void compileFilesInFolder (File buildFolder , File srcFolder , List <File > includeFolders ) throws RunnerException {
658
650
createFolder (buildFolder );
659
- List <File > objects = compileFiles (buildFolder . getAbsolutePath () , srcFolder , false , includePaths );
651
+ List <File > objects = compileFiles (buildFolder , srcFolder , false , includeFolders );
660
652
objectFiles .addAll (objects );
661
653
}
662
654
@@ -665,22 +657,22 @@ private void compileFilesInFolder(File buildFolder, File srcFolder, List<String>
665
657
void compileCore ()
666
658
throws RunnerException {
667
659
668
- String corePath = prefs .get ("build.core.path" );
669
- String variantPath = prefs .get ("build.variant.path" );
670
- String buildPath = prefs .get ("build.path" );
660
+ File coreFolder = prefs .getFile ("build.core.path" );
661
+ File variantFolder = prefs .getFile ("build.variant.path" );
662
+ File buildFolder = prefs .getFile ("build.path" );
671
663
672
- List <String > includePaths = new ArrayList <String >();
673
- includePaths .add (corePath ); // include core path only
674
- if (variantPath . length () != 0 )
675
- includePaths .add (variantPath );
664
+ List <File > includeFolders = new ArrayList <File >();
665
+ includeFolders .add (coreFolder ); // include core path only
666
+ if (variantFolder != null )
667
+ includeFolders .add (variantFolder );
676
668
677
- List <File > coreObjectFiles = compileFiles (buildPath , new File ( corePath ) ,
678
- true , includePaths );
679
- if (variantPath . length () != 0 )
680
- coreObjectFiles .addAll (compileFiles (buildPath , new File ( variantPath ) ,
681
- true , includePaths ));
669
+ List <File > objectFiles = compileFiles (buildFolder , coreFolder , true ,
670
+ includeFolders );
671
+ if (variantFolder != null )
672
+ objectFiles .addAll (compileFiles (buildFolder , variantFolder , true ,
673
+ includeFolders ));
682
674
683
- for (File file : coreObjectFiles ) {
675
+ for (File file : objectFiles ) {
684
676
685
677
PreferencesMap dict = new PreferencesMap (prefs );
686
678
dict .put ("ide_version" , "" + Base .REVISION );
@@ -699,7 +691,7 @@ void compileCore()
699
691
}
700
692
701
693
// 4. link it all together into the .elf file
702
- void compileLink (List < String > includePaths )
694
+ void compileLink ()
703
695
throws RunnerException {
704
696
705
697
// TODO: Make the --relax thing in configuration files.
@@ -733,7 +725,7 @@ void compileLink(List<String> includePaths)
733
725
}
734
726
735
727
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
736
- void compileEep (List < String > includePaths ) throws RunnerException {
728
+ void compileEep () throws RunnerException {
737
729
PreferencesMap dict = new PreferencesMap (prefs );
738
730
dict .put ("ide_version" , "" + Base .REVISION );
739
731
@@ -748,7 +740,7 @@ void compileEep(List<String> includePaths) throws RunnerException {
748
740
}
749
741
750
742
// 6. build the .hex file
751
- void compileHex (List < String > includePaths ) throws RunnerException {
743
+ void compileHex () throws RunnerException {
752
744
PreferencesMap dict = new PreferencesMap (prefs );
753
745
dict .put ("ide_version" , "" + Base .REVISION );
754
746
@@ -762,10 +754,10 @@ void compileHex(List<String> includePaths) throws RunnerException {
762
754
execAsynchronously (cmdArray );
763
755
}
764
756
765
- private static String preparePaths (List <String > includePaths ) {
757
+ private static String prepareIncludes (List <File > includeFolders ) {
766
758
String res = "" ;
767
- for (String p : includePaths )
768
- res += " \" -I" + p + '"' ;
759
+ for (File p : includeFolders )
760
+ res += " \" -I" + p . getAbsolutePath () + '"' ;
769
761
770
762
// Remove first space
771
763
return res .substring (1 );
0 commit comments