mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-01 23:29:28 +01:00
Integrating the Sizer.
This commit is contained in:
parent
e2952cdc77
commit
8b6fb36ace
@ -26,6 +26,7 @@ package processing.app;
|
|||||||
import processing.app.debug.AvrdudeUploader;
|
import processing.app.debug.AvrdudeUploader;
|
||||||
import processing.app.debug.Compiler;
|
import processing.app.debug.Compiler;
|
||||||
import processing.app.debug.RunnerException;
|
import processing.app.debug.RunnerException;
|
||||||
|
import processing.app.debug.Sizer;
|
||||||
import processing.app.debug.Target;
|
import processing.app.debug.Target;
|
||||||
import processing.app.debug.Uploader;
|
import processing.app.debug.Uploader;
|
||||||
import processing.app.preproc.*;
|
import processing.app.preproc.*;
|
||||||
@ -1140,6 +1141,8 @@ public class Sketch {
|
|||||||
* </PRE>
|
* </PRE>
|
||||||
*/
|
*/
|
||||||
protected String compile(Target target) throws RunnerException {
|
protected String compile(Target target) throws RunnerException {
|
||||||
|
String name;
|
||||||
|
|
||||||
// make sure the user didn't hide the sketch folder
|
// make sure the user didn't hide the sketch folder
|
||||||
ensureExistence();
|
ensureExistence();
|
||||||
|
|
||||||
@ -1170,7 +1173,10 @@ public class Sketch {
|
|||||||
cleanup();
|
cleanup();
|
||||||
|
|
||||||
// handle preprocessing the main file's code
|
// handle preprocessing the main file's code
|
||||||
return build(tempBuildFolder.getAbsolutePath(), target);
|
name = build(tempBuildFolder.getAbsolutePath(), target);
|
||||||
|
size(tempBuildFolder.getAbsolutePath(), name);
|
||||||
|
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1414,12 +1420,32 @@ public class Sketch {
|
|||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//size(appletFolder.getPath(), name);
|
size(appletFolder.getPath(), foundName);
|
||||||
upload(appletFolder.getPath(), foundName);
|
upload(appletFolder.getPath(), foundName);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void size(String buildPath, String suggestedClassName)
|
||||||
|
throws RunnerException {
|
||||||
|
long size = 0;
|
||||||
|
long maxsize = Preferences.getInteger("boards." + Preferences.get("board") + ".upload.maximum_size");
|
||||||
|
Sizer sizer = new Sizer(buildPath, suggestedClassName);
|
||||||
|
try {
|
||||||
|
size = sizer.computeSize();
|
||||||
|
System.out.println("Binary sketch size: " + size + " bytes (of a " +
|
||||||
|
maxsize + " byte maximum)");
|
||||||
|
} catch (RunnerException e) {
|
||||||
|
System.err.println("Couldn't determine program size: " + 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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected String upload(String buildPath, String suggestedClassName)
|
protected String upload(String buildPath, String suggestedClassName)
|
||||||
throws RunnerException {
|
throws RunnerException {
|
||||||
|
|
||||||
|
108
app/src/processing/app/debug/Sizer.java
Normal file
108
app/src/processing/app/debug/Sizer.java
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Sizer - computes the size of a .hex file
|
||||||
|
Part of the Arduino project - http://www.arduino.cc/
|
||||||
|
|
||||||
|
Copyright (c) 2006 David A. Mellis
|
||||||
|
|
||||||
|
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
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
package processing.app.debug;
|
||||||
|
|
||||||
|
import processing.app.Base;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
exception = null;
|
||||||
|
size = -1;
|
||||||
|
firstLine = null;
|
||||||
|
Process process = Runtime.getRuntime().exec(commandSize);
|
||||||
|
MessageSiphon in = new MessageSiphon(process.getInputStream(), this);
|
||||||
|
MessageSiphon err = new MessageSiphon(process.getErrorStream(), this);
|
||||||
|
|
||||||
|
boolean running = true;
|
||||||
|
|
||||||
|
while(running) {
|
||||||
|
try {
|
||||||
|
if (in.thread != null)
|
||||||
|
in.thread.join();
|
||||||
|
if (err.thread != null)
|
||||||
|
err.thread.join();
|
||||||
|
r = process.waitFor();
|
||||||
|
running = false;
|
||||||
|
} catch (InterruptedException intExc) { }
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// The default Throwable.toString() never returns null, but apparently
|
||||||
|
// some sub-class has overridden it to do so, thus we need to check for
|
||||||
|
// it. See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1166589459
|
||||||
|
exception = new RunnerException(
|
||||||
|
(e.toString() == null) ? e.getClass().getName() + r : e.toString() + r);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exception != null)
|
||||||
|
throw exception;
|
||||||
|
|
||||||
|
if (size == -1)
|
||||||
|
throw new RunnerException(firstLine);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user