From 498d615fb8f7993aba39266e3ba63a0779fca1bb Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Fri, 6 Mar 2015 16:17:56 -0600 Subject: [PATCH 1/3] Additional context for build hooks --- arduino-core/src/processing/app/debug/Compiler.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index e84ba4eda3..8364673d1b 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -183,6 +183,9 @@ public Compiler(SketchData _sketch, String _buildPath, String _primaryClassName) sketch = _sketch; prefs = createBuildPreferences(_buildPath, _primaryClassName); + // provide access to the source tree + prefs.put("build.source.path", _sketch.getFolder().getAbsolutePath()); + // Start with an empty progress listener progressListener = new ProgressListener() { @Override From 2f65f5fdc1a42cc8dc69487ee5db8879faf4ca9f Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Fri, 6 Mar 2015 16:16:04 -0600 Subject: [PATCH 2/3] Provide Hooks before and after the build process Closes #2732 --- arduino-core/src/processing/app/debug/Compiler.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index 8364673d1b..9d8790b279 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -349,6 +349,11 @@ public boolean compile(boolean _verbose) throws RunnerException, PreferencesMapE verbose = _verbose || PreferencesData.getBoolean("build.verbose"); sketchIsCompiled = false; + + // Hook runs at Start of Compilation + if (prefs.containsKey("recipe.hooks.prebuild")) + runRecipe("recipe.hooks.prebuild"); + objectFiles = new ArrayList(); // 0. include paths for core + all libraries @@ -416,6 +421,11 @@ public boolean compile(boolean _verbose) throws RunnerException, PreferencesMapE } progressListener.progress(90); + + // Hook runs at End of Compilation + if (prefs.containsKey("recipe.hooks.postbuild")) + runRecipe("recipe.hooks.postbuild"); + return true; } From 0644bdc51cbdca0afd7fd42c4e557a9e22873d74 Mon Sep 17 00:00:00 2001 From: Richard Wackerbarth Date: Sat, 7 Mar 2015 10:43:45 -0600 Subject: [PATCH 3/3] Convert to action pattern to allow multiple actions --- .../src/processing/app/debug/Compiler.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/arduino-core/src/processing/app/debug/Compiler.java b/arduino-core/src/processing/app/debug/Compiler.java index 9d8790b279..dd5d7128f6 100644 --- a/arduino-core/src/processing/app/debug/Compiler.java +++ b/arduino-core/src/processing/app/debug/Compiler.java @@ -351,8 +351,7 @@ public boolean compile(boolean _verbose) throws RunnerException, PreferencesMapE sketchIsCompiled = false; // Hook runs at Start of Compilation - if (prefs.containsKey("recipe.hooks.prebuild")) - runRecipe("recipe.hooks.prebuild"); + runActions("hooks.prebuild", prefs); objectFiles = new ArrayList(); @@ -422,9 +421,8 @@ public boolean compile(boolean _verbose) throws RunnerException, PreferencesMapE progressListener.progress(90); - // Hook runs at End of Compilation - if (prefs.containsKey("recipe.hooks.postbuild")) - runRecipe("recipe.hooks.postbuild"); + // Hook runs at End of Compilation + runActions("hooks.postbuild", prefs); return true; } @@ -1047,6 +1045,18 @@ void compileLink() execAsynchronously(cmdArray); } + void runActions(String recipeClass, PreferencesMap prefs) throws RunnerException, PreferencesMapException { + List patterns = new ArrayList(); + for (String key : prefs.keySet()) { + if (key.startsWith("recipe."+recipeClass) && key.endsWith(".pattern")) + patterns.add(key); + } + Collections.sort(patterns); + for (String recipe : patterns) { + runRecipe(recipe); + } + } + void runRecipe(String recipe) throws RunnerException, PreferencesMapException { PreferencesMap dict = new PreferencesMap(prefs); dict.put("ide_version", "" + BaseNoGui.REVISION);