Skip to content

Commit 32cf196

Browse files
author
Federico Fissore
committed
"Merge sketch with bootloader" and "save hex" should work flawlessly with cores that save binaries in both buildpath/sketch and plain buildpath
1 parent 98d0a72 commit 32cf196

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

arduino-core/src/processing/app/debug/Compiler.java

+35-16
Original file line numberDiff line numberDiff line change
@@ -1215,34 +1215,45 @@ void runRecipe(String recipe) throws RunnerException, PreferencesMapException {
12151215
execAsynchronously(cmdArray);
12161216
}
12171217

1218-
private File mergeSketchWithBootloaderIfAppropriate(String className, PreferencesMap prefs) throws IOException {
1218+
private void mergeSketchWithBootloaderIfAppropriate(String className, PreferencesMap prefs) throws IOException {
12191219
if (!prefs.containsKey("bootloader.noblink") && !prefs.containsKey("bootloader.file")) {
1220-
return null;
1220+
return;
12211221
}
12221222

12231223
String buildPath = prefs.get("build.path");
1224-
File sketch = new File(buildPath, className + ".hex");
1225-
if (!sketch.exists()) {
1226-
return null;
1224+
1225+
Path sketch;
1226+
Path sketchInSubfolder = Paths.get(buildPath, "sketch", className + ".hex");
1227+
Path sketchInBuildPath = Paths.get(buildPath, className + ".hex");
1228+
if (Files.exists(sketchInSubfolder)) {
1229+
sketch = sketchInSubfolder;
1230+
} else if (Files.exists(sketchInBuildPath)) {
1231+
sketch = sketchInBuildPath;
1232+
} else {
1233+
return;
12271234
}
12281235

12291236
String bootloaderNoBlink = prefs.get("bootloader.noblink");
12301237
if (bootloaderNoBlink == null) {
12311238
bootloaderNoBlink = prefs.get("bootloader.file");
12321239
}
12331240

1234-
File bootloader = new File(new File(prefs.get("runtime.platform.path"), "bootloaders"), bootloaderNoBlink);
1235-
if (!bootloader.exists()) {
1241+
Path bootloader = Paths.get(prefs.get("runtime.platform.path"), "bootloaders", bootloaderNoBlink);
1242+
if (!Files.exists(bootloader)) {
12361243
System.err.println(I18n.format(_("Bootloader file specified but missing: {0}"), bootloader));
1237-
return null;
1244+
return;
12381245
}
12391246

1240-
File mergedSketch = new File(buildPath, className + ".with_bootloader.hex");
1241-
FileUtils.copyFile(sketch, mergedSketch);
1247+
Path mergedSketch;
1248+
if ("sketch".equals(sketch.getParent().getFileName().toString())) {
1249+
mergedSketch = Paths.get(buildPath, "sketch", className + ".with_bootloader.hex");
1250+
} else {
1251+
mergedSketch = Paths.get(buildPath, className + ".with_bootloader.hex");
1252+
}
12421253

1243-
new MergeSketchWithBooloader().merge(mergedSketch, bootloader);
1254+
Files.copy(sketch, mergedSketch, StandardCopyOption.REPLACE_EXISTING);
12441255

1245-
return mergedSketch;
1256+
new MergeSketchWithBooloader().merge(mergedSketch.toFile(), bootloader.toFile());
12461257
}
12471258

12481259
//7. Save the .hex file
@@ -1280,11 +1291,19 @@ private void saveHex(String compiledSketch, String copyOfCompiledSketch, Prefere
12801291
compiledSketch = StringReplacer.replaceFromMapping(compiledSketch, dict);
12811292
copyOfCompiledSketch = StringReplacer.replaceFromMapping(copyOfCompiledSketch, dict);
12821293

1283-
File compiledSketchFile = new File(prefs.get("build.path"), compiledSketch);
1284-
File copyOfCompiledSketchFile = new File(sketch.getFolder(), copyOfCompiledSketch);
1294+
Path compiledSketchPath;
1295+
Path compiledSketchPathInSubfolder = Paths.get(prefs.get("build.path"), "sketch", compiledSketch);
1296+
Path compiledSketchPathInBuildPath = Paths.get(prefs.get("build.path"), compiledSketch);
1297+
if (Files.exists(compiledSketchPathInSubfolder)) {
1298+
compiledSketchPath = compiledSketchPathInSubfolder;
1299+
} else {
1300+
compiledSketchPath = compiledSketchPathInBuildPath;
1301+
}
1302+
1303+
Path copyOfCompiledSketchFilePath = Paths.get(this.sketch.getFolder().getAbsolutePath(), copyOfCompiledSketch);
12851304

1286-
FileUtils.copyFile(compiledSketchFile, copyOfCompiledSketchFile);
1287-
} catch (Exception e) {
1305+
Files.copy(compiledSketchPath, copyOfCompiledSketchFilePath, StandardCopyOption.REPLACE_EXISTING);
1306+
} catch (IOException e) {
12881307
throw new RunnerException(e);
12891308
}
12901309
}

0 commit comments

Comments
 (0)