49
49
import processing .app .PreferencesData ;
50
50
import processing .app .SketchCode ;
51
51
import processing .app .SketchData ;
52
- import processing .app .helpers .FileUtils ;
53
- import processing .app .helpers .PreferencesMap ;
54
- import processing .app .helpers .ProcessUtils ;
55
- import processing .app .helpers .StringReplacer ;
52
+ import processing .app .helpers .*;
56
53
import processing .app .helpers .filefilters .OnlyDirs ;
57
54
import processing .app .packages .Library ;
58
55
import processing .app .packages .LibraryList ;
@@ -86,7 +83,7 @@ public interface ProgressListener {
86
83
87
84
private ProgressListener progressListener ;
88
85
89
- static public String build (SketchData data , String buildPath , File tempBuildFolder , ProgressListener progListener , boolean verbose ) throws RunnerException {
86
+ static public String build (SketchData data , String buildPath , File tempBuildFolder , ProgressListener progListener , boolean verbose ) throws RunnerException , PreferencesMapException {
90
87
if (SketchData .checkSketchFile (data .getPrimaryFile ()) == null )
91
88
BaseNoGui .showError (_ ("Bad file selected" ),
92
89
_ ("Bad sketch primary file or bad sketck directory structure" ), null );
@@ -338,12 +335,12 @@ protected void size(PreferencesMap prefs) throws RunnerException {
338
335
339
336
/**
340
337
* Compile sketch.
341
- * @param buildPath
338
+ * @param _verbose
342
339
*
343
340
* @return true if successful.
344
341
* @throws RunnerException Only if there's a problem. Only then.
345
342
*/
346
- public boolean compile (boolean _verbose ) throws RunnerException {
343
+ public boolean compile (boolean _verbose ) throws RunnerException , PreferencesMapException {
347
344
preprocess (prefs .get ("build.path" ));
348
345
349
346
verbose = _verbose || PreferencesData .getBoolean ("build.verbose" );
@@ -404,11 +401,11 @@ public boolean compile(boolean _verbose) throws RunnerException {
404
401
405
402
// 5. extract EEPROM data (from EEMEM directive) to .eep file.
406
403
progressListener .progress (70 );
407
- compileEep ( );
404
+ runRecipe ( "recipe.objcopy.eep.pattern" );
408
405
409
406
// 6. build the .hex file
410
407
progressListener .progress (80 );
411
- compileHex ( );
408
+ runRecipe ( "recipe.objcopy.hex.pattern" );
412
409
413
410
progressListener .progress (90 );
414
411
return true ;
@@ -505,7 +502,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
505
502
506
503
private List <File > compileFiles (File outputPath , File sourcePath ,
507
504
boolean recurse , List <File > includeFolders )
508
- throws RunnerException {
505
+ throws RunnerException , PreferencesMapException {
509
506
List <File > sSources = findFilesInFolder (sourcePath , "S" , recurse );
510
507
List <File > cSources = findFilesInFolder (sourcePath , "c" , recurse );
511
508
List <File > cppSources = findFilesInFolder (sourcePath , "cpp" , recurse );
@@ -514,7 +511,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
514
511
for (File file : sSources ) {
515
512
File objectFile = new File (outputPath , file .getName () + ".o" );
516
513
objectPaths .add (objectFile );
517
- String [] cmd = getCommandCompilerS (includeFolders , file , objectFile );
514
+ String [] cmd = getCommandCompilerByRecipe (includeFolders , file , objectFile , "recipe.S.o.pattern" );
518
515
execAsynchronously (cmd );
519
516
}
520
517
@@ -524,7 +521,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
524
521
objectPaths .add (objectFile );
525
522
if (isAlreadyCompiled (file , objectFile , dependFile , prefs ))
526
523
continue ;
527
- String [] cmd = getCommandCompilerC (includeFolders , file , objectFile );
524
+ String [] cmd = getCommandCompilerByRecipe (includeFolders , file , objectFile , "recipe.c.o.pattern" );
528
525
execAsynchronously (cmd );
529
526
}
530
527
@@ -534,7 +531,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
534
531
objectPaths .add (objectFile );
535
532
if (isAlreadyCompiled (file , objectFile , dependFile , prefs ))
536
533
continue ;
537
- String [] cmd = getCommandCompilerCPP (includeFolders , file , objectFile );
534
+ String [] cmd = getCommandCompilerByRecipe (includeFolders , file , objectFile , "recipe.cpp.o.pattern" );
538
535
execAsynchronously (cmd );
539
536
}
540
537
@@ -545,7 +542,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
545
542
* Strip escape sequences used in makefile dependency files (.d)
546
543
* https://github.com/arduino/Arduino/issues/2255#issuecomment-57645845
547
544
*
548
- * @param dep
545
+ * @param line
549
546
* @return
550
547
*/
551
548
protected static String unescapeDepFile (String line ) {
@@ -814,55 +811,15 @@ public void message(String s) {
814
811
System .err .print (s );
815
812
}
816
813
817
- private String [] getCommandCompilerS (List <File > includeFolders ,
818
- File sourceFile , File objectFile )
819
- throws RunnerException {
820
- String includes = prepareIncludes (includeFolders );
821
- PreferencesMap dict = new PreferencesMap (prefs );
822
- dict .put ("ide_version" , "" + BaseNoGui .REVISION );
823
- dict .put ("includes" , includes );
824
- dict .put ("source_file" , sourceFile .getAbsolutePath ());
825
- dict .put ("object_file" , objectFile .getAbsolutePath ());
826
-
827
- try {
828
- String cmd = prefs .get ("recipe.S.o.pattern" );
829
- return StringReplacer .formatAndSplit (cmd , dict , true );
830
- } catch (Exception e ) {
831
- throw new RunnerException (e );
832
- }
833
- }
834
-
835
- private String [] getCommandCompilerC (List <File > includeFolders ,
836
- File sourceFile , File objectFile )
837
- throws RunnerException {
838
- String includes = prepareIncludes (includeFolders );
839
-
840
- PreferencesMap dict = new PreferencesMap (prefs );
841
- dict .put ("ide_version" , "" + BaseNoGui .REVISION );
842
- dict .put ("includes" , includes );
843
- dict .put ("source_file" , sourceFile .getAbsolutePath ());
844
- dict .put ("object_file" , objectFile .getAbsolutePath ());
845
-
846
- String cmd = prefs .get ("recipe.c.o.pattern" );
847
- try {
848
- return StringReplacer .formatAndSplit (cmd , dict , true );
849
- } catch (Exception e ) {
850
- throw new RunnerException (e );
851
- }
852
- }
853
-
854
- private String [] getCommandCompilerCPP (List <File > includeFolders ,
855
- File sourceFile , File objectFile )
856
- throws RunnerException {
814
+ private String [] getCommandCompilerByRecipe (List <File > includeFolders , File sourceFile , File objectFile , String recipe ) throws PreferencesMapException , RunnerException {
857
815
String includes = prepareIncludes (includeFolders );
858
-
859
816
PreferencesMap dict = new PreferencesMap (prefs );
860
817
dict .put ("ide_version" , "" + BaseNoGui .REVISION );
861
818
dict .put ("includes" , includes );
862
819
dict .put ("source_file" , sourceFile .getAbsolutePath ());
863
820
dict .put ("object_file" , objectFile .getAbsolutePath ());
864
821
865
- String cmd = prefs .get ( " recipe.cpp.o.pattern" );
822
+ String cmd = prefs .getOrExcept ( recipe );
866
823
try {
867
824
return StringReplacer .formatAndSplit (cmd , dict , true );
868
825
} catch (Exception e ) {
@@ -909,21 +866,21 @@ static public List<File> findFilesInFolder(File folder, String extension,
909
866
}
910
867
911
868
// 1. compile the sketch (already in the buildPath)
912
- void compileSketch (List <File > includeFolders ) throws RunnerException {
869
+ void compileSketch (List <File > includeFolders ) throws RunnerException , PreferencesMapException {
913
870
File buildPath = prefs .getFile ("build.path" );
914
871
objectFiles .addAll (compileFiles (buildPath , buildPath , false , includeFolders ));
915
872
}
916
873
917
874
// 2. compile the libraries, outputting .o files to:
918
875
// <buildPath>/<library>/
919
- void compileLibraries (List <File > includeFolders ) throws RunnerException {
876
+ void compileLibraries (List <File > includeFolders ) throws RunnerException , PreferencesMapException {
920
877
for (Library lib : importedLibraries ) {
921
878
compileLibrary (lib , includeFolders );
922
879
}
923
880
}
924
881
925
882
private void compileLibrary (Library lib , List <File > includeFolders )
926
- throws RunnerException {
883
+ throws RunnerException , PreferencesMapException {
927
884
File libFolder = lib .getSrcFolder ();
928
885
File libBuildFolder = prefs .getFile (("build.path" ), lib .getName ());
929
886
@@ -949,15 +906,15 @@ private void compileLibrary(Library lib, List<File> includeFolders)
949
906
}
950
907
}
951
908
952
- private void recursiveCompileFilesInFolder (File srcBuildFolder , File srcFolder , List <File > includeFolders ) throws RunnerException {
909
+ private void recursiveCompileFilesInFolder (File srcBuildFolder , File srcFolder , List <File > includeFolders ) throws RunnerException , PreferencesMapException {
953
910
compileFilesInFolder (srcBuildFolder , srcFolder , includeFolders );
954
911
for (File subFolder : srcFolder .listFiles (new OnlyDirs ())) {
955
912
File subBuildFolder = new File (srcBuildFolder , subFolder .getName ());
956
913
recursiveCompileFilesInFolder (subBuildFolder , subFolder , includeFolders );
957
914
}
958
915
}
959
916
960
- private void compileFilesInFolder (File buildFolder , File srcFolder , List <File > includeFolders ) throws RunnerException {
917
+ private void compileFilesInFolder (File buildFolder , File srcFolder , List <File > includeFolders ) throws RunnerException , PreferencesMapException {
961
918
createFolder (buildFolder );
962
919
List <File > objects = compileFiles (buildFolder , srcFolder , false , includeFolders );
963
920
objectFiles .addAll (objects );
@@ -968,7 +925,7 @@ private void compileFilesInFolder(File buildFolder, File srcFolder, List<File> i
968
925
// Also compiles the variant (if it supplies actual source files),
969
926
// which are included in the link directly (not through core.a)
970
927
void compileCore ()
971
- throws RunnerException {
928
+ throws RunnerException , PreferencesMapException {
972
929
973
930
File coreFolder = prefs .getFile ("build.core.path" );
974
931
File variantFolder = prefs .getFile ("build.variant.path" );
@@ -1024,8 +981,8 @@ void compileCore()
1024
981
dict .put ("object_file" , file .getAbsolutePath ());
1025
982
1026
983
String [] cmdArray ;
984
+ String cmd = prefs .getOrExcept ("recipe.ar.pattern" );
1027
985
try {
1028
- String cmd = prefs .get ("recipe.ar.pattern" );
1029
986
cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
1030
987
} catch (Exception e ) {
1031
988
throw new RunnerException (e );
@@ -1040,7 +997,7 @@ void compileCore()
1040
997
1041
998
// 4. link it all together into the .elf file
1042
999
void compileLink ()
1043
- throws RunnerException {
1000
+ throws RunnerException , PreferencesMapException {
1044
1001
1045
1002
// TODO: Make the --relax thing in configuration files.
1046
1003
@@ -1063,38 +1020,22 @@ void compileLink()
1063
1020
dict .put ("ide_version" , "" + BaseNoGui .REVISION );
1064
1021
1065
1022
String [] cmdArray ;
1023
+ String cmd = prefs .getOrExcept ("recipe.c.combine.pattern" );
1066
1024
try {
1067
- String cmd = prefs .get ("recipe.c.combine.pattern" );
1068
1025
cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
1069
1026
} catch (Exception e ) {
1070
1027
throw new RunnerException (e );
1071
1028
}
1072
1029
execAsynchronously (cmdArray );
1073
1030
}
1074
1031
1075
- // 5. extract EEPROM data (from EEMEM directive) to .eep file.
1076
- void compileEep () throws RunnerException {
1077
- PreferencesMap dict = new PreferencesMap (prefs );
1078
- dict .put ("ide_version" , "" + BaseNoGui .REVISION );
1079
-
1080
- String [] cmdArray ;
1081
- try {
1082
- String cmd = prefs .get ("recipe.objcopy.eep.pattern" );
1083
- cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
1084
- } catch (Exception e ) {
1085
- throw new RunnerException (e );
1086
- }
1087
- execAsynchronously (cmdArray );
1088
- }
1089
-
1090
- // 6. build the .hex file
1091
- void compileHex () throws RunnerException {
1032
+ void runRecipe (String recipe ) throws RunnerException , PreferencesMapException {
1092
1033
PreferencesMap dict = new PreferencesMap (prefs );
1093
1034
dict .put ("ide_version" , "" + BaseNoGui .REVISION );
1094
1035
1095
1036
String [] cmdArray ;
1037
+ String cmd = prefs .getOrExcept (recipe );
1096
1038
try {
1097
- String cmd = prefs .get ("recipe.objcopy.hex.pattern" );
1098
1039
cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
1099
1040
} catch (Exception e ) {
1100
1041
throw new RunnerException (e );
0 commit comments