4949import processing .app .PreferencesData ;
5050import processing .app .SketchCode ;
5151import 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 .*;
5653import processing .app .helpers .filefilters .OnlyDirs ;
5754import processing .app .packages .Library ;
5855import processing .app .packages .LibraryList ;
@@ -86,7 +83,7 @@ public interface ProgressListener {
8683
8784 private ProgressListener progressListener ;
8885
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 {
9087 if (SketchData .checkSketchFile (data .getPrimaryFile ()) == null )
9188 BaseNoGui .showError (_ ("Bad file selected" ),
9289 _ ("Bad sketch primary file or bad sketck directory structure" ), null );
@@ -338,12 +335,12 @@ protected void size(PreferencesMap prefs) throws RunnerException {
338335
339336 /**
340337 * Compile sketch.
341- * @param buildPath
338+ * @param _verbose
342339 *
343340 * @return true if successful.
344341 * @throws RunnerException Only if there's a problem. Only then.
345342 */
346- public boolean compile (boolean _verbose ) throws RunnerException {
343+ public boolean compile (boolean _verbose ) throws RunnerException , PreferencesMapException {
347344 preprocess (prefs .get ("build.path" ));
348345
349346 verbose = _verbose || PreferencesData .getBoolean ("build.verbose" );
@@ -404,11 +401,11 @@ public boolean compile(boolean _verbose) throws RunnerException {
404401
405402 // 5. extract EEPROM data (from EEMEM directive) to .eep file.
406403 progressListener .progress (70 );
407- compileEep ( );
404+ runRecipe ( "recipe.objcopy.eep.pattern" );
408405
409406 // 6. build the .hex file
410407 progressListener .progress (80 );
411- compileHex ( );
408+ runRecipe ( "recipe.objcopy.hex.pattern" );
412409
413410 progressListener .progress (90 );
414411 return true ;
@@ -505,7 +502,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
505502
506503 private List <File > compileFiles (File outputPath , File sourcePath ,
507504 boolean recurse , List <File > includeFolders )
508- throws RunnerException {
505+ throws RunnerException , PreferencesMapException {
509506 List <File > sSources = findFilesInFolder (sourcePath , "S" , recurse );
510507 List <File > cSources = findFilesInFolder (sourcePath , "c" , recurse );
511508 List <File > cppSources = findFilesInFolder (sourcePath , "cpp" , recurse );
@@ -514,7 +511,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
514511 for (File file : sSources ) {
515512 File objectFile = new File (outputPath , file .getName () + ".o" );
516513 objectPaths .add (objectFile );
517- String [] cmd = getCommandCompilerS (includeFolders , file , objectFile );
514+ String [] cmd = getCommandCompilerByRecipe (includeFolders , file , objectFile , "recipe.S.o.pattern" );
518515 execAsynchronously (cmd );
519516 }
520517
@@ -524,7 +521,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
524521 objectPaths .add (objectFile );
525522 if (isAlreadyCompiled (file , objectFile , dependFile , prefs ))
526523 continue ;
527- String [] cmd = getCommandCompilerC (includeFolders , file , objectFile );
524+ String [] cmd = getCommandCompilerByRecipe (includeFolders , file , objectFile , "recipe.c.o.pattern" );
528525 execAsynchronously (cmd );
529526 }
530527
@@ -534,7 +531,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
534531 objectPaths .add (objectFile );
535532 if (isAlreadyCompiled (file , objectFile , dependFile , prefs ))
536533 continue ;
537- String [] cmd = getCommandCompilerCPP (includeFolders , file , objectFile );
534+ String [] cmd = getCommandCompilerByRecipe (includeFolders , file , objectFile , "recipe.cpp.o.pattern" );
538535 execAsynchronously (cmd );
539536 }
540537
@@ -545,7 +542,7 @@ private List<File> compileFiles(File outputPath, File sourcePath,
545542 * Strip escape sequences used in makefile dependency files (.d)
546543 * https://github.com/arduino/Arduino/issues/2255#issuecomment-57645845
547544 *
548- * @param dep
545+ * @param line
549546 * @return
550547 */
551548 protected static String unescapeDepFile (String line ) {
@@ -814,55 +811,15 @@ public void message(String s) {
814811 System .err .print (s );
815812 }
816813
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 {
857815 String includes = prepareIncludes (includeFolders );
858-
859816 PreferencesMap dict = new PreferencesMap (prefs );
860817 dict .put ("ide_version" , "" + BaseNoGui .REVISION );
861818 dict .put ("includes" , includes );
862819 dict .put ("source_file" , sourceFile .getAbsolutePath ());
863820 dict .put ("object_file" , objectFile .getAbsolutePath ());
864821
865- String cmd = prefs .get ( " recipe.cpp.o.pattern" );
822+ String cmd = prefs .getOrExcept ( recipe );
866823 try {
867824 return StringReplacer .formatAndSplit (cmd , dict , true );
868825 } catch (Exception e ) {
@@ -909,21 +866,21 @@ static public List<File> findFilesInFolder(File folder, String extension,
909866 }
910867
911868 // 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 {
913870 File buildPath = prefs .getFile ("build.path" );
914871 objectFiles .addAll (compileFiles (buildPath , buildPath , false , includeFolders ));
915872 }
916873
917874 // 2. compile the libraries, outputting .o files to:
918875 // <buildPath>/<library>/
919- void compileLibraries (List <File > includeFolders ) throws RunnerException {
876+ void compileLibraries (List <File > includeFolders ) throws RunnerException , PreferencesMapException {
920877 for (Library lib : importedLibraries ) {
921878 compileLibrary (lib , includeFolders );
922879 }
923880 }
924881
925882 private void compileLibrary (Library lib , List <File > includeFolders )
926- throws RunnerException {
883+ throws RunnerException , PreferencesMapException {
927884 File libFolder = lib .getSrcFolder ();
928885 File libBuildFolder = prefs .getFile (("build.path" ), lib .getName ());
929886
@@ -949,15 +906,15 @@ private void compileLibrary(Library lib, List<File> includeFolders)
949906 }
950907 }
951908
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 {
953910 compileFilesInFolder (srcBuildFolder , srcFolder , includeFolders );
954911 for (File subFolder : srcFolder .listFiles (new OnlyDirs ())) {
955912 File subBuildFolder = new File (srcBuildFolder , subFolder .getName ());
956913 recursiveCompileFilesInFolder (subBuildFolder , subFolder , includeFolders );
957914 }
958915 }
959916
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 {
961918 createFolder (buildFolder );
962919 List <File > objects = compileFiles (buildFolder , srcFolder , false , includeFolders );
963920 objectFiles .addAll (objects );
@@ -968,7 +925,7 @@ private void compileFilesInFolder(File buildFolder, File srcFolder, List<File> i
968925 // Also compiles the variant (if it supplies actual source files),
969926 // which are included in the link directly (not through core.a)
970927 void compileCore ()
971- throws RunnerException {
928+ throws RunnerException , PreferencesMapException {
972929
973930 File coreFolder = prefs .getFile ("build.core.path" );
974931 File variantFolder = prefs .getFile ("build.variant.path" );
@@ -1024,8 +981,8 @@ void compileCore()
1024981 dict .put ("object_file" , file .getAbsolutePath ());
1025982
1026983 String [] cmdArray ;
984+ String cmd = prefs .getOrExcept ("recipe.ar.pattern" );
1027985 try {
1028- String cmd = prefs .get ("recipe.ar.pattern" );
1029986 cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
1030987 } catch (Exception e ) {
1031988 throw new RunnerException (e );
@@ -1040,7 +997,7 @@ void compileCore()
1040997
1041998 // 4. link it all together into the .elf file
1042999 void compileLink ()
1043- throws RunnerException {
1000+ throws RunnerException , PreferencesMapException {
10441001
10451002 // TODO: Make the --relax thing in configuration files.
10461003
@@ -1063,38 +1020,22 @@ void compileLink()
10631020 dict .put ("ide_version" , "" + BaseNoGui .REVISION );
10641021
10651022 String [] cmdArray ;
1023+ String cmd = prefs .getOrExcept ("recipe.c.combine.pattern" );
10661024 try {
1067- String cmd = prefs .get ("recipe.c.combine.pattern" );
10681025 cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
10691026 } catch (Exception e ) {
10701027 throw new RunnerException (e );
10711028 }
10721029 execAsynchronously (cmdArray );
10731030 }
10741031
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 {
10921033 PreferencesMap dict = new PreferencesMap (prefs );
10931034 dict .put ("ide_version" , "" + BaseNoGui .REVISION );
10941035
10951036 String [] cmdArray ;
1037+ String cmd = prefs .getOrExcept (recipe );
10961038 try {
1097- String cmd = prefs .get ("recipe.objcopy.hex.pattern" );
10981039 cmdArray = StringReplacer .formatAndSplit (cmd , dict , true );
10991040 } catch (Exception e ) {
11001041 throw new RunnerException (e );
0 commit comments