Skip to content

Commit b783392

Browse files
Don't recompile core.a if none of the .o files changed
Before, core.a would be rebuilt on every build, even when none of the core .o files changed. Now, the timestamps are checked against the timestamp on core.a first, skipping the build if nothing changed. Because this uses the current list of .o files, there is a corner case when a source file is deleted, but no other source file is modified. In that case, core.a is not rebuilt, even though it should be. However, this is such a narrow and unrealistic case, that it should pose a real problem. This fixes part of arduino#1991
1 parent 87c87c2 commit b783392

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

app/src/processing/app/debug/Compiler.java

+28-4
Original file line numberDiff line numberDiff line change
@@ -703,11 +703,39 @@ void compileCore()
703703
if (variantFolder != null)
704704
includeFolders.add(variantFolder);
705705

706+
707+
if (variantFolder != null)
708+
objectFiles.addAll(compileFiles(buildFolder, variantFolder, true,
709+
includeFolders));
710+
706711
File afile = new File(buildFolder, "core.a");
707712

708713
List<File> coreObjectFiles = compileFiles(buildFolder, coreFolder, true,
709714
includeFolders);
710715

716+
// See if the .a file is already uptodate
717+
if (afile.exists()) {
718+
boolean changed = false;
719+
for (File file : coreObjectFiles) {
720+
if (file.lastModified() > afile.lastModified()) {
721+
changed = true;
722+
break;
723+
}
724+
}
725+
726+
// If none of the object files is newer than the .a file, don't
727+
// bother rebuilding the .a file. There is a small corner case
728+
// here: If a source file was removed, but no other source file
729+
// was modified, this will not rebuild core.a even when it
730+
// should. It's hard to fix and not a realistic case, so it
731+
// shouldn't be a problem.
732+
if (!changed) {
733+
if (verbose)
734+
System.out.println(I18n.format(_("Using previously compiled file: {0}"), afile.getPath()));
735+
return;
736+
}
737+
}
738+
711739
// Delete the .a file, to prevent any previous code from lingering
712740
afile.delete();
713741

@@ -732,10 +760,6 @@ void compileCore()
732760
afile.delete();
733761
throw e;
734762
}
735-
736-
if (variantFolder != null)
737-
objectFiles.addAll(compileFiles(buildFolder, variantFolder, true,
738-
includeFolders));
739763
}
740764

741765
// 4. link it all together into the .elf file

0 commit comments

Comments
 (0)