diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 687f5666f..3f19cd3a3 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -28,6 +28,7 @@ import processing.app.debug.Compiler; import processing.app.debug.RunnerException; import processing.app.debug.Sizer; import processing.app.debug.Uploader; +import processing.app.helpers.PreferencesMap; import processing.app.preproc.*; import processing.core.*; import static processing.app.I18n._; @@ -1610,9 +1611,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 { // run the preprocessor editor.status.progressUpdate(20); String primaryClassName = preprocess(buildPath); @@ -1621,12 +1620,11 @@ public class Sketch { // that will bubble up to whomever called build(). Compiler compiler = new Compiler(); if (compiler.compile(this, buildPath, primaryClassName, verbose)) { - size(buildPath, primaryClassName); + size(compiler.getBuildPreferences()); return primaryClassName; } return null; - } - + } protected boolean exportApplet(boolean usingProgrammer) throws Exception { return exportApplet(tempBuildFolder.getAbsolutePath(), usingProgrammer); @@ -1668,31 +1666,28 @@ public class Sketch { } - protected void size(String buildPath, String suggestedClassName) - throws RunnerException { + protected void size(PreferencesMap prefs) throws RunnerException { long size = 0; - String maxsizeString = Base.getBoardPreferences().get("upload.maximum_size"); - if (maxsizeString == null) return; + String maxsizeString = prefs.get("upload.maximum_size"); + if (maxsizeString == null) + return; long maxsize = Integer.parseInt(maxsizeString); - Sizer sizer = new Sizer(buildPath, suggestedClassName); - try { + Sizer sizer = new Sizer(prefs); + try { size = sizer.computeSize(); - System.out.println( - I18n.format( - _("Binary sketch size: {0} bytes (of a {1} byte maximum)"), - size, maxsize - ) - ); + System.out.println(I18n + .format(_("Binary sketch size: {0} bytes (of a {1} byte maximum)"), + size, maxsize)); } catch (RunnerException e) { - System.err.println(I18n.format(_("Couldn't determine program size: {0}"), e.getMessage())); + System.err.println(I18n.format(_("Couldn't determine program size: {0}"), + e.getMessage())); } if (size > maxsize) throw new RunnerException( - _("Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.")); + _("Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.")); } - protected String upload(String buildPath, String suggestedClassName, boolean usingProgrammer) throws RunnerException, SerialException { diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index fa71913ea..1d6dfad87 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -689,4 +689,8 @@ public class Compiler implements MessageConsumer { // Remove first space return res.substring(1); } + + public PreferencesMap getBuildPreferences() { + return prefs; + } } diff --git a/app/src/processing/app/debug/Sizer.java b/app/src/processing/app/debug/Sizer.java index d67728a3c..2de116cb2 100644 --- a/app/src/processing/app/debug/Sizer.java +++ b/app/src/processing/app/debug/Sizer.java @@ -5,6 +5,7 @@ Part of the Arduino project - http://www.arduino.cc/ Copyright (c) 2006 David A. Mellis + Copyright (c) 2011 Cristian Maglie This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,42 +26,38 @@ package processing.app.debug; -import processing.app.Base; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -import java.io.*; -import java.util.*; +import processing.app.helpers.PreferencesMap; +import processing.app.helpers.StringReplacer; public class Sizer implements MessageConsumer { - private String buildPath, sketchName; - private String firstLine; private long size; private RunnerException exception; - - public Sizer(String buildPath, String sketchName) { - this.buildPath = buildPath; - this.sketchName = sketchName; + private PreferencesMap prefs; + private String firstLine; + private Pattern pattern; + + public Sizer(PreferencesMap _prefs) { + prefs = _prefs; + pattern = Pattern.compile(prefs.get("recipe.size.regex")); } public long computeSize() throws RunnerException { - String avrBasePath = Base.getAvrBasePath(); - String commandSize[] = new String[] { - avrBasePath + "avr-size", - " " - }; - - commandSize[1] = buildPath + File.separator + sketchName + ".hex"; int r = 0; try { + String pattern = prefs.get("recipe.size.pattern"); + String cmd[] = StringReplacer.formatAndSplit(pattern, prefs, true); + exception = null; size = -1; - firstLine = null; - Process process = Runtime.getRuntime().exec(commandSize); + Process process = Runtime.getRuntime().exec(cmd); MessageSiphon in = new MessageSiphon(process.getInputStream(), this); MessageSiphon err = new MessageSiphon(process.getErrorStream(), this); boolean running = true; - while(running) { try { if (in.thread != null) @@ -91,18 +88,8 @@ public class Sizer implements MessageConsumer { public void message(String s) { if (firstLine == null) firstLine = s; - else { - StringTokenizer st = new StringTokenizer(s, " "); - try { - st.nextToken(); - st.nextToken(); - st.nextToken(); - size = (new Integer(st.nextToken().trim())).longValue(); - } catch (NoSuchElementException e) { - exception = new RunnerException(e.toString()); - } catch (NumberFormatException e) { - exception = new RunnerException(e.toString()); - } - } + Matcher matcher = pattern.matcher(s.trim()); + if (matcher.matches()) + size = Long.parseLong(matcher.group(1)); } } \ No newline at end of file diff --git a/hardware/arduino/avr/platform.txt b/hardware/arduino/avr/platform.txt index 9664c20f8..c47cd8ba2 100644 --- a/hardware/arduino/avr/platform.txt +++ b/hardware/arduino/avr/platform.txt @@ -19,8 +19,7 @@ compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc, compiler.elf2hex.flags=-O ihex -R .eeprom compiler.elf2hex.cmd=avr-objcopy compiler.ldflags= -compiler.upload.cmd= -compiler.upload.flags= +compiler.size.cmd=avr-size # AVR compile patterns # -------------------- @@ -43,6 +42,10 @@ recipe.objcopy.eep.pattern={compiler.path}{compiler.objcopy.cmd} {compiler.objco ## Create hex recipe.objcopy.hex.pattern={compiler.path}{compiler.elf2hex.cmd} {compiler.elf2hex.flags} {build.path}/{build.project_name}.elf {build.path}/{build.project_name}.hex +## Compute size +recipe.size.pattern={compiler.path}{compiler.size.cmd} -A {build.path}/{build.project_name}.hex +recipe.size.regex=Total\s+([0-9]+).* + # AVR Uploader/Programmers tools # -------------------