forked from arduino/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompiler.java
630 lines (535 loc) · 24.5 KB
/
Compiler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
/*
* This file is part of Arduino.
*
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
*
* Arduino 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*/
package cc.arduino;
import cc.arduino.i18n.I18NAwareMessageConsumer;
import cc.arduino.packages.BoardPort;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.lang3.StringUtils;
import processing.app.*;
import processing.app.debug.*;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.PreferencesMapException;
import processing.app.helpers.ProcessUtils;
import processing.app.helpers.StringReplacer;
import processing.app.legacy.PApplet;
import processing.app.tools.DoubleQuotedArgumentsOnWindowsCommandLine;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static processing.app.I18n.tr;
public class Compiler implements MessageConsumer {
//used by transifex integration
static {
tr("'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information");
tr("Archiving built core (caching) in: {0}");
tr("Board {0} (platform {1}, package {2}) is unknown");
tr("Bootloader file specified but missing: {0}");
tr("Build options changed, rebuilding all");
tr("Unable to find {0} in {1}");
tr("Invalid quoting: no closing [{0}] char found.");
tr("(legacy)");
tr("Multiple libraries were found for \"{0}\"");
tr(" Not used: {0}");
tr(" Used: {0}");
tr("Library can't use both 'src' and 'utility' folders. Double check {0}");
tr("WARNING: library {0} claims to run on {1} architecture(s) and may be incompatible with your current board which runs on {2} architecture(s).");
tr("Looking for recipes like {0}*{1}");
tr("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}");
tr("Selected board depends on '{0}' core (not installed).");
tr("{0} must be a folder");
tr("{0}: Unknown package");
tr("{0} pattern is missing");
tr("Platform {0} (package {1}) is unknown");
tr("Progress {0}");
tr("Missing '{0}' from library in {1}");
tr("Running: {0}");
tr("Running recipe: {0}");
tr("Setting build path to {0}");
tr("Unhandled type {0} in context key {1}");
tr("Unknown sketch file extension: {0}");
tr("Using library {0} at version {1} in folder: {2} {3}");
tr("Using library {0} in folder: {1} {2}");
tr("Using previously compiled file: {0}");
tr("WARNING: Category '{0}' in library {1} is not valid. Setting to '{2}'");
tr("Warning: platform.txt from core '{0}' misses property '{1}', using default value '{2}'. Consider upgrading this core.");
tr("Warning: platform.txt from core '{0}' contains deprecated {1}, automatically converted to {2}. Consider upgrading this core.");
tr("WARNING: Spurious {0} folder in '{1}' library");
tr("Sketch uses {0} bytes ({2}%%) of program storage space. Maximum is {1} bytes.");
tr("Couldn't determine program size: {0}");
tr("Global variables use {0} bytes ({2}%%) of dynamic memory, leaving {3} bytes for local variables. Maximum is {1} bytes.");
tr("Global variables use {0} bytes of dynamic memory.");
tr("Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.");
tr("Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint.");
tr("Low memory available, stability problems may occur.");
tr("An error occurred while verifying the sketch");
tr("An error occurred while verifying/uploading the sketch");
tr("Can't find the sketch in the specified path");
tr("Done compiling");
tr("Done uploading");
tr("Error while uploading");
tr("Error while verifying");
tr("Error while verifying/uploading");
tr("Mode not supported");
tr("Multiple files not supported");
tr("No command line parameters found");
tr("No parameters");
tr("No sketch");
tr("No sketchbook");
tr("Only --verify, --upload or --get-pref are supported");
tr("Sketchbook path not defined");
tr("The --upload option supports only one file at a time");
tr("Verifying and uploading...");
}
enum BuilderAction {
COMPILE("-compile"), DUMP_PREFS("-dump-prefs");
final String value;
BuilderAction(String value) {
this.value = value;
}
}
private static final Pattern ERROR_FORMAT = Pattern.compile("(.+\\.\\w+):(\\d+)(:\\d+)*:\\s*(fatal)?\\s*error:\\s*(.*)\\s*", Pattern.MULTILINE | Pattern.DOTALL);
private final File pathToSketch;
private final Sketch sketch;
private String buildPath;
private File buildCache;
private final boolean verbose;
private RunnerException exception;
public Compiler(Sketch data) {
this(data.getPrimaryFile().getFile(), data);
}
public Compiler(File pathToSketch, Sketch sketch) {
this.pathToSketch = pathToSketch;
this.sketch = sketch;
this.verbose = PreferencesData.getBoolean("build.verbose");
}
public String build(CompilerProgressListener progListener, boolean exportHex) throws RunnerException, PreferencesMapException, IOException {
List<CompilerProgressListener> listeners = new ArrayList<>();
listeners.add(progListener);
return this.build(listeners, exportHex);
}
public String build(List<CompilerProgressListener> progListeners, boolean exportHex) throws RunnerException, PreferencesMapException, IOException {
this.buildPath = sketch.getBuildPath().getAbsolutePath();
this.buildCache = BaseNoGui.getCachePath();
TargetBoard board = BaseNoGui.getTargetBoard();
if (board == null) {
throw new RunnerException("Board is not selected");
}
TargetPlatform platform = board.getContainerPlatform();
TargetPackage aPackage = platform.getContainerPackage();
String vidpid = VIDPID();
PreferencesMap prefs = loadPreferences(board, platform, aPackage, vidpid);
MessageConsumerOutputStream out = new MessageConsumerOutputStream(new ProgressAwareMessageConsumer(new I18NAwareMessageConsumer(System.out, System.err), progListeners), "\n");
MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(System.err, Compiler.this), "\n");
callArduinoBuilder(board, platform, aPackage, vidpid, BuilderAction.COMPILE, out, err);
out.flush();
err.flush();
if (exportHex) {
runActions("hooks.savehex.presavehex", prefs);
saveHex(prefs);
runActions("hooks.savehex.postsavehex", prefs);
}
return sketch.getPrimaryFile().getFileName();
}
private String VIDPID() {
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
if (boardPort == null) {
return "";
}
String vid = boardPort.getPrefs().get("vid");
String pid = boardPort.getPrefs().get("pid");
if (StringUtils.isEmpty(vid) || StringUtils.isEmpty(pid)) {
return "";
}
return vid.toUpperCase() + "_" + pid.toUpperCase();
}
private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid) throws RunnerException, IOException {
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(new PrintStream(stderr), Compiler.this), "\n");
try {
callArduinoBuilder(board, platform, aPackage, vidpid, BuilderAction.DUMP_PREFS, stdout, err);
} catch (RunnerException e) {
System.err.println(new String(stderr.toByteArray()));
throw e;
}
PreferencesMap prefs = new PreferencesMap();
prefs.load(new ByteArrayInputStream(stdout.toByteArray()));
return prefs;
}
private void addPathFlagIfPathExists(List<String> cmd, String flag, File folder) {
if (folder.exists()) {
cmd.add(flag);
cmd.add(folder.getAbsolutePath());
}
}
private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid, BuilderAction action, OutputStream outStream, OutputStream errStream) throws RunnerException {
List<String> cmd = new ArrayList<>();
cmd.add(BaseNoGui.getContentFile("arduino-builder").getAbsolutePath());
cmd.add(action.value);
cmd.add("-logger=machine");
File installedPackagesFolder = new File(BaseNoGui.getSettingsFolder(), "packages");
addPathFlagIfPathExists(cmd, "-hardware", BaseNoGui.getHardwareFolder());
addPathFlagIfPathExists(cmd, "-hardware", installedPackagesFolder);
addPathFlagIfPathExists(cmd, "-hardware", BaseNoGui.getSketchbookHardwareFolder());
addPathFlagIfPathExists(cmd, "-tools", BaseNoGui.getContentFile("tools-builder"));
addPathFlagIfPathExists(cmd, "-tools", Paths.get(BaseNoGui.getHardwarePath(), "tools", "avr").toFile());
addPathFlagIfPathExists(cmd, "-tools", installedPackagesFolder);
addPathFlagIfPathExists(cmd, "-built-in-libraries", BaseNoGui.getContentFile("libraries"));
addPathFlagIfPathExists(cmd, "-libraries", BaseNoGui.getSketchbookLibrariesFolder().folder);
String fqbn = Stream.of(aPackage.getId(), platform.getId(), board.getId(), boardOptions(board)).filter(s -> !s.isEmpty()).collect(Collectors.joining(":"));
cmd.add("-fqbn=" + fqbn);
if (!"".equals(vidpid)) {
cmd.add("-vid-pid=" + vidpid);
}
cmd.add("-ide-version=" + BaseNoGui.REVISION);
cmd.add("-build-path");
cmd.add(buildPath);
cmd.add("-warnings=" + PreferencesData.get("compiler.warning_level"));
if (PreferencesData.getBoolean("compiler.cache_core") == true && buildCache != null) {
cmd.add("-build-cache");
cmd.add(buildCache.getAbsolutePath());
}
if (PreferencesData.getBoolean("builder.use_platform_sketch_txt")) {
cmd.add("-use-platform-sketch-txt");
}
PreferencesData.getMap()
.subTree("runtime.build_properties_custom")
.entrySet()
.stream()
.forEach(kv -> cmd.add("-prefs=" + kv.getKey() + "=" + kv.getValue()));
cmd.add("-prefs=build.warn_data_percentage=" + PreferencesData.get("build.warn_data_percentage"));
for (Map.Entry<String, String> entry : BaseNoGui.getBoardPreferences().entrySet()) {
if (entry.getKey().startsWith("runtime.tools")) {
cmd.add("-prefs=" + entry.getKey() + "=" + entry.getValue());
}
}
//commandLine.addArgument("-debug-level=10", false);
if (verbose) {
cmd.add("-verbose");
}
cmd.add(pathToSketch.getAbsolutePath());
if (verbose) {
System.out.println(StringUtils.join(cmd, ' '));
}
int result;
try {
Process proc = ProcessUtils.exec(cmd.toArray(new String[0]));
MessageSiphon in = new MessageSiphon(proc.getInputStream(), (msg) -> {
try {
outStream.write(msg.getBytes());
} catch (Exception e) {
exception = new RunnerException(e);
}
});
MessageSiphon err = new MessageSiphon(proc.getErrorStream(), (msg) -> {
try {
errStream.write(msg.getBytes());
} catch (Exception e) {
exception = new RunnerException(e);
}
});
in.join();
err.join();
result = proc.waitFor();
} catch (Exception e) {
throw new RunnerException(e);
}
if (exception != null)
throw exception;
if (result > 1) {
System.err.println(I18n.format(tr("{0} returned {1}"), cmd.get(0), result));
}
if (result != 0) {
RunnerException re = new RunnerException(I18n.format(tr("Error compiling for board {0}."), board.getName()));
re.hideStackTrace();
throw re;
}
}
private void saveHex(PreferencesMap prefs) throws RunnerException {
List<String> compiledSketches = new ArrayList<>(prefs.subTree("recipe.output.tmp_file", 1).values());
List<String> copyOfCompiledSketches = new ArrayList<>(prefs.subTree("recipe.output.save_file", 1).values());
if (isExportCompiledSketchSupported(compiledSketches, copyOfCompiledSketches, prefs)) {
System.err.println(tr("Warning: This core does not support exporting sketches. Please consider upgrading it or contacting its author"));
return;
}
PreferencesMap dict = new PreferencesMap(prefs);
dict.put("ide_version", "" + BaseNoGui.REVISION);
PreferencesMap withBootloaderDict = new PreferencesMap(dict);
dict.put("build.project_name", dict.get("build.project_name") + ".with_bootloader");
if (!compiledSketches.isEmpty()) {
for (int i = 0; i < compiledSketches.size(); i++) {
saveHex(compiledSketches.get(i), copyOfCompiledSketches.get(i), dict);
saveHex(compiledSketches.get(i), copyOfCompiledSketches.get(i), withBootloaderDict);
}
} else {
try {
saveHex(prefs.getOrExcept("recipe.output.tmp_file"), prefs.getOrExcept("recipe.output.save_file"), dict);
saveHex(prefs.getOrExcept("recipe.output.tmp_file"), prefs.getOrExcept("recipe.output.save_file"), withBootloaderDict);
} catch (PreferencesMapException e) {
throw new RunnerException(e);
}
}
}
private void saveHex(String compiledSketch, String copyOfCompiledSketch, PreferencesMap prefs) throws RunnerException {
try {
compiledSketch = StringReplacer.replaceFromMapping(compiledSketch, prefs);
copyOfCompiledSketch = StringReplacer.replaceFromMapping(copyOfCompiledSketch, prefs);
copyOfCompiledSketch = copyOfCompiledSketch.replaceAll(":", "_");
Path compiledSketchPath;
Path compiledSketchPathInSubfolder = Paths.get(prefs.get("build.path"), "sketch", compiledSketch);
Path compiledSketchPathInBuildPath = Paths.get(prefs.get("build.path"), compiledSketch);
if (Files.exists(compiledSketchPathInSubfolder)) {
compiledSketchPath = compiledSketchPathInSubfolder;
} else if (Files.exists(compiledSketchPathInBuildPath)) {
compiledSketchPath = compiledSketchPathInBuildPath;
} else {
return;
}
Path copyOfCompiledSketchFilePath = Paths.get(this.sketch.getFolder().getAbsolutePath(), copyOfCompiledSketch);
Files.copy(compiledSketchPath, copyOfCompiledSketchFilePath, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RunnerException(e);
}
}
private boolean isExportCompiledSketchSupported(List<String> compiledSketches, List<String> copyOfCompiledSketches, PreferencesMap prefs) {
return (compiledSketches.isEmpty() || copyOfCompiledSketches.isEmpty() || copyOfCompiledSketches.size() < compiledSketches.size()) && (!prefs.containsKey("recipe.output.tmp_file") || !prefs.containsKey("recipe.output.save_file"));
}
private void runActions(String recipeClass, PreferencesMap prefs) throws RunnerException, PreferencesMapException {
List<String> patterns = prefs.keySet().stream().filter(key -> key.startsWith("recipe." + recipeClass) && key.endsWith(".pattern")).collect(Collectors.toList());
Collections.sort(patterns);
for (String recipe : patterns) {
runRecipe(recipe, prefs);
}
}
private void runRecipe(String recipe, PreferencesMap prefs) throws RunnerException, PreferencesMapException {
PreferencesMap dict = new PreferencesMap(prefs);
dict.put("ide_version", "" + BaseNoGui.REVISION);
dict.put("sketch_path", sketch.getFolder().getAbsolutePath());
String[] cmdArray;
String cmd = prefs.getOrExcept(recipe);
try {
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
} catch (Exception e) {
throw new RunnerException(e);
}
exec(cmdArray);
}
private void exec(String[] command) throws RunnerException {
// eliminate any empty array entries
List<String> stringList = new ArrayList<>();
for (String string : command) {
string = string.trim();
if (string.length() != 0)
stringList.add(string);
}
command = stringList.toArray(new String[stringList.size()]);
if (command.length == 0)
return;
if (verbose) {
for (String c : command)
System.out.print(c + " ");
System.out.println();
}
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler() {
@Override
protected Thread createPump(InputStream is, OutputStream os, boolean closeWhenExhausted) {
final Thread result = new Thread(new MyStreamPumper(is, Compiler.this));
result.setName("MyStreamPumper Thread");
result.setDaemon(true);
return result;
}
});
CommandLine commandLine = new DoubleQuotedArgumentsOnWindowsCommandLine(command[0]);
for (int i = 1; i < command.length; i++) {
commandLine.addArgument(command[i], false);
}
int result;
executor.setExitValues(null);
try {
result = executor.execute(commandLine);
} catch (IOException e) {
RunnerException re = new RunnerException(e.getMessage());
re.hideStackTrace();
throw re;
}
executor.setExitValues(new int[0]);
// an error was queued up by message(), barf this back to compile(),
// which will barf it back to Editor. if you're having trouble
// discerning the imagery, consider how cows regurgitate their food
// to digest it, and the fact that they have five stomaches.
//
//System.out.println("throwing up " + exception);
if (exception != null)
throw exception;
if (result > 1) {
// a failure in the tool (e.g. unable to locate a sub-executable)
System.err
.println(I18n.format(tr("{0} returned {1}"), command[0], result));
}
if (result != 0) {
RunnerException re = new RunnerException(tr("Error compiling."));
re.hideStackTrace();
throw re;
}
}
private String boardOptions(TargetBoard board) {
return board.getMenuIds().stream()
.filter(board::hasMenu)
.filter(menuId -> {
String entry = PreferencesData.get("custom_" + menuId);
return entry != null && entry.startsWith(board.getId());
})
.map(menuId -> {
String entry = PreferencesData.get("custom_" + menuId);
String selectionId = entry.substring(board.getId().length() + 1);
return menuId + "=" + selectionId;
})
.collect(Collectors.joining(","));
}
/**
* Part of the MessageConsumer interface, this is called
* whenever a piece (usually a line) of error message is spewed
* out from the compiler. The errors are parsed for their contents
* and line number, which is then reported back to Editor.
*/
@Override
public void message(String s) {
int i;
if (!verbose) {
while ((i = s.indexOf(buildPath + File.separator)) != -1) {
s = s.substring(0, i) + s.substring(i + (buildPath + File.separator).length());
}
}
String[] pieces = PApplet.match(s, ERROR_FORMAT);
if (pieces != null) {
String msg = "";
int errorIdx = pieces.length - 1;
String error = pieces[errorIdx];
String filename = pieces[1];
int line = PApplet.parseInt(pieces[2]);
int col;
if (errorIdx > 3) {
col = PApplet.parseInt(pieces[3].substring(1));
} else {
col = -1;
}
if (error.trim().equals("SPI.h: No such file or directory")) {
error = tr("Please import the SPI library from the Sketch > Import Library menu.");
msg = tr("\nAs of Arduino 0019, the Ethernet library depends on the SPI library." +
"\nYou appear to be using it or another library that depends on the SPI library.\n\n");
}
if (error.trim().equals("'BYTE' was not declared in this scope")) {
error = tr("The 'BYTE' keyword is no longer supported.");
msg = tr("\nAs of Arduino 1.0, the 'BYTE' keyword is no longer supported." +
"\nPlease use Serial.write() instead.\n\n");
}
if (error.trim().equals("no matching function for call to 'Server::Server(int)'")) {
error = tr("The Server class has been renamed EthernetServer.");
msg = tr("\nAs of Arduino 1.0, the Server class in the Ethernet library " +
"has been renamed to EthernetServer.\n\n");
}
if (error.trim().equals("no matching function for call to 'Client::Client(byte [4], int)'")) {
error = tr("The Client class has been renamed EthernetClient.");
msg = tr("\nAs of Arduino 1.0, the Client class in the Ethernet library " +
"has been renamed to EthernetClient.\n\n");
}
if (error.trim().equals("'Udp' was not declared in this scope")) {
error = tr("The Udp class has been renamed EthernetUdp.");
msg = tr("\nAs of Arduino 1.0, the Udp class in the Ethernet library " +
"has been renamed to EthernetUdp.\n\n");
}
if (error.trim().equals("'class TwoWire' has no member named 'send'")) {
error = tr("Wire.send() has been renamed Wire.write().");
msg = tr("\nAs of Arduino 1.0, the Wire.send() function was renamed " +
"to Wire.write() for consistency with other libraries.\n\n");
}
if (error.trim().equals("'class TwoWire' has no member named 'receive'")) {
error = tr("Wire.receive() has been renamed Wire.read().");
msg = tr("\nAs of Arduino 1.0, the Wire.receive() function was renamed " +
"to Wire.read() for consistency with other libraries.\n\n");
}
if (error.trim().equals("'Mouse' was not declared in this scope")) {
error = tr("'Mouse' not found. Does your sketch include the line '#include <Mouse.h>'?");
//msg = _("\nThe 'Mouse' class is only supported on the Arduino Leonardo.\n\n");
}
if (error.trim().equals("'Keyboard' was not declared in this scope")) {
error = tr("'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?");
//msg = _("\nThe 'Keyboard' class is only supported on the Arduino Leonardo.\n\n");
}
RunnerException ex = placeException(error, filename, line - 1, col);
if (ex != null) {
String fileName = ex.getCodeFile().getPrettyName();
int lineNum = ex.getCodeLine() + 1;
int colNum = ex.getCodeColumn();
if (colNum != -1) {
s = fileName + ":" + lineNum + ":" + colNum + ": error: " + error + msg;
} else {
s = fileName + ":" + lineNum + ": error: " + error + msg;
}
}
if (ex != null) {
if (exception == null || exception.getMessage().equals(ex.getMessage())) {
exception = ex;
exception.hideStackTrace();
}
}
}
if (s.contains("undefined reference to `SPIClass::begin()'") &&
s.contains("libraries/Robot_Control")) {
String error = tr("Please import the SPI library from the Sketch > Import Library menu.");
exception = new RunnerException(error);
}
if (s.contains("undefined reference to `Wire'") &&
s.contains("libraries/Robot_Control")) {
String error = tr("Please import the Wire library from the Sketch > Import Library menu.");
exception = new RunnerException(error);
}
System.err.println(s);
}
private RunnerException placeException(String message, String fileName, int line, int col) {
for (SketchFile file : sketch.getFiles()) {
if (new File(fileName).getName().equals(file.getFileName())) {
return new RunnerException(message, file, line, col);
}
}
return null;
}
}