Skip to content

Commit 8e2c3c7

Browse files
author
Federico Fissore
committed
Compiler: #3435 introduced a bug: you needed to save a file for it to be copied to build path. Hence, restored previous "copy sketch file" logic, couples with a recursive one, used only for files external to the sketch (in subfolders)
1 parent 9a01e30 commit 8e2c3c7

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

arduino-core/src/cc/arduino/utils/Pair.java

+4
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ public Pair(K key, V value) {
3939
this.value = value;
4040
}
4141

42+
@Override
43+
public String toString() {
44+
return "key: " + key + ", value: " + value;
45+
}
4246
}

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

+20-4
Original file line numberDiff line numberDiff line change
@@ -1397,22 +1397,35 @@ public void preprocess(String buildPath, PdePreprocessor preprocessor) throws Ru
13971397
}
13981398
}
13991399

1400-
copyAdditionalFilesToBuildFolderSavingOriginalFolderStructure(sketch, buildPath);
1401-
14021400
// 3. then loop over the code[] and save each .java file
14031401
for (SketchCode sc : sketch.getCodes()) {
1404-
if (sc.isExtension("ino") || sc.isExtension("pde")) {
1402+
if (sc.isExtension(SketchData.OTHER_ALLOWED_EXTENSIONS)) {
1403+
// no pre-processing services necessary for java files
1404+
// just write the the contents of 'program' to a .java file
1405+
// into the build directory. uses byte stream and reader/writer
1406+
// shtuff so that unicode bunk is properly handled
1407+
String filename = sc.getFileName(); //code[i].name + ".java";
1408+
try {
1409+
BaseNoGui.saveFile(sc.getProgram(), new File(buildPath, filename));
1410+
} catch (IOException e) {
1411+
e.printStackTrace();
1412+
throw new RunnerException(I18n.format(_("Problem moving {0} to the build folder"), filename));
1413+
}
1414+
1415+
} else if (sc.isExtension("ino") || sc.isExtension("pde")) {
14051416
// The compiler and runner will need this to have a proper offset
14061417
sc.addPreprocOffset(headerOffset);
14071418
}
14081419
}
1420+
1421+
copyAdditionalFilesToBuildFolderSavingOriginalFolderStructure(sketch, buildPath);
14091422
}
14101423

14111424
private void copyAdditionalFilesToBuildFolderSavingOriginalFolderStructure(SketchData sketch, String buildPath) throws RunnerException {
14121425
Path sketchPath = Paths.get(sketch.getFolder().getAbsolutePath());
14131426
Stream<Path> otherFilesStream;
14141427
try {
1415-
otherFilesStream = Files.find(sketchPath, ADDITIONAL_FILES_COPY_MAX_DEPTH, (path, attribs) -> !attribs.isDirectory() && FileUtils.hasExtension(path.toFile(), SketchData.OTHER_ALLOWED_EXTENSIONS));
1428+
otherFilesStream = Files.find(sketchPath, ADDITIONAL_FILES_COPY_MAX_DEPTH, (path, attribs) -> !attribs.isDirectory() && isPathInASubfolder(sketchPath, path) && FileUtils.hasExtension(path.toFile(), SketchData.OTHER_ALLOWED_EXTENSIONS));
14161429
} catch (IOException e) {
14171430
throw new RunnerException(e);
14181431
}
@@ -1428,6 +1441,9 @@ private void copyAdditionalFilesToBuildFolderSavingOriginalFolderStructure(Sketc
14281441
});
14291442
}
14301443

1444+
private boolean isPathInASubfolder(Path sketchPath, Path path) {
1445+
return sketchPath.relativize(path).getNameCount() > 1;
1446+
}
14311447

14321448
/**
14331449
* List of library folders.

0 commit comments

Comments
 (0)