From 980709f6f785c0fe524ca05cfc8b1bd4ae764d7a Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Thu, 8 Jan 2015 13:45:17 +0100 Subject: [PATCH 1/4] Compiler: missing mandatory key now blocks compilation --- app/src/processing/app/Editor.java | 8 +++ app/src/processing/app/Sketch.java | 5 +- .../src/processing/app/debug/Compiler.java | 53 +++++++++---------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 47ab58e79..776b454fb 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1924,6 +1924,10 @@ public class Editor extends JFrame implements RunnerListener { sketch.prepare(); sketch.build(false); statusNotice(_("Done compiling.")); + } catch (PreferencesMapException e) { + statusError(I18n.format( + _("Error while compiling: missing '{0}' configuration parameter"), + e.getMessage())); } catch (Exception e) { status.unprogress(); statusError(e); @@ -1941,6 +1945,10 @@ public class Editor extends JFrame implements RunnerListener { sketch.prepare(); sketch.build(true); statusNotice(_("Done compiling.")); + } catch (PreferencesMapException e) { + statusError(I18n.format( + _("Error while compiling: missing '{0}' configuration parameter"), + e.getMessage())); } catch (Exception e) { status.unprogress(); statusError(e); diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 285962755..8a32717f7 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -29,6 +29,7 @@ import processing.app.debug.Compiler.ProgressListener; import processing.app.debug.RunnerException; import processing.app.forms.PasswordAuthorizationDialog; import processing.app.helpers.OSUtils; +import processing.app.helpers.PreferencesMapException; import processing.app.packages.Library; import static processing.app.I18n._; @@ -1129,7 +1130,7 @@ public class Sketch { * @return null if compilation failed, main class name if not * @throws RunnerException */ - public String build(boolean verbose) throws RunnerException { + public String build(boolean verbose) throws RunnerException, PreferencesMapException { return build(tempBuildFolder.getAbsolutePath(), verbose); } @@ -1142,7 +1143,7 @@ public class Sketch { * * @return null if compilation failed, main class name if not */ - public String build(String buildPath, boolean verbose) throws RunnerException { + public String build(String buildPath, boolean verbose) throws RunnerException, PreferencesMapException { // run the preprocessor editor.status.progressUpdate(20); diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index 2088bc5f1..6224d64f1 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -49,10 +49,7 @@ import processing.app.I18n; import processing.app.PreferencesData; import processing.app.SketchCode; import processing.app.SketchData; -import processing.app.helpers.FileUtils; -import processing.app.helpers.PreferencesMap; -import processing.app.helpers.ProcessUtils; -import processing.app.helpers.StringReplacer; +import processing.app.helpers.*; import processing.app.helpers.filefilters.OnlyDirs; import processing.app.packages.Library; import processing.app.packages.LibraryList; @@ -86,7 +83,7 @@ public class Compiler implements MessageConsumer { private ProgressListener progressListener; - static public String build(SketchData data, String buildPath, File tempBuildFolder, ProgressListener progListener, boolean verbose) throws RunnerException { + static public String build(SketchData data, String buildPath, File tempBuildFolder, ProgressListener progListener, boolean verbose) throws RunnerException, PreferencesMapException { if (SketchData.checkSketchFile(data.getPrimaryFile()) == null) BaseNoGui.showError(_("Bad file selected"), _("Bad sketch primary file or bad sketck directory structure"), null); @@ -338,12 +335,12 @@ public class Compiler implements MessageConsumer { /** * Compile sketch. - * @param buildPath + * @param _verbose * * @return true if successful. * @throws RunnerException Only if there's a problem. Only then. */ - public boolean compile(boolean _verbose) throws RunnerException { + public boolean compile(boolean _verbose) throws RunnerException, PreferencesMapException { preprocess(prefs.get("build.path")); verbose = _verbose || PreferencesData.getBoolean("build.verbose"); @@ -505,7 +502,7 @@ public class Compiler implements MessageConsumer { private List compileFiles(File outputPath, File sourcePath, boolean recurse, List includeFolders) - throws RunnerException { + throws RunnerException, PreferencesMapException { List sSources = findFilesInFolder(sourcePath, "S", recurse); List cSources = findFilesInFolder(sourcePath, "c", recurse); List cppSources = findFilesInFolder(sourcePath, "cpp", recurse); @@ -545,7 +542,7 @@ public class Compiler implements MessageConsumer { * Strip escape sequences used in makefile dependency files (.d) * https://github.com/arduino/Arduino/issues/2255#issuecomment-57645845 * - * @param dep + * @param line * @return */ protected static String unescapeDepFile(String line) { @@ -816,7 +813,7 @@ public class Compiler implements MessageConsumer { private String[] getCommandCompilerS(List includeFolders, File sourceFile, File objectFile) - throws RunnerException { + throws RunnerException, PreferencesMapException { String includes = prepareIncludes(includeFolders); PreferencesMap dict = new PreferencesMap(prefs); dict.put("ide_version", "" + BaseNoGui.REVISION); @@ -824,8 +821,8 @@ public class Compiler implements MessageConsumer { dict.put("source_file", sourceFile.getAbsolutePath()); dict.put("object_file", objectFile.getAbsolutePath()); + String cmd = prefs.getOrExcept("recipe.S.o.pattern"); try { - String cmd = prefs.get("recipe.S.o.pattern"); return StringReplacer.formatAndSplit(cmd, dict, true); } catch (Exception e) { throw new RunnerException(e); @@ -834,7 +831,7 @@ public class Compiler implements MessageConsumer { private String[] getCommandCompilerC(List includeFolders, File sourceFile, File objectFile) - throws RunnerException { + throws RunnerException, PreferencesMapException { String includes = prepareIncludes(includeFolders); PreferencesMap dict = new PreferencesMap(prefs); @@ -843,7 +840,7 @@ public class Compiler implements MessageConsumer { dict.put("source_file", sourceFile.getAbsolutePath()); dict.put("object_file", objectFile.getAbsolutePath()); - String cmd = prefs.get("recipe.c.o.pattern"); + String cmd = prefs.getOrExcept("recipe.c.o.pattern"); try { return StringReplacer.formatAndSplit(cmd, dict, true); } catch (Exception e) { @@ -853,7 +850,7 @@ public class Compiler implements MessageConsumer { private String[] getCommandCompilerCPP(List includeFolders, File sourceFile, File objectFile) - throws RunnerException { + throws RunnerException, PreferencesMapException { String includes = prepareIncludes(includeFolders); PreferencesMap dict = new PreferencesMap(prefs); @@ -862,7 +859,7 @@ public class Compiler implements MessageConsumer { dict.put("source_file", sourceFile.getAbsolutePath()); dict.put("object_file", objectFile.getAbsolutePath()); - String cmd = prefs.get("recipe.cpp.o.pattern"); + String cmd = prefs.getOrExcept("recipe.cpp.o.pattern"); try { return StringReplacer.formatAndSplit(cmd, dict, true); } catch (Exception e) { @@ -909,21 +906,21 @@ public class Compiler implements MessageConsumer { } // 1. compile the sketch (already in the buildPath) - void compileSketch(List includeFolders) throws RunnerException { + void compileSketch(List includeFolders) throws RunnerException, PreferencesMapException { File buildPath = prefs.getFile("build.path"); objectFiles.addAll(compileFiles(buildPath, buildPath, false, includeFolders)); } // 2. compile the libraries, outputting .o files to: // // - void compileLibraries(List includeFolders) throws RunnerException { + void compileLibraries(List includeFolders) throws RunnerException, PreferencesMapException { for (Library lib : importedLibraries) { compileLibrary(lib, includeFolders); } } private void compileLibrary(Library lib, List includeFolders) - throws RunnerException { + throws RunnerException, PreferencesMapException { File libFolder = lib.getSrcFolder(); File libBuildFolder = prefs.getFile(("build.path"), lib.getName()); @@ -949,7 +946,7 @@ public class Compiler implements MessageConsumer { } } - private void recursiveCompileFilesInFolder(File srcBuildFolder, File srcFolder, List includeFolders) throws RunnerException { + private void recursiveCompileFilesInFolder(File srcBuildFolder, File srcFolder, List includeFolders) throws RunnerException, PreferencesMapException { compileFilesInFolder(srcBuildFolder, srcFolder, includeFolders); for (File subFolder : srcFolder.listFiles(new OnlyDirs())) { File subBuildFolder = new File(srcBuildFolder, subFolder.getName()); @@ -957,7 +954,7 @@ public class Compiler implements MessageConsumer { } } - private void compileFilesInFolder(File buildFolder, File srcFolder, List includeFolders) throws RunnerException { + private void compileFilesInFolder(File buildFolder, File srcFolder, List includeFolders) throws RunnerException, PreferencesMapException { createFolder(buildFolder); List objects = compileFiles(buildFolder, srcFolder, false, includeFolders); objectFiles.addAll(objects); @@ -968,7 +965,7 @@ public class Compiler implements MessageConsumer { // Also compiles the variant (if it supplies actual source files), // which are included in the link directly (not through core.a) void compileCore() - throws RunnerException { + throws RunnerException, PreferencesMapException { File coreFolder = prefs.getFile("build.core.path"); File variantFolder = prefs.getFile("build.variant.path"); @@ -1024,8 +1021,8 @@ public class Compiler implements MessageConsumer { dict.put("object_file", file.getAbsolutePath()); String[] cmdArray; + String cmd = prefs.getOrExcept("recipe.ar.pattern"); try { - String cmd = prefs.get("recipe.ar.pattern"); cmdArray = StringReplacer.formatAndSplit(cmd, dict, true); } catch (Exception e) { throw new RunnerException(e); @@ -1040,7 +1037,7 @@ public class Compiler implements MessageConsumer { // 4. link it all together into the .elf file void compileLink() - throws RunnerException { + throws RunnerException, PreferencesMapException { // TODO: Make the --relax thing in configuration files. @@ -1063,8 +1060,8 @@ public class Compiler implements MessageConsumer { dict.put("ide_version", "" + BaseNoGui.REVISION); String[] cmdArray; + String cmd = prefs.getOrExcept("recipe.c.combine.pattern"); try { - String cmd = prefs.get("recipe.c.combine.pattern"); cmdArray = StringReplacer.formatAndSplit(cmd, dict, true); } catch (Exception e) { throw new RunnerException(e); @@ -1073,13 +1070,13 @@ public class Compiler implements MessageConsumer { } // 5. extract EEPROM data (from EEMEM directive) to .eep file. - void compileEep() throws RunnerException { + void compileEep() throws RunnerException, PreferencesMapException { PreferencesMap dict = new PreferencesMap(prefs); dict.put("ide_version", "" + BaseNoGui.REVISION); String[] cmdArray; + String cmd = prefs.getOrExcept("recipe.objcopy.eep.pattern"); try { - String cmd = prefs.get("recipe.objcopy.eep.pattern"); cmdArray = StringReplacer.formatAndSplit(cmd, dict, true); } catch (Exception e) { throw new RunnerException(e); @@ -1088,13 +1085,13 @@ public class Compiler implements MessageConsumer { } // 6. build the .hex file - void compileHex() throws RunnerException { + void compileHex() throws RunnerException, PreferencesMapException { PreferencesMap dict = new PreferencesMap(prefs); dict.put("ide_version", "" + BaseNoGui.REVISION); String[] cmdArray; + String cmd = prefs.getOrExcept("recipe.objcopy.hex.pattern"); try { - String cmd = prefs.get("recipe.objcopy.hex.pattern"); cmdArray = StringReplacer.formatAndSplit(cmd, dict, true); } catch (Exception e) { throw new RunnerException(e); From f5520fc7e186351db9f73cf94fbe09f64f9f3086 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Thu, 8 Jan 2015 13:49:51 +0100 Subject: [PATCH 2/4] Compiler: removed duplicated functions compileEep and compileHex in favour of generic runRecipe --- .../src/processing/app/debug/Compiler.java | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index 6224d64f1..82d13f49c 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -401,11 +401,11 @@ public class Compiler implements MessageConsumer { // 5. extract EEPROM data (from EEMEM directive) to .eep file. progressListener.progress(70); - compileEep(); + runRecipe("recipe.objcopy.eep.pattern"); // 6. build the .hex file progressListener.progress(80); - compileHex(); + runRecipe("recipe.objcopy.hex.pattern"); progressListener.progress(90); return true; @@ -1069,28 +1069,12 @@ public class Compiler implements MessageConsumer { execAsynchronously(cmdArray); } - // 5. extract EEPROM data (from EEMEM directive) to .eep file. - void compileEep() throws RunnerException, PreferencesMapException { + void runRecipe(String recipe) throws RunnerException, PreferencesMapException { PreferencesMap dict = new PreferencesMap(prefs); dict.put("ide_version", "" + BaseNoGui.REVISION); String[] cmdArray; - String cmd = prefs.getOrExcept("recipe.objcopy.eep.pattern"); - try { - cmdArray = StringReplacer.formatAndSplit(cmd, dict, true); - } catch (Exception e) { - throw new RunnerException(e); - } - execAsynchronously(cmdArray); - } - - // 6. build the .hex file - void compileHex() throws RunnerException, PreferencesMapException { - PreferencesMap dict = new PreferencesMap(prefs); - dict.put("ide_version", "" + BaseNoGui.REVISION); - - String[] cmdArray; - String cmd = prefs.getOrExcept("recipe.objcopy.hex.pattern"); + String cmd = prefs.getOrExcept(recipe); try { cmdArray = StringReplacer.formatAndSplit(cmd, dict, true); } catch (Exception e) { From fd4a5a82b3976abbf1316ab987b01791de7b1dae Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Thu, 8 Jan 2015 13:54:20 +0100 Subject: [PATCH 3/4] Compiler: removed duplicated functions getCommandCompilerS, getCommandCompilerC, and getCommandCompilerCPP in favour of generic getCommandCompilerByRecipe --- .../src/processing/app/debug/Compiler.java | 50 ++----------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index 82d13f49c..3b6d92e00 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -511,7 +511,7 @@ public class Compiler implements MessageConsumer { for (File file : sSources) { File objectFile = new File(outputPath, file.getName() + ".o"); objectPaths.add(objectFile); - String[] cmd = getCommandCompilerS(includeFolders, file, objectFile); + String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.S.o.pattern"); execAsynchronously(cmd); } @@ -521,7 +521,7 @@ public class Compiler implements MessageConsumer { objectPaths.add(objectFile); if (isAlreadyCompiled(file, objectFile, dependFile, prefs)) continue; - String[] cmd = getCommandCompilerC(includeFolders, file, objectFile); + String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.c.o.pattern"); execAsynchronously(cmd); } @@ -531,7 +531,7 @@ public class Compiler implements MessageConsumer { objectPaths.add(objectFile); if (isAlreadyCompiled(file, objectFile, dependFile, prefs)) continue; - String[] cmd = getCommandCompilerCPP(includeFolders, file, objectFile); + String[] cmd = getCommandCompilerByRecipe(includeFolders, file, objectFile, "recipe.cpp.o.pattern"); execAsynchronously(cmd); } @@ -811,9 +811,7 @@ public class Compiler implements MessageConsumer { System.err.print(s); } - private String[] getCommandCompilerS(List includeFolders, - File sourceFile, File objectFile) - throws RunnerException, PreferencesMapException { + private String[] getCommandCompilerByRecipe(List includeFolders, File sourceFile, File objectFile, String recipe) throws PreferencesMapException, RunnerException { String includes = prepareIncludes(includeFolders); PreferencesMap dict = new PreferencesMap(prefs); dict.put("ide_version", "" + BaseNoGui.REVISION); @@ -821,45 +819,7 @@ public class Compiler implements MessageConsumer { dict.put("source_file", sourceFile.getAbsolutePath()); dict.put("object_file", objectFile.getAbsolutePath()); - String cmd = prefs.getOrExcept("recipe.S.o.pattern"); - try { - return StringReplacer.formatAndSplit(cmd, dict, true); - } catch (Exception e) { - throw new RunnerException(e); - } - } - - private String[] getCommandCompilerC(List includeFolders, - File sourceFile, File objectFile) - throws RunnerException, PreferencesMapException { - String includes = prepareIncludes(includeFolders); - - PreferencesMap dict = new PreferencesMap(prefs); - dict.put("ide_version", "" + BaseNoGui.REVISION); - dict.put("includes", includes); - dict.put("source_file", sourceFile.getAbsolutePath()); - dict.put("object_file", objectFile.getAbsolutePath()); - - String cmd = prefs.getOrExcept("recipe.c.o.pattern"); - try { - return StringReplacer.formatAndSplit(cmd, dict, true); - } catch (Exception e) { - throw new RunnerException(e); - } - } - - private String[] getCommandCompilerCPP(List includeFolders, - File sourceFile, File objectFile) - throws RunnerException, PreferencesMapException { - String includes = prepareIncludes(includeFolders); - - PreferencesMap dict = new PreferencesMap(prefs); - dict.put("ide_version", "" + BaseNoGui.REVISION); - dict.put("includes", includes); - dict.put("source_file", sourceFile.getAbsolutePath()); - dict.put("object_file", objectFile.getAbsolutePath()); - - String cmd = prefs.getOrExcept("recipe.cpp.o.pattern"); + String cmd = prefs.getOrExcept(recipe); try { return StringReplacer.formatAndSplit(cmd, dict, true); } catch (Exception e) { From b16ee6c7b2c8070f3455b7745f4351803e2177e6 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Thu, 8 Jan 2015 14:03:38 +0100 Subject: [PATCH 4/4] Editor: removed duplicated classes DefaultRunHandler, and DefaultPresentHandler in favour of generic BuildHandler --- app/src/processing/app/Editor.java | 43 +++++++++++------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 776b454fb..bd0d6c75c 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1426,8 +1426,8 @@ public class Editor extends JFrame implements RunnerListener { public void resetHandlers() { - runHandler = new DefaultRunHandler(); - presentHandler = new DefaultPresentHandler(); + runHandler = new BuildHandler(); + presentHandler = new BuildHandler(true); stopHandler = new DefaultStopHandler(); exportHandler = new DefaultExportHandler(); exportAppHandler = new DefaultExportAppHandler(); @@ -1917,33 +1917,23 @@ public class Editor extends JFrame implements RunnerListener { new Thread(verbose ? presentHandler : runHandler).start(); } - // DAM: in Arduino, this is compile - class DefaultRunHandler implements Runnable { - public void run() { - try { - sketch.prepare(); - sketch.build(false); - statusNotice(_("Done compiling.")); - } catch (PreferencesMapException e) { - statusError(I18n.format( - _("Error while compiling: missing '{0}' configuration parameter"), - e.getMessage())); - } catch (Exception e) { - status.unprogress(); - statusError(e); - } + class BuildHandler implements Runnable { - status.unprogress(); - toolbar.deactivate(EditorToolbar.RUN); + private final boolean verbose; + + public BuildHandler() { + this(false); } - } - // DAM: in Arduino, this is compile (with verbose output) - class DefaultPresentHandler implements Runnable { + public BuildHandler(boolean verbose) { + this.verbose = verbose; + } + + @Override public void run() { try { sketch.prepare(); - sketch.build(true); + sketch.build(verbose); statusNotice(_("Done compiling.")); } catch (PreferencesMapException e) { statusError(I18n.format( @@ -1961,11 +1951,8 @@ public class Editor extends JFrame implements RunnerListener { class DefaultStopHandler implements Runnable { public void run() { - try { - // DAM: we should try to kill the compilation or upload process here. - } catch (Exception e) { - statusError(e); - } + // TODO + // DAM: we should try to kill the compilation or upload process here. } }