mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
Added method to determine board FQBN
This simplifies a bit the organization of the arduino-builder calls.
This commit is contained in:
parent
b693544c77
commit
b4b32f244a
@ -172,16 +172,14 @@ public class Compiler implements MessageConsumer {
|
|||||||
throw new RunnerException("Board is not selected");
|
throw new RunnerException("Board is not selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPlatform platform = board.getContainerPlatform();
|
|
||||||
TargetPackage aPackage = platform.getContainerPackage();
|
|
||||||
String vidpid = VIDPID();
|
String vidpid = VIDPID();
|
||||||
|
|
||||||
PreferencesMap prefs = loadPreferences(board, platform, aPackage, vidpid);
|
PreferencesMap prefs = loadPreferences(board, vidpid);
|
||||||
|
|
||||||
MessageConsumerOutputStream out = new MessageConsumerOutputStream(new ProgressAwareMessageConsumer(new I18NAwareMessageConsumer(System.out, System.err), progListeners), "\n");
|
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");
|
MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(System.err, Compiler.this), "\n");
|
||||||
|
|
||||||
callArduinoBuilder(board, platform, aPackage, vidpid, BuilderAction.COMPILE, out, err);
|
callArduinoBuilder(board, vidpid, BuilderAction.COMPILE, out, err);
|
||||||
|
|
||||||
out.flush();
|
out.flush();
|
||||||
err.flush();
|
err.flush();
|
||||||
@ -206,8 +204,6 @@ public class Compiler implements MessageConsumer {
|
|||||||
throw new RunnerException("Board is not selected");
|
throw new RunnerException("Board is not selected");
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPlatform platform = board.getContainerPlatform();
|
|
||||||
TargetPackage aPackage = platform.getContainerPackage();
|
|
||||||
String vidpid = VIDPID();
|
String vidpid = VIDPID();
|
||||||
|
|
||||||
ByteArrayOutputStream completions = new ByteArrayOutputStream();
|
ByteArrayOutputStream completions = new ByteArrayOutputStream();
|
||||||
@ -217,7 +213,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
codeCompleteFile = file;
|
codeCompleteFile = file;
|
||||||
codeCompleteLine = line;
|
codeCompleteLine = line;
|
||||||
codeCompleteCol = col;
|
codeCompleteCol = col;
|
||||||
callArduinoBuilder(board, platform, aPackage, vidpid, BuilderAction.CODE_COMPLETE, out, err);
|
callArduinoBuilder(board, vidpid, BuilderAction.CODE_COMPLETE, out, err);
|
||||||
|
|
||||||
out.flush();
|
out.flush();
|
||||||
err.flush();
|
err.flush();
|
||||||
@ -240,12 +236,12 @@ public class Compiler implements MessageConsumer {
|
|||||||
return vid.toUpperCase() + "_" + pid.toUpperCase();
|
return vid.toUpperCase() + "_" + pid.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid) throws RunnerException, IOException {
|
private PreferencesMap loadPreferences(TargetBoard board, String vidpid) throws RunnerException, IOException {
|
||||||
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
|
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
|
||||||
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
|
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
|
||||||
MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(new PrintStream(stderr), Compiler.this), "\n");
|
MessageConsumerOutputStream err = new MessageConsumerOutputStream(new I18NAwareMessageConsumer(new PrintStream(stderr), Compiler.this), "\n");
|
||||||
try {
|
try {
|
||||||
callArduinoBuilder(board, platform, aPackage, vidpid, BuilderAction.DUMP_PREFS, stdout, err);
|
callArduinoBuilder(board, vidpid, BuilderAction.DUMP_PREFS, stdout, err);
|
||||||
} catch (RunnerException e) {
|
} catch (RunnerException e) {
|
||||||
System.err.println(new String(stderr.toByteArray()));
|
System.err.println(new String(stderr.toByteArray()));
|
||||||
throw e;
|
throw e;
|
||||||
@ -262,7 +258,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid, BuilderAction action, OutputStream outStream, OutputStream errStream) throws RunnerException {
|
private void callArduinoBuilder(TargetBoard board, String vidpid, BuilderAction action, OutputStream outStream, OutputStream errStream) throws RunnerException {
|
||||||
List<String> cmd = new ArrayList<>();
|
List<String> cmd = new ArrayList<>();
|
||||||
cmd.add(BaseNoGui.getContentFile("arduino-builder").getAbsolutePath());
|
cmd.add(BaseNoGui.getContentFile("arduino-builder").getAbsolutePath());
|
||||||
cmd.add(action.value);
|
cmd.add(action.value);
|
||||||
@ -284,8 +280,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
addPathFlagIfPathExists(cmd, "-built-in-libraries", BaseNoGui.getContentFile("libraries"));
|
addPathFlagIfPathExists(cmd, "-built-in-libraries", BaseNoGui.getContentFile("libraries"));
|
||||||
addPathFlagIfPathExists(cmd, "-libraries", BaseNoGui.getSketchbookLibrariesFolder().folder);
|
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=" + getBoardFQBN(board));
|
||||||
cmd.add("-fqbn=" + fqbn);
|
|
||||||
|
|
||||||
if (!"".equals(vidpid)) {
|
if (!"".equals(vidpid)) {
|
||||||
cmd.add("-vid-pid=" + vidpid);
|
cmd.add("-vid-pid=" + vidpid);
|
||||||
@ -514,7 +509,17 @@ public class Compiler implements MessageConsumer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String boardOptions(TargetBoard board) {
|
public static String getBoardFQBN(TargetBoard board) {
|
||||||
|
TargetPlatform plat = board.getContainerPlatform();
|
||||||
|
TargetPackage pack = plat.getContainerPackage();
|
||||||
|
String fqbn = pack.getId() + ":" + plat.getId() + ":" + board.getId();
|
||||||
|
String opts = boardOptions(board);
|
||||||
|
if (!opts.isEmpty())
|
||||||
|
fqbn += ":" + opts;
|
||||||
|
return fqbn;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String boardOptions(TargetBoard board) {
|
||||||
return board.getMenuIds().stream()
|
return board.getMenuIds().stream()
|
||||||
.filter(board::hasMenu)
|
.filter(board::hasMenu)
|
||||||
.filter(menuId -> {
|
.filter(menuId -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user