26
26
import cc .arduino .packages .BoardPort ;
27
27
import cc .arduino .packages .UploaderAndMonitorFactory ;
28
28
import cc .arduino .packages .Uploader ;
29
- import processing .app .debug .*;
30
29
import processing .app .debug .Compiler ;
31
30
import processing .app .debug .Compiler .ProgressListener ;
31
+ import processing .app .debug .RunnerException ;
32
+ import processing .app .debug .TargetPlatform ;
32
33
import processing .app .forms .PasswordAuthorizationDialog ;
33
34
import processing .app .helpers .OSUtils ;
34
- import processing .app .helpers .PreferencesMap ;
35
- import processing .app .helpers .FileUtils ;
36
35
import processing .app .packages .Library ;
37
36
import static processing .app .I18n ._ ;
38
37
@@ -61,12 +60,6 @@ public class Sketch {
61
60
/** Class name for the PApplet, as determined by the preprocessor. */
62
61
private String appletClassName ;
63
62
64
- /**
65
- * File inside the build directory that contains the build options
66
- * used for the last build.
67
- */
68
- static final String BUILD_PREFS_FILE = "buildprefs.txt" ;
69
-
70
63
/**
71
64
* path is location of the main .pde file, because this is also
72
65
* simplest to use when opening the file from the finder/explorer.
@@ -1017,48 +1010,6 @@ protected void setCurrentCode(String findName) {
1017
1010
}
1018
1011
1019
1012
1020
- /**
1021
- * Cleanup temporary files used during a build/run.
1022
- */
1023
- protected void cleanup (boolean force ) {
1024
- // if the java runtime is holding onto any files in the build dir, we
1025
- // won't be able to delete them, so we need to force a gc here
1026
- System .gc ();
1027
-
1028
- if (force ) {
1029
- // delete the entire directory and all contents
1030
- // when we know something changed and all objects
1031
- // need to be recompiled, or if the board does not
1032
- // use setting build.dependency
1033
- //Base.removeDir(tempBuildFolder);
1034
-
1035
- // note that we can't remove the builddir itself, otherwise
1036
- // the next time we start up, internal runs using Runner won't
1037
- // work because the build dir won't exist at startup, so the classloader
1038
- // will ignore the fact that that dir is in the CLASSPATH in run.sh
1039
- Base .removeDescendants (tempBuildFolder );
1040
- } else {
1041
- // delete only stale source files, from the previously
1042
- // compiled sketch. This allows multiple windows to be
1043
- // used. Keep everything else, which might be reusable
1044
- if (tempBuildFolder .exists ()) {
1045
- String files [] = tempBuildFolder .list ();
1046
- for (String file : files ) {
1047
- if (file .endsWith (".c" ) || file .endsWith (".cpp" ) || file .endsWith (".s" )) {
1048
- File deleteMe = new File (tempBuildFolder , file );
1049
- if (!deleteMe .delete ()) {
1050
- System .err .println ("Could not delete " + deleteMe );
1051
- }
1052
- }
1053
- }
1054
- }
1055
- }
1056
-
1057
- // Create a fresh applet folder (needed before preproc is run below)
1058
- //tempBuildFolder.mkdirs();
1059
- }
1060
-
1061
-
1062
1013
/**
1063
1014
* Preprocess, Compile, and Run the current code.
1064
1015
* <P>
@@ -1180,47 +1131,6 @@ public String build(boolean verbose) throws RunnerException {
1180
1131
return build (tempBuildFolder .getAbsolutePath (), verbose );
1181
1132
}
1182
1133
1183
- /**
1184
- * Check if the build preferences used on the previous build in
1185
- * buildPath match the ones given.
1186
- */
1187
- protected boolean buildPreferencesChanged (File buildPrefsFile , String newBuildPrefs ) {
1188
- // No previous build, so no match
1189
- if (!buildPrefsFile .exists ())
1190
- return true ;
1191
-
1192
- String previousPrefs ;
1193
- try {
1194
- previousPrefs = FileUtils .readFileToString (buildPrefsFile );
1195
- } catch (IOException e ) {
1196
- System .err .println (_ ("Could not read prevous build preferences file, rebuilding all" ));
1197
- return true ;
1198
- }
1199
-
1200
- if (!previousPrefs .equals (newBuildPrefs )) {
1201
- System .out .println (_ ("Build options changed, rebuilding all" ));
1202
- return true ;
1203
- } else {
1204
- return false ;
1205
- }
1206
- }
1207
-
1208
- /**
1209
- * Returns the build preferences of the given compiler as a string.
1210
- * Only includes build-specific preferences, to make sure unrelated
1211
- * preferences don't cause a rebuild (in particular preferences that
1212
- * change on every start, like last.ide.xxx.daterun). */
1213
- protected String buildPrefsString (Compiler compiler ) {
1214
- PreferencesMap buildPrefs = compiler .getBuildPreferences ();
1215
- String res = "" ;
1216
- SortedSet <String > treeSet = new TreeSet <String >(buildPrefs .keySet ());
1217
- for (String k : treeSet ) {
1218
- if (k .startsWith ("build." ) || k .startsWith ("compiler." ) || k .startsWith ("recipes." ))
1219
- res += k + " = " + buildPrefs .get (k ) + "\n " ;
1220
- }
1221
- return res ;
1222
- }
1223
-
1224
1134
/**
1225
1135
* Preprocess and compile all the code for this sketch.
1226
1136
*
@@ -1231,45 +1141,19 @@ protected String buildPrefsString(Compiler compiler) {
1231
1141
* @return null if compilation failed, main class name if not
1232
1142
*/
1233
1143
public String build (String buildPath , boolean verbose ) throws RunnerException {
1234
- String primaryClassName = data .getName () + ".cpp" ;
1235
- Compiler compiler = new Compiler (data , buildPath , primaryClassName );
1236
- File buildPrefsFile = new File (buildPath , BUILD_PREFS_FILE );
1237
- String newBuildPrefs = buildPrefsString (compiler );
1238
-
1239
- // Do a forced cleanup (throw everything away) if the previous
1240
- // build settings do not match the previous ones
1241
- boolean prefsChanged = buildPreferencesChanged (buildPrefsFile , newBuildPrefs );
1242
- cleanup (prefsChanged );
1243
-
1244
- if (prefsChanged ) {
1245
- try {
1246
- PrintWriter out = new PrintWriter (buildPrefsFile );
1247
- out .print (newBuildPrefs );
1248
- out .close ();
1249
- } catch (IOException e ) {
1250
- System .err .println (_ ("Could not write build preferences file" ));
1251
- }
1252
- }
1253
-
1254
1144
// run the preprocessor
1255
1145
editor .status .progressUpdate (20 );
1256
1146
1257
1147
ensureExistence ();
1258
1148
1259
- compiler . setProgressListener ( new ProgressListener () {
1149
+ ProgressListener pl = new ProgressListener () {
1260
1150
@ Override
1261
1151
public void progress (int percent ) {
1262
1152
editor .status .progressUpdate (percent );
1263
1153
}
1264
- }) ;
1154
+ };
1265
1155
1266
- // compile the program. errors will happen as a RunnerException
1267
- // that will bubble up to whomever called build().
1268
- if (compiler .compile (verbose )) {
1269
- size (compiler .getBuildPreferences ());
1270
- return primaryClassName ;
1271
- }
1272
- return null ;
1156
+ return Compiler .build (data , buildPath , tempBuildFolder , pl , verbose );
1273
1157
}
1274
1158
1275
1159
protected boolean exportApplet (boolean usingProgrammer ) throws Exception {
@@ -1307,58 +1191,6 @@ public boolean exportApplet(String appletPath, boolean usingProgrammer)
1307
1191
}
1308
1192
1309
1193
1310
- protected void size (PreferencesMap prefs ) throws RunnerException {
1311
- String maxTextSizeString = prefs .get ("upload.maximum_size" );
1312
- String maxDataSizeString = prefs .get ("upload.maximum_data_size" );
1313
- if (maxTextSizeString == null )
1314
- return ;
1315
- long maxTextSize = Integer .parseInt (maxTextSizeString );
1316
- long maxDataSize = -1 ;
1317
- if (maxDataSizeString != null )
1318
- maxDataSize = Integer .parseInt (maxDataSizeString );
1319
- Sizer sizer = new Sizer (prefs );
1320
- long [] sizes ;
1321
- try {
1322
- sizes = sizer .computeSize ();
1323
- } catch (RunnerException e ) {
1324
- System .err .println (I18n .format (_ ("Couldn't determine program size: {0}" ),
1325
- e .getMessage ()));
1326
- return ;
1327
- }
1328
-
1329
- long textSize = sizes [0 ];
1330
- long dataSize = sizes [1 ];
1331
- System .out .println ();
1332
- System .out .println (I18n
1333
- .format (_ ("Sketch uses {0} bytes ({2}%%) of program storage space. Maximum is {1} bytes." ),
1334
- textSize , maxTextSize , textSize * 100 / maxTextSize ));
1335
- if (dataSize >= 0 ) {
1336
- if (maxDataSize > 0 ) {
1337
- System .out
1338
- .println (I18n
1339
- .format (
1340
- _ ("Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes." ),
1341
- dataSize , maxDataSize , dataSize * 100 / maxDataSize ,
1342
- maxDataSize - dataSize ));
1343
- } else {
1344
- System .out .println (I18n
1345
- .format (_ ("Global variables use {0} bytes of dynamic memory." ), dataSize ));
1346
- }
1347
- }
1348
-
1349
- if (textSize > maxTextSize )
1350
- throw new RunnerException (
1351
- _ ("Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it." ));
1352
-
1353
- if (maxDataSize > 0 && dataSize > maxDataSize )
1354
- throw new RunnerException (
1355
- _ ("Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint." ));
1356
-
1357
- int warnDataPercentage = Integer .parseInt (prefs .get ("build.warn_data_percentage" ));
1358
- if (maxDataSize > 0 && dataSize > maxDataSize *warnDataPercentage /100 )
1359
- System .err .println (_ ("Low memory available, stability problems may occur." ));
1360
- }
1361
-
1362
1194
protected boolean upload (String buildPath , String suggestedClassName , boolean usingProgrammer ) throws Exception {
1363
1195
1364
1196
TargetPlatform target = Base .getTargetPlatform ();
0 commit comments