mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-30 16:24:09 +03:00
Merge branch 'penguin359-ide-1.5.x-ram' into ide-1.5.x
Fixes #1377 Fixes #1356
This commit is contained in:
@ -1613,25 +1613,50 @@ public class Sketch {
|
||||
|
||||
|
||||
protected void size(PreferencesMap prefs) throws RunnerException {
|
||||
long size = 0;
|
||||
String maxsizeString = prefs.get("upload.maximum_size");
|
||||
if (maxsizeString == null)
|
||||
String maxTextSizeString = prefs.get("upload.maximum_size");
|
||||
String maxDataSizeString = prefs.get("upload.maximum_data_size");
|
||||
if (maxTextSizeString == null)
|
||||
return;
|
||||
long maxsize = Integer.parseInt(maxsizeString);
|
||||
long maxTextSize = Integer.parseInt(maxTextSizeString);
|
||||
long maxDataSize = -1;
|
||||
if (maxDataSizeString != null)
|
||||
maxDataSize = Integer.parseInt(maxDataSizeString);
|
||||
Sizer sizer = new Sizer(prefs);
|
||||
long[] sizes;
|
||||
try {
|
||||
size = sizer.computeSize();
|
||||
System.out.println(I18n
|
||||
.format(_("Binary sketch size: {0} bytes (of a {1} byte maximum) - {2}% used"),
|
||||
size, maxsize, size * 100 / maxsize));
|
||||
sizes = sizer.computeSize();
|
||||
} catch (RunnerException e) {
|
||||
System.err.println(I18n.format(_("Couldn't determine program size: {0}"),
|
||||
e.getMessage()));
|
||||
return;
|
||||
}
|
||||
|
||||
long textSize = sizes[0];
|
||||
long dataSize = sizes[1];
|
||||
System.out.println(I18n
|
||||
.format(_("Binary sketch size: {0} bytes (of a {1} byte maximum) - {2}% used"),
|
||||
textSize, maxTextSize, textSize * 100 / maxTextSize));
|
||||
if (dataSize >= 0) {
|
||||
if (maxDataSize > 0) {
|
||||
System.out.println(I18n.format(
|
||||
_("Minimum Memory usage: {0} bytes (of a {1} byte maximum) - {2}% used"),
|
||||
dataSize, maxDataSize, dataSize * 100 / maxDataSize));
|
||||
} else {
|
||||
System.out.println(I18n.format(_("Minimum Memory usage: {0} bytes"), dataSize));
|
||||
}
|
||||
}
|
||||
|
||||
if (size > maxsize)
|
||||
if (textSize > maxTextSize)
|
||||
throw new RunnerException(
|
||||
_("Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."));
|
||||
|
||||
if (maxDataSize > 0 && dataSize > maxDataSize)
|
||||
throw new RunnerException(
|
||||
_("Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint."));
|
||||
|
||||
int warnDataPercentage = Integer.parseInt(prefs.get("build.warn_data_percentage"));
|
||||
if (maxDataSize > 0 && dataSize > maxDataSize*warnDataPercentage/100)
|
||||
System.out.println(_("Low memory available, stability problems may occur"));
|
||||
}
|
||||
|
||||
protected String upload(String buildPath, String suggestedClassName, boolean usingProgrammer)
|
||||
|
@ -33,18 +33,30 @@ import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.StringReplacer;
|
||||
|
||||
public class Sizer implements MessageConsumer {
|
||||
private long size;
|
||||
private long textSize;
|
||||
private long dataSize;
|
||||
private long eepromSize;
|
||||
private RunnerException exception;
|
||||
private PreferencesMap prefs;
|
||||
private String firstLine;
|
||||
private Pattern pattern;
|
||||
private Pattern textPattern;
|
||||
private Pattern dataPattern;
|
||||
private Pattern eepromPattern;
|
||||
|
||||
public Sizer(PreferencesMap _prefs) {
|
||||
prefs = _prefs;
|
||||
pattern = Pattern.compile(prefs.get("recipe.size.regex"));
|
||||
textPattern = Pattern.compile(prefs.get("recipe.size.regex"));
|
||||
dataPattern = null;
|
||||
String pref = prefs.get("recipe.size.regex.data");
|
||||
if (pref != null)
|
||||
dataPattern = Pattern.compile(pref);
|
||||
eepromPattern = null;
|
||||
pref = prefs.get("recipe.size.regex.eeprom");
|
||||
if (pref != null)
|
||||
eepromPattern = Pattern.compile(pref);
|
||||
}
|
||||
|
||||
public long computeSize() throws RunnerException {
|
||||
public long[] computeSize() throws RunnerException {
|
||||
|
||||
int r = 0;
|
||||
try {
|
||||
@ -52,7 +64,9 @@ public class Sizer implements MessageConsumer {
|
||||
String cmd[] = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||
|
||||
exception = null;
|
||||
size = -1;
|
||||
textSize = -1;
|
||||
dataSize = -1;
|
||||
eepromSize = -1;
|
||||
Process process = Runtime.getRuntime().exec(cmd);
|
||||
MessageSiphon in = new MessageSiphon(process.getInputStream(), this);
|
||||
MessageSiphon err = new MessageSiphon(process.getErrorStream(), this);
|
||||
@ -77,17 +91,36 @@ public class Sizer implements MessageConsumer {
|
||||
if (exception != null)
|
||||
throw exception;
|
||||
|
||||
if (size == -1)
|
||||
if (textSize == -1)
|
||||
throw new RunnerException(firstLine);
|
||||
|
||||
return size;
|
||||
return new long[] { textSize, dataSize, eepromSize };
|
||||
}
|
||||
|
||||
public void message(String s) {
|
||||
if (firstLine == null)
|
||||
firstLine = s;
|
||||
Matcher matcher = pattern.matcher(s.trim());
|
||||
if (matcher.matches())
|
||||
size = Long.parseLong(matcher.group(1));
|
||||
Matcher textMatcher = textPattern.matcher(s.trim());
|
||||
if (textMatcher.matches()) {
|
||||
if (textSize < 0)
|
||||
textSize = 0;
|
||||
textSize += Long.parseLong(textMatcher.group(1));
|
||||
}
|
||||
if(dataPattern != null) {
|
||||
Matcher dataMatcher = dataPattern.matcher(s.trim());
|
||||
if (dataMatcher.matches()) {
|
||||
if (dataSize < 0)
|
||||
dataSize = 0;
|
||||
dataSize += Long.parseLong(dataMatcher.group(1));
|
||||
}
|
||||
}
|
||||
if(eepromPattern != null) {
|
||||
Matcher eepromMatcher = eepromPattern.matcher(s.trim());
|
||||
if (eepromMatcher.matches()) {
|
||||
if (eepromSize < 0)
|
||||
eepromSize = 0;
|
||||
eepromSize += Long.parseLong(eepromMatcher.group(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user