Skip to content

Commit 3bb7697

Browse files
committed
Added optional .a linkage for libraries
1 parent 695fc40 commit 3bb7697

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

Diff for: arduino-core/src/processing/app/debug/Compiler.java

+70-2
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,76 @@ private void compileLibrary(UserLibrary lib, List<File> includeFolders)
10701070
if (lib.useRecursion()) {
10711071
// libBuildFolder == {build.path}/LibName
10721072
// libFolder == {lib.path}/src
1073-
recursiveCompileFilesInFolder(libBuildFolder, libFolder, includeFolders);
1074-
1073+
1074+
// Compile the library with .a linkage if a flag was set in library.properties
1075+
if(lib.alinkage()){
1076+
1077+
File afile = new File(libBuildFolder, lib.getName() + ".a");
1078+
1079+
createFolder(libBuildFolder);
1080+
List<File> libraryObjectFiles = compileFiles(libBuildFolder, libFolder, true, includeFolders);
1081+
1082+
// See if the .a file is already uptodate
1083+
if (afile.exists()) {
1084+
boolean changed = false;
1085+
for (File file : libraryObjectFiles) {
1086+
if (file.lastModified() > afile.lastModified()) {
1087+
changed = true;
1088+
break;
1089+
}
1090+
}
1091+
1092+
// If none of the object files is newer than the .a file, don't
1093+
// bother rebuilding the .a file. There is a small corner case
1094+
// here: If a source file was removed, but no other source file
1095+
// was modified, this will not rebuild core.a even when it
1096+
// should. It's hard to fix and not a realistic case, so it
1097+
// shouldn't be a problem.
1098+
if (!changed) {
1099+
if (verbose)
1100+
System.out.println(I18n.format(tr("Using previously compiled file: {0}"), afile.getPath()));
1101+
1102+
// this is no longer an object file, but will be added anyways.
1103+
objectFiles.add(afile);
1104+
return;
1105+
}
1106+
}
1107+
1108+
// Delete the .a file, to prevent any previous code from lingering
1109+
afile.delete();
1110+
1111+
try {
1112+
for (File file : libraryObjectFiles) {
1113+
PreferencesMap dict = new PreferencesMap(prefs);
1114+
dict.put("ide_version", "" + BaseNoGui.REVISION);
1115+
dict.put("archive_file", afile.getName());
1116+
dict.put("object_file", file.getAbsolutePath());
1117+
dict.put("build.path", libBuildFolder.getAbsolutePath());
1118+
1119+
String[] cmdArray;
1120+
String cmd = prefs.getOrExcept("recipe.ar.pattern");
1121+
try {
1122+
cmdArray = StringReplacer.formatAndSplit(cmd, dict, true);
1123+
} catch (Exception e) {
1124+
throw new RunnerException(e);
1125+
}
1126+
execAsynchronously(cmdArray);
1127+
}
1128+
1129+
} catch (RunnerException e) {
1130+
afile.delete();
1131+
throw e;
1132+
}
1133+
1134+
// this is no longer an object file, but will be added anyways.
1135+
objectFiles.add(afile);
1136+
}
1137+
1138+
// no alinkage, old, default .o file linkage
1139+
else{
1140+
recursiveCompileFilesInFolder(libBuildFolder, libFolder, includeFolders);
1141+
}
1142+
10751143
} else {
10761144
// libFolder == {lib.path}/
10771145
// utilityFolder == {lib.path}/utility

Diff for: arduino-core/src/processing/app/packages/UserLibrary.java

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class UserLibrary extends ContributedLibrary {
5858
private List<String> types;
5959
private List<String> declaredTypes;
6060
private boolean onGoingDevelopment;
61+
private boolean alinkage;
6162

6263
private static final List<String> MANDATORY_PROPERTIES = Arrays
6364
.asList("name", "version", "author", "maintainer",
@@ -154,6 +155,12 @@ public static UserLibrary create(File libFolder) throws IOException {
154155
typesList.add(type.trim());
155156
}
156157

158+
String alinkageString = properties.get("alinkage");
159+
boolean alinkage = false;
160+
if(alinkageString != null && alinkageString.equals("true")) {
161+
alinkage = true;
162+
}
163+
157164
UserLibrary res = new UserLibrary();
158165
res.setInstalledFolder(libFolder);
159166
res.setInstalled(true);
@@ -170,6 +177,7 @@ public static UserLibrary create(File libFolder) throws IOException {
170177
res.layout = layout;
171178
res.declaredTypes = typesList;
172179
res.onGoingDevelopment = Files.exists(Paths.get(libFolder.getAbsolutePath(), Constants.LIBRARY_DEVELOPMENT_FLAG_FILE));
180+
res.alinkage = alinkage;
173181
return res;
174182
}
175183

@@ -274,6 +282,10 @@ public boolean onGoingDevelopment() {
274282
return onGoingDevelopment;
275283
}
276284

285+
public boolean alinkage() {
286+
return alinkage;
287+
}
288+
277289
protected enum LibraryLayout {
278290
FLAT, RECURSIVE
279291
}

0 commit comments

Comments
 (0)