mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Delete temporary sketch copy after build
When a sketch has unsaved changes, a temporary copy of the sketch is made with those changes applied. This copy is then passed to arduino-builder. Previously, this temporary copy was kept around and only deleted when the IDE was closed. However, all files were written to it again on every build, so keeping the old files around did not serve any real purpose. When a file was renamed in the IDE, the original name would still be present in the temporary copy, and could cause linker errors because both were compiled. This commit makes sure the temporary copy is deleted after every build, instead of at IDE exit, which fixes this problem with renames. When a file is deleted from the sketch, the file would also be deleted from the temporary copy, presumably to fix this same problem for deletes (but renames were forgotten). With this commit, this special handling for deleting files is no longer needed, so it is removed. This fixes #4335
This commit is contained in:
parent
a73d393554
commit
1029e0b78d
@ -26,7 +26,6 @@ package processing.app;
|
||||
import cc.arduino.Compiler;
|
||||
import cc.arduino.CompilerProgressListener;
|
||||
import cc.arduino.UploaderUtils;
|
||||
import cc.arduino.files.DeleteFilesOnShutdown;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import processing.app.debug.RunnerException;
|
||||
@ -463,7 +462,7 @@ public class Sketch {
|
||||
|
||||
} else {
|
||||
// delete the file
|
||||
if (!current.getCode().deleteFile(BaseNoGui.getBuildFolder(data).toPath(), Paths.get(System.getProperty("java.io.tmpdir"), "arduino_" + DigestUtils.md5Hex(getMainFilePath())))) {
|
||||
if (!current.getCode().deleteFile(BaseNoGui.getBuildFolder(data).toPath())) {
|
||||
Base.showMessage(tr("Couldn't do it"),
|
||||
I18n.format(tr("Could not delete \"{0}\"."), current.getCode().getFileName()));
|
||||
return;
|
||||
@ -1100,17 +1099,27 @@ public class Sketch {
|
||||
|
||||
CompilerProgressListener progressListener = editor.status::progressUpdate;
|
||||
|
||||
boolean deleteTemp = false;
|
||||
String pathToSketch = data.getMainFilePath();
|
||||
if (isModified()) {
|
||||
// If any files are modified, make a copy of the sketch with the changes
|
||||
// saved, so arduino-builder will see the modifications.
|
||||
pathToSketch = saveSketchInTempFolder();
|
||||
deleteTemp = true;
|
||||
}
|
||||
|
||||
return new Compiler(pathToSketch, data, buildPath).build(progressListener, save);
|
||||
try {
|
||||
return new Compiler(pathToSketch, data, buildPath).build(progressListener,
|
||||
save);
|
||||
} finally {
|
||||
// Make sure we clean up any temporary sketch copy
|
||||
if (deleteTemp)
|
||||
FileUtils.recursiveDelete(new File(pathToSketch).getParentFile());
|
||||
}
|
||||
}
|
||||
|
||||
private String saveSketchInTempFolder() throws IOException {
|
||||
File tempFolder = FileUtils.createTempFolder("arduino_", DigestUtils.md5Hex(data.getMainFilePath()));
|
||||
DeleteFilesOnShutdown.add(tempFolder);
|
||||
FileUtils.copy(getFolder(), tempFolder);
|
||||
|
||||
for (SketchCode sc : Stream.of(data.getCodes()).filter(SketchCode::isModified).collect(Collectors.toList())) {
|
||||
|
@ -91,14 +91,13 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
protected boolean deleteFile(Path tempBuildFolder, Path tempUnsavedSketchPath) throws IOException {
|
||||
protected boolean deleteFile(Path tempBuildFolder) throws IOException {
|
||||
if (!file.delete()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Path> tempBuildFolders = Stream.of(tempBuildFolder, tempBuildFolder.resolve("sketch"), tempUnsavedSketchPath)
|
||||
.filter(path -> Files.exists(path))
|
||||
.collect(Collectors.toList());
|
||||
List<Path> tempBuildFolders = Stream.of(tempBuildFolder, tempBuildFolder.resolve("sketch"))
|
||||
.filter(path -> Files.exists(path)).collect(Collectors.toList());
|
||||
|
||||
for (Path folder : tempBuildFolders) {
|
||||
if (!deleteCompiledFilesFrom(folder)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user