Skip to content

Commit 6ae06b1

Browse files
facchinmcmaglie
authored andcommitted
INITIAL: integrate compile with arduino-cli
1 parent c0c75a9 commit 6ae06b1

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

arduino-core/src/cc/arduino/Compiler.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
package cc.arduino;
3131

32+
import cc.arduino.cli.ArduinoCoreInstance;
3233
import cc.arduino.i18n.I18NAwareMessageConsumer;
3334
import cc.arduino.packages.BoardPort;
3435
import org.apache.commons.exec.CommandLine;
@@ -142,6 +143,7 @@ enum BuilderAction {
142143
private File buildCache;
143144
private final boolean verbose;
144145
private RunnerException exception;
146+
private ArduinoCoreInstance core;
145147

146148
public Compiler(Sketch data) {
147149
this(data.getPrimaryFile().getFile(), data);
@@ -150,6 +152,7 @@ public Compiler(Sketch data) {
150152
public Compiler(File pathToSketch, Sketch sketch) {
151153
this.pathToSketch = pathToSketch;
152154
this.sketch = sketch;
155+
this.core = BaseNoGui.getArduinoCoreService();
153156
this.verbose = PreferencesData.getBoolean("build.verbose");
154157
}
155158

@@ -209,18 +212,7 @@ private String VIDPID() {
209212
}
210213

211214
private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid) throws RunnerException, IOException {
212-
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
213-
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
214-
MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(new PrintStream(stderr), Compiler.this), "\n");
215-
try {
216-
callArduinoBuilder(board, platform, aPackage, vidpid, BuilderAction.DUMP_PREFS, stdout, err);
217-
} catch (RunnerException e) {
218-
System.err.println(new String(stderr.toByteArray()));
219-
throw e;
220-
}
221-
PreferencesMap prefs = new PreferencesMap();
222-
prefs.load(new ByteArrayInputStream(stdout.toByteArray()));
223-
return prefs;
215+
return new PreferencesMap();
224216
}
225217

226218
private void addPathFlagIfPathExists(List<String> cmd, String flag, File folder) {
@@ -294,7 +286,9 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
294286

295287
int result;
296288
try {
297-
Process proc = ProcessUtils.exec(cmd.toArray(new String[0]));
289+
core.compile(fqbn, pathToSketch.getAbsolutePath());
290+
291+
/*
298292
MessageSiphon in = new MessageSiphon(proc.getInputStream(), (msg) -> {
299293
try {
300294
outStream.write(msg.getBytes());
@@ -313,18 +307,12 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
313307
in.join();
314308
err.join();
315309
result = proc.waitFor();
310+
*/
316311
} catch (Exception e) {
317312
throw new RunnerException(e);
318313
}
319314

320-
if (exception != null)
321-
throw exception;
322-
323-
if (result > 1) {
324-
System.err.println(I18n.format(tr("{0} returned {1}"), cmd.get(0), result));
325-
}
326-
327-
if (result != 0) {
315+
if (exception != null) {
328316
RunnerException re = new RunnerException(I18n.format(tr("Error compiling for board {0}."), board.getName()));
329317
re.hideStackTrace();
330318
throw re;

0 commit comments

Comments
 (0)