Skip to content

Don't rebuild core.a when not needed #2003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 50 additions & 15 deletions app/src/processing/app/debug/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -703,28 +703,63 @@ void compileCore()
if (variantFolder != null)
includeFolders.add(variantFolder);


if (variantFolder != null)
objectFiles.addAll(compileFiles(buildFolder, variantFolder, true,
includeFolders));

File afile = new File(buildFolder, "core.a");

List<File> coreObjectFiles = compileFiles(buildFolder, coreFolder, true,
includeFolders);
for (File file : coreObjectFiles) {

PreferencesMap dict = new PreferencesMap(prefs);
dict.put("ide_version", "" + Base.REVISION);
dict.put("archive_file", "core.a");
dict.put("object_file", file.getAbsolutePath());
// See if the .a file is already uptodate
if (afile.exists()) {
boolean changed = false;
for (File file : coreObjectFiles) {
if (file.lastModified() > afile.lastModified()) {
changed = true;
break;
}
}

String[] cmdArray;
try {
String cmd = prefs.get("recipe.ar.pattern");
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
} catch (Exception e) {
throw new RunnerException(e);
// If none of the object files is newer than the .a file, don't
// bother rebuilding the .a file. There is a small corner case
// here: If a source file was removed, but no other source file
// was modified, this will not rebuild core.a even when it
// should. It's hard to fix and not a realistic case, so it
// shouldn't be a problem.
if (!changed) {
if (verbose)
System.out.println(I18n.format(_("Using previously compiled file: {0}"), afile.getPath()));
return;
}
execAsynchronously(cmdArray);
}

if (variantFolder != null)
objectFiles.addAll(compileFiles(buildFolder, variantFolder, true,
includeFolders));
// Delete the .a file, to prevent any previous code from lingering
afile.delete();

try {
for (File file : coreObjectFiles) {

PreferencesMap dict = new PreferencesMap(prefs);
dict.put("ide_version", "" + Base.REVISION);
dict.put("archive_file", afile.getName());
dict.put("object_file", file.getAbsolutePath());

String[] cmdArray;
try {
String cmd = prefs.get("recipe.ar.pattern");
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
} catch (Exception e) {
throw new RunnerException(e);
}
execAsynchronously(cmdArray);
}
} catch (RunnerException e) {
afile.delete();
throw e;
}
}

// 4. link it all together into the .elf file
Expand Down