From 5b6adec95fe419981735eb08777528130fc11d43 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 20 Mar 2017 12:46:42 +0100 Subject: [PATCH] add preference checkbox for core cache --- .../arduino/view/preferences/Preferences.java | 9 +++++++++ arduino-core/src/cc/arduino/Compiler.java | 9 ++++++++- .../src/processing/app/BaseNoGui.java | 19 ++++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/app/src/cc/arduino/view/preferences/Preferences.java b/app/src/cc/arduino/view/preferences/Preferences.java index f833024e9..ba1837f26 100644 --- a/app/src/cc/arduino/view/preferences/Preferences.java +++ b/app/src/cc/arduino/view/preferences/Preferences.java @@ -128,6 +128,7 @@ public class Preferences extends javax.swing.JDialog { enableCodeFoldingBox = new javax.swing.JCheckBox(); verifyUploadBox = new javax.swing.JCheckBox(); externalEditorBox = new javax.swing.JCheckBox(); + cacheCompiledCore = new javax.swing.JCheckBox(); checkUpdatesBox = new javax.swing.JCheckBox(); updateExtensionBox = new javax.swing.JCheckBox(); saveVerifyUploadBox = new javax.swing.JCheckBox(); @@ -244,6 +245,9 @@ public class Preferences extends javax.swing.JDialog { externalEditorBox.setText(tr("Use external editor")); checkboxesContainer.add(externalEditorBox); + cacheCompiledCore.setText(tr("Aggressively cache compiled core")); + checkboxesContainer.add(cacheCompiledCore); + checkUpdatesBox.setText(tr("Check for updates on startup")); checkboxesContainer.add(checkUpdatesBox); @@ -678,6 +682,7 @@ public class Preferences extends javax.swing.JDialog { private javax.swing.JCheckBox enableCodeFoldingBox; private javax.swing.JButton extendedAdditionalUrlFieldWindow; private javax.swing.JCheckBox externalEditorBox; + private javax.swing.JCheckBox cacheCompiledCore; private javax.swing.JTextField fontSizeField; private javax.swing.JLabel fontSizeLabel; private javax.swing.JLabel jLabel1; @@ -772,6 +777,8 @@ public class Preferences extends javax.swing.JDialog { PreferencesData.setBoolean("editor.external", externalEditorBox.isSelected()); + PreferencesData.setBoolean("compiler.cache_core", cacheCompiledCore.isSelected()); + PreferencesData.setBoolean("update.check", checkUpdatesBox.isSelected()); PreferencesData.setBoolean("editor.update_extension", updateExtensionBox.isSelected()); @@ -832,6 +839,8 @@ public class Preferences extends javax.swing.JDialog { externalEditorBox.setSelected(PreferencesData.getBoolean("editor.external")); + cacheCompiledCore.setSelected(PreferencesData.get("compiler.cache_core") == null || PreferencesData.getBoolean("compiler.cache_core")); + checkUpdatesBox.setSelected(PreferencesData.getBoolean("update.check")); updateExtensionBox.setSelected(PreferencesData.get("editor.update_extension") == null || PreferencesData.getBoolean("editor.update_extension")); diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java index e04f1a729..0cf36b2ff 100644 --- a/arduino-core/src/cc/arduino/Compiler.java +++ b/arduino-core/src/cc/arduino/Compiler.java @@ -138,6 +138,7 @@ public class Compiler implements MessageConsumer { private final File pathToSketch; private final Sketch sketch; private String buildPath; + private File buildCache; private final boolean verbose; private RunnerException exception; @@ -156,9 +157,10 @@ public class Compiler implements MessageConsumer { listeners.add(progListener); return this.build(listeners, exportHex); } - + public String build(ArrayList progListeners, boolean exportHex) throws RunnerException, PreferencesMapException, IOException { this.buildPath = sketch.getBuildPath().getAbsolutePath(); + this.buildCache = BaseNoGui.getCachePath(); TargetBoard board = BaseNoGui.getTargetBoard(); if (board == null) { @@ -258,6 +260,11 @@ public class Compiler implements MessageConsumer { cmd.add(buildPath); cmd.add("-warnings=" + PreferencesData.get("compiler.warning_level")); + if (PreferencesData.getBoolean("compiler.cache_core") == true && buildCache != null) { + cmd.add("-build-cache"); + cmd.add(buildCache.getAbsolutePath()); + } + PreferencesData.getMap() .subTree("runtime.build_properties_custom") .entrySet() diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index fd372596c..b634bc25e 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -21,6 +21,9 @@ import processing.app.legacy.PApplet; import processing.app.packages.LibraryList; import processing.app.packages.UserLibrary; +import cc.arduino.files.DeleteFilesOnShutdown; +import processing.app.helpers.FileUtils; + import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.File; @@ -100,6 +103,8 @@ public class BaseNoGui { private static String boardManagerLink = ""; + private static File buildCache; + // Returns a File object for the given pathname. If the pathname // is not absolute, it is interpreted relative to the current // directory when starting the IDE (which is not the same as the @@ -131,7 +136,7 @@ public class BaseNoGui { if (board == null) return null; String boardId = board.getId(); - + PreferencesMap prefs = new PreferencesMap(board.getPreferences()); String extendedName = prefs.get("name"); @@ -256,6 +261,18 @@ public class BaseNoGui { return portableSketchbookFolder; } + static public File getCachePath() { + if (buildCache == null) { + try { + buildCache = FileUtils.createTempFolder("arduino_cache_"); + DeleteFilesOnShutdown.add(buildCache); + } catch (IOException e) { + return null; + } + } + return buildCache; + } + /** * Convenience method to get a File object for the specified filename inside * the settings folder.