mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-13 10:29:35 +01:00
INITIAL: integrate compile with arduino-cli
This commit is contained in:
parent
a0d73d3bf6
commit
8757f7c6ed
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
package cc.arduino;
|
package cc.arduino;
|
||||||
|
|
||||||
|
import cc.arduino.cli.ArduinoCoreInstance;
|
||||||
import cc.arduino.i18n.I18NAwareMessageConsumer;
|
import cc.arduino.i18n.I18NAwareMessageConsumer;
|
||||||
import cc.arduino.packages.BoardPort;
|
import cc.arduino.packages.BoardPort;
|
||||||
import org.apache.commons.exec.CommandLine;
|
import org.apache.commons.exec.CommandLine;
|
||||||
@ -143,6 +144,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
private File buildCache;
|
private File buildCache;
|
||||||
private final boolean verbose;
|
private final boolean verbose;
|
||||||
private RunnerException exception;
|
private RunnerException exception;
|
||||||
|
private ArduinoCoreInstance core;
|
||||||
|
|
||||||
public Compiler(Sketch data) {
|
public Compiler(Sketch data) {
|
||||||
this(data.getPrimaryFile().getFile(), data);
|
this(data.getPrimaryFile().getFile(), data);
|
||||||
@ -151,6 +153,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
public Compiler(File pathToSketch, Sketch sketch) {
|
public Compiler(File pathToSketch, Sketch sketch) {
|
||||||
this.pathToSketch = pathToSketch;
|
this.pathToSketch = pathToSketch;
|
||||||
this.sketch = sketch;
|
this.sketch = sketch;
|
||||||
|
this.core = BaseNoGui.getArduinoCoreService();
|
||||||
this.verbose = PreferencesData.getBoolean("build.verbose");
|
this.verbose = PreferencesData.getBoolean("build.verbose");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,18 +214,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid) throws RunnerException, IOException {
|
private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid) throws RunnerException, IOException {
|
||||||
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
|
return new PreferencesMap();
|
||||||
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) {
|
private void addPathFlagIfPathExists(List<String> cmd, String flag, File folder) {
|
||||||
@ -296,7 +288,9 @@ public class Compiler implements MessageConsumer {
|
|||||||
|
|
||||||
int result;
|
int result;
|
||||||
try {
|
try {
|
||||||
Process proc = ProcessUtils.exec(cmd.toArray(new String[0]));
|
core.compile(fqbn, pathToSketch.getAbsolutePath());
|
||||||
|
|
||||||
|
/*
|
||||||
MessageSiphon in = new MessageSiphon(proc.getInputStream(), (msg) -> {
|
MessageSiphon in = new MessageSiphon(proc.getInputStream(), (msg) -> {
|
||||||
try {
|
try {
|
||||||
outStream.write(msg.getBytes());
|
outStream.write(msg.getBytes());
|
||||||
@ -315,18 +309,12 @@ public class Compiler implements MessageConsumer {
|
|||||||
in.join();
|
in.join();
|
||||||
err.join();
|
err.join();
|
||||||
result = proc.waitFor();
|
result = proc.waitFor();
|
||||||
|
*/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exception != null)
|
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()));
|
RunnerException re = new RunnerException(I18n.format(tr("Error compiling for board {0}."), board.getName()));
|
||||||
re.hideStackTrace();
|
re.hideStackTrace();
|
||||||
throw re;
|
throw re;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user