Skip to content

Commit cb50ebc

Browse files
committed
Slightly simplified argument passing to arduino-builder
1 parent 2856600 commit cb50ebc

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,27 +190,28 @@ private PreferencesMap loadPreferences(TargetBoard board, TargetPlatform platfor
190190
return prefs;
191191
}
192192

193+
private void addPathFlagIfPathExists(List<String> cmd, String flag, File folder) {
194+
if (folder.exists()) {
195+
cmd.add(flag);
196+
cmd.add(folder.getAbsolutePath());
197+
}
198+
}
199+
193200
private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, TargetPackage aPackage, String vidpid, BuilderAction action, OutputStream outStream, OutputStream errStream) throws RunnerException {
194201
List<String> cmd = new ArrayList<>();
195202
cmd.add(BaseNoGui.getContentFile("arduino-builder").getAbsolutePath());
196203
cmd.add(action.value);
197204
cmd.add("-logger=machine");
198205

199-
Stream.of(BaseNoGui.getHardwarePath(), new File(BaseNoGui.getSettingsFolder(), "packages").getAbsolutePath(), BaseNoGui.getSketchbookHardwareFolder().getAbsolutePath())
200-
.forEach(p -> {
201-
if (Files.exists(Paths.get(p))) {
202-
cmd.add("-hardware");
203-
cmd.add(p);
204-
}
205-
});
206+
File installedPackagesFolder = new File(BaseNoGui.getSettingsFolder(), "packages");
206207

207-
Stream.of(BaseNoGui.getContentFile("tools-builder").getAbsolutePath(), Paths.get(BaseNoGui.getHardwarePath(), "tools", "avr").toAbsolutePath().toString(), new File(BaseNoGui.getSettingsFolder(), "packages").getAbsolutePath())
208-
.forEach(p -> {
209-
if (Files.exists(Paths.get(p))) {
210-
cmd.add("-tools");
211-
cmd.add(p);
212-
}
213-
});
208+
addPathFlagIfPathExists(cmd, "-hardware", BaseNoGui.getHardwareFolder());
209+
addPathFlagIfPathExists(cmd, "-hardware", installedPackagesFolder);
210+
addPathFlagIfPathExists(cmd, "-hardware", BaseNoGui.getSketchbookHardwareFolder());
211+
212+
addPathFlagIfPathExists(cmd, "-tools", BaseNoGui.getContentFile("tools-builder"));
213+
addPathFlagIfPathExists(cmd, "-tools", Paths.get(BaseNoGui.getHardwarePath(), "tools", "avr").toFile());
214+
addPathFlagIfPathExists(cmd, "-tools", installedPackagesFolder);
214215

215216
cmd.add("-built-in-libraries");
216217
cmd.add(BaseNoGui.getContentFile("libraries").getAbsolutePath());

0 commit comments

Comments
 (0)