|
1 | 1 | /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
2 | 2 |
|
3 | 3 | /* |
4 | | - Sizer - computes the size of a .hex file |
5 | | - Part of the Arduino project - http://www.arduino.cc/ |
| 4 | + Sizer - computes the size of a .hex file |
| 5 | + Part of the Arduino project - http://www.arduino.cc/ |
6 | 6 |
|
7 | | - Copyright (c) 2006 David A. Mellis |
| 7 | + Copyright (c) 2006 David A. Mellis |
8 | 8 |
|
9 | | - This program is free software; you can redistribute it and/or modify |
10 | | - it under the terms of the GNU General Public License as published by |
11 | | - the Free Software Foundation; either version 2 of the License, or |
12 | | - (at your option) any later version. |
| 9 | + This program is free software; you can redistribute it and/or modify |
| 10 | + it under the terms of the GNU General Public License as published by |
| 11 | + the Free Software Foundation; either version 2 of the License, or |
| 12 | + (at your option) any later version. |
13 | 13 |
|
14 | | - This program is distributed in the hope that it will be useful, |
15 | | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | - GNU General Public License for more details. |
| 14 | + This program is distributed in the hope that it will be useful, |
| 15 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | + GNU General Public License for more details. |
18 | 18 |
|
19 | | - You should have received a copy of the GNU General Public License |
20 | | - along with this program; if not, write to the Free Software Foundation, |
21 | | - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 | | -
|
23 | | - $Id$ |
24 | | - */ |
| 19 | + You should have received a copy of the GNU General Public License |
| 20 | + along with this program; if not, write to the Free Software Foundation, |
| 21 | + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | + |
| 23 | + $Id$ |
| 24 | +*/ |
25 | 25 |
|
26 | 26 | package processing.app.debug; |
27 | 27 |
|
28 | | -import java.io.File; |
29 | | -import java.text.MessageFormat; |
30 | | -import java.util.Map; |
31 | | -import java.util.NoSuchElementException; |
32 | | -import java.util.StringTokenizer; |
| 28 | +import processing.app.Base; |
| 29 | + |
| 30 | +import java.io.*; |
| 31 | +import java.util.*; |
33 | 32 |
|
34 | 33 | public class Sizer implements MessageConsumer { |
35 | 34 | private String buildPath, sketchName; |
36 | | - |
37 | 35 | private String firstLine; |
38 | | - |
39 | 36 | private long size; |
40 | | - |
41 | 37 | private RunnerException exception; |
42 | 38 |
|
43 | | - private Map<String, String> prefs; |
44 | | - |
45 | | - public Sizer(String buildPath, String sketchName, |
46 | | - Map<String, String> prefs) { |
| 39 | + public Sizer(String buildPath, String sketchName) { |
47 | 40 | this.buildPath = buildPath; |
48 | 41 | this.sketchName = sketchName; |
49 | | - this.prefs = prefs; |
50 | 42 | } |
51 | | - |
| 43 | + |
52 | 44 | public long computeSize() throws RunnerException { |
53 | | - String args[] = new String[3]; |
54 | | - args[0] = prefs.get("compiler.path"); |
55 | | - args[1] = prefs.get("compiler.size.cmd"); |
56 | | - args[2] = buildPath + File.separator + sketchName; |
57 | | - |
58 | | - String recipe = prefs.get("recipe.size.pattern"); |
59 | | - MessageFormat compileFormat = new MessageFormat(recipe); |
60 | | - String command = compileFormat.format(args); |
61 | | - String[] commandArray = command.split("\\|"); |
| 45 | + String avrBasePath = Base.getAvrBasePath(); |
| 46 | + String commandSize[] = new String[] { |
| 47 | + avrBasePath + "avr-size", |
| 48 | + " " |
| 49 | + }; |
| 50 | + |
| 51 | + commandSize[1] = buildPath + File.separator + sketchName + ".hex"; |
62 | 52 |
|
63 | 53 | int r = 0; |
64 | 54 | try { |
65 | 55 | exception = null; |
66 | 56 | size = -1; |
67 | 57 | firstLine = null; |
68 | | - Process process = Runtime.getRuntime().exec(commandArray); |
| 58 | + Process process = Runtime.getRuntime().exec(commandSize); |
69 | 59 | MessageSiphon in = new MessageSiphon(process.getInputStream(), this); |
70 | 60 | MessageSiphon err = new MessageSiphon(process.getErrorStream(), this); |
71 | 61 |
|
72 | 62 | boolean running = true; |
73 | 63 |
|
74 | | - while (running) { |
| 64 | + while(running) { |
75 | 65 | try { |
76 | 66 | if (in.thread != null) |
77 | 67 | in.thread.join(); |
78 | 68 | if (err.thread != null) |
79 | 69 | err.thread.join(); |
80 | 70 | r = process.waitFor(); |
81 | 71 | running = false; |
82 | | - } catch (InterruptedException intExc) { |
83 | | - } |
| 72 | + } catch (InterruptedException intExc) { } |
84 | 73 | } |
85 | 74 | } catch (Exception e) { |
86 | 75 | // The default Throwable.toString() never returns null, but apparently |
87 | 76 | // some sub-class has overridden it to do so, thus we need to check for |
88 | | - // it. See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1166589459 |
89 | | - if (e.toString() == null) |
90 | | - exception = new RunnerException(e.getClass().getName() + r); |
91 | | - else |
92 | | - exception = new RunnerException(e.toString() + r); |
| 77 | + // it. See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1166589459 |
| 78 | + exception = new RunnerException( |
| 79 | + (e.toString() == null) ? e.getClass().getName() + r : e.toString() + r); |
93 | 80 | } |
94 | | - |
| 81 | + |
95 | 82 | if (exception != null) |
96 | 83 | throw exception; |
97 | | - |
| 84 | + |
98 | 85 | if (size == -1) |
99 | 86 | throw new RunnerException(firstLine); |
100 | | - |
| 87 | + |
101 | 88 | return size; |
102 | 89 | } |
103 | | - |
| 90 | + |
104 | 91 | public void message(String s) { |
105 | 92 | if (firstLine == null) |
106 | 93 | firstLine = s; |
|
0 commit comments