Skip to content

Commit e93760a

Browse files
committed
Implemented support for 1.5 libraries specification rev.2
- removed "arch" folder support - allow to optinally use "src" folder - slightly changed metadata For more information see: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification http://goo.gl/gfFJzU
1 parent 660c7d8 commit e93760a

File tree

2 files changed

+101
-113
lines changed

2 files changed

+101
-113
lines changed

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

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ public boolean compile(boolean _verbose) throws RunnerException {
9696
if (verbose)
9797
System.out.println(I18n
9898
.format(_("Using library {0} in folder: {1} {2}"), lib.getName(),
99-
lib.getFolder(), lib.isPre15Lib() ? "(pre-1.5)" : ""));
100-
for (File folder : lib.getSrcFolders(targetArch))
101-
includePaths.add(folder.getPath());
99+
lib.getFolder(), lib.isLegacy() ? "(legacy)" : ""));
100+
includePaths.add(lib.getSrcFolder().getPath());
102101
}
103102
if (verbose)
104103
System.out.println();
@@ -615,47 +614,50 @@ void compileSketch(List<String> includePaths) throws RunnerException {
615614
// 2. compile the libraries, outputting .o files to:
616615
// <buildPath>/<library>/
617616
void compileLibraries(List<String> includePaths) throws RunnerException {
618-
File outputPath = new File(prefs.get("build.path"));
619617
for (Library lib : sketch.getImportedLibraries()) {
620-
for (File folder : lib.getSrcFolders(targetArch)) {
621-
if (lib.isPre15Lib()) {
622-
compileLibrary(outputPath, folder, includePaths);
623-
} else {
624-
recursiveCompileLibrary(outputPath, folder, includePaths);
625-
}
626-
}
618+
compileLibrary(lib, includePaths);
627619
}
628620
}
629621

630-
private void recursiveCompileLibrary(File outputPath, File libraryFolder, List<String> includePaths) throws RunnerException {
631-
File newOutputPath = compileFilesInFolder(outputPath, libraryFolder, includePaths);
632-
for (File subFolder : libraryFolder.listFiles(new OnlyDirs())) {
633-
recursiveCompileLibrary(newOutputPath, subFolder, includePaths);
622+
private void compileLibrary(Library lib, List<String> includePaths)
623+
throws RunnerException {
624+
File libFolder = lib.getSrcFolder();
625+
File libBuildFolder = new File(prefs.get("build.path"), lib.getName());
626+
627+
if (lib.useRecursion()) {
628+
// libBuildFolder == {build.path}/LibName
629+
// libFolder == {lib.path}/src
630+
recursiveCompileFilesInFolder(libBuildFolder, libFolder, includePaths);
631+
632+
} else {
633+
// libFolder == {lib.path}/
634+
// utilityFolder == {lib.path}/utility
635+
// libBuildFolder == {build.path}/LibName
636+
// utilityBuildFolder == {build.path}/LibName/utility
637+
File utilityFolder = new File(libFolder, "utility");
638+
File utilityBuildFolder = new File(libBuildFolder, "utility");
639+
640+
includePaths.add(utilityFolder.getAbsolutePath());
641+
compileFilesInFolder(libBuildFolder, libFolder, includePaths);
642+
compileFilesInFolder(utilityBuildFolder, utilityFolder, includePaths);
643+
644+
// other libraries should not see this library's utility/ folder
645+
includePaths.remove(utilityFolder.getAbsolutePath());
634646
}
635647
}
636648

637-
private File compileFilesInFolder(File outputPath, File libraryFolder, List<String> includePaths) throws RunnerException {
638-
File outputFolder = new File(outputPath, libraryFolder.getName());
639-
createFolder(outputFolder);
640-
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(), libraryFolder, false, includePaths));
641-
return outputFolder;
649+
private void recursiveCompileFilesInFolder(File srcBuildFolder, File srcFolder, List<String> includePaths) throws RunnerException {
650+
compileFilesInFolder(srcBuildFolder, srcFolder, includePaths);
651+
for (File subFolder : srcFolder.listFiles(new OnlyDirs())) {
652+
File subBuildFolder = new File(srcBuildFolder, subFolder.getName());
653+
recursiveCompileFilesInFolder(subBuildFolder, subFolder, includePaths);
654+
}
642655
}
643656

644-
private void compileLibrary(File outputPath, File libraryFolder, List<String> includePaths) throws RunnerException {
645-
File outputFolder = new File(outputPath, libraryFolder.getName());
646-
File utilityFolder = new File(libraryFolder, "utility");
647-
createFolder(outputFolder);
648-
// this library can use includes in its utility/ folder
649-
includePaths.add(utilityFolder.getAbsolutePath());
650-
651-
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(),
652-
libraryFolder, false, includePaths));
653-
outputFolder = new File(outputFolder, "utility");
654-
createFolder(outputFolder);
655-
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(),
656-
utilityFolder, false, includePaths));
657-
// other libraries should not see this library's utility/ folder
658-
includePaths.remove(includePaths.size() - 1);
657+
private void compileFilesInFolder(File buildFolder, File srcFolder, List<String> includePaths) throws RunnerException {
658+
createFolder(buildFolder);
659+
List<File> objects = compileFiles(buildFolder.getAbsolutePath(), srcFolder, false, includePaths);
660+
objectFiles.addAll(objects);
659661
}
660662

661663
// 3. compile the core, outputting .o files to <buildPath> and then

app/src/processing/app/packages/Library.java

Lines changed: 64 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,23 @@ public class Library {
1717
private String name;
1818
private String version;
1919
private String author;
20-
private String email;
21-
private String url;
20+
private String maintainer;
2221
private String sentence;
2322
private String paragraph;
24-
private List<String> coreDependencies;
25-
private List<String> dependencies;
26-
private File folder, srcFolder, archFolder;
23+
private String url;
2724
private List<String> architectures;
28-
private boolean pre15Lib;
25+
private File folder;
26+
private File srcFolder;
27+
private boolean useRecursion;
28+
private boolean isLegacy;
2929

3030
private static final List<String> MANDATORY_PROPERTIES = Arrays
31-
.asList(new String[] { "architectures", "author", "core-dependencies",
32-
"dependencies", "email", "name", "paragraph", "sentence", "url",
33-
"version" });
31+
.asList(new String[] { "name", "version", "author", "maintainer",
32+
"sentence", "paragraph", "url" });
3433

3534
/**
3635
* Scans inside a folder and create a Library object out of it. Automatically
37-
* detects pre-1.5 libraries. Automatically fills metadata from
36+
* detects legacy libraries. Automatically fills metadata from
3837
* library.properties file if found.
3938
*
4039
* @param libFolder
@@ -45,7 +44,7 @@ static public Library create(File libFolder) throws IOException {
4544
// "library.properties"
4645
File check = new File(libFolder, "library.properties");
4746
if (!check.exists() || !check.isFile())
48-
return createPre15Library(libFolder);
47+
return createLegacyLibrary(libFolder);
4948
else
5049
return createLibrary(libFolder);
5150
}
@@ -60,14 +59,34 @@ private static Library createLibrary(File libFolder) throws IOException {
6059
// ---------------------
6160

6261
// 1. Check mandatory properties
62+
63+
// provide compatibility with 1.5 rev.1 libs
64+
// ("email" field changed to "maintainer")
65+
if (!properties.containsKey("maintainer"))
66+
properties.put("maintainer", properties.get("email"));
67+
6368
for (String p : MANDATORY_PROPERTIES)
6469
if (!properties.containsKey(p))
6570
throw new IOException("Missing '" + p + "' from library");
6671

67-
// 2. Check mandatory folders
72+
// 2. Check layout
73+
boolean useRecursion;
6874
File srcFolder = new File(libFolder, "src");
69-
if (!srcFolder.exists() || !srcFolder.isDirectory())
70-
throw new IOException("Missing 'src' folder");
75+
76+
if (srcFolder.exists() && srcFolder.isDirectory()) {
77+
// Layout with a single "src" folder and recursive compilation
78+
useRecursion = true;
79+
80+
File utilFolder = new File(libFolder, "utility");
81+
if (utilFolder.exists() && utilFolder.isDirectory()) {
82+
throw new IOException(
83+
"Library can't use both 'src' and 'utility' folders.");
84+
}
85+
} else {
86+
// Layout with source code on library's root and "utility" folders
87+
srcFolder = libFolder;
88+
useRecursion = false;
89+
}
7190

7291
// 3. Warn if root folder contains development leftovers
7392
for (File file : libFolder.listFiles()) {
@@ -81,65 +100,38 @@ private static Library createLibrary(File libFolder) throws IOException {
81100
}
82101

83102
// Extract metadata info
103+
String architectures = properties.get("architectures");
104+
if (architectures == null)
105+
architectures = "*"; // defaults to "any"
84106
List<String> archs = new ArrayList<String>();
85-
for (String arch : properties.get("architectures").split(","))
107+
for (String arch : architectures.split(","))
86108
archs.add(arch.trim());
87109

88-
List<String> coreDeps = new ArrayList<String>();
89-
for (String dep : properties.get("core-dependencies").split(","))
90-
coreDeps.add(dep.trim());
91-
92-
List<String> dependencies = new ArrayList<String>();
93-
for (String dependency : properties.get("dependencies").split(",")) {
94-
dependency = dependency.trim();
95-
if (!dependency.equals("")) {
96-
dependencies.add(dependency);
97-
}
98-
}
99-
100110
Library res = new Library();
101111
res.folder = libFolder;
102112
res.srcFolder = srcFolder;
103-
res.archFolder = new File(libFolder, "arch");
104113
res.name = properties.get("name").trim();
114+
res.version = properties.get("version").trim();
105115
res.author = properties.get("author").trim();
106-
res.email = properties.get("email").trim();
116+
res.maintainer = properties.get("maintainer").trim();
107117
res.sentence = properties.get("sentence").trim();
108118
res.paragraph = properties.get("paragraph").trim();
109119
res.url = properties.get("url").trim();
110120
res.architectures = archs;
111-
res.coreDependencies = coreDeps;
112-
res.dependencies = dependencies;
113-
res.version = properties.get("version").trim();
114-
res.pre15Lib = false;
121+
res.useRecursion = useRecursion;
122+
res.isLegacy = false;
115123
return res;
116124
}
117125

118-
private static Library createPre15Library(File libFolder) {
126+
private static Library createLegacyLibrary(File libFolder) {
119127
// construct an old style library
120128
Library res = new Library();
121129
res.folder = libFolder;
122130
res.srcFolder = libFolder;
131+
res.useRecursion = false;
123132
res.name = libFolder.getName();
124133
res.architectures = Arrays.asList("*");
125-
res.pre15Lib = true;
126-
return res;
127-
}
128-
129-
public List<File> getSrcFolders(String reqArch) {
130-
if (!supportsArchitecture(reqArch))
131-
return null;
132-
List<File> res = new ArrayList<File>();
133-
res.add(srcFolder);
134-
File archSpecificFolder = new File(archFolder, reqArch);
135-
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory()) {
136-
res.add(archSpecificFolder);
137-
} else {
138-
// If specific architecture folder is not found try with "default"
139-
archSpecificFolder = new File(archFolder, "default");
140-
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory())
141-
res.add(archSpecificFolder);
142-
}
134+
res.isLegacy = true;
143135
return res;
144136
}
145137

@@ -157,18 +149,10 @@ public int compare(Library o1, Library o2) {
157149
}
158150
};
159151

160-
public File getSrcFolder() {
161-
return srcFolder;
162-
}
163-
164152
public String getName() {
165153
return name;
166154
}
167155

168-
public boolean isPre15Lib() {
169-
return pre15Lib;
170-
}
171-
172156
public File getFolder() {
173157
return folder;
174158
}
@@ -181,18 +165,6 @@ public String getAuthor() {
181165
return author;
182166
}
183167

184-
public List<String> getCoreDependencies() {
185-
return coreDependencies;
186-
}
187-
188-
public List<String> getDependencies() {
189-
return dependencies;
190-
}
191-
192-
public String getEmail() {
193-
return email;
194-
}
195-
196168
public String getParagraph() {
197169
return paragraph;
198170
}
@@ -209,19 +181,33 @@ public String getVersion() {
209181
return version;
210182
}
211183

184+
public String getMaintainer() {
185+
return maintainer;
186+
}
187+
188+
public boolean useRecursion() {
189+
return useRecursion;
190+
}
191+
192+
public File getSrcFolder() {
193+
return srcFolder;
194+
}
195+
196+
public boolean isLegacy() {
197+
return isLegacy;
198+
}
199+
212200
@Override
213201
public String toString() {
214202
String res = "Library:";
215203
res += " (name=" + name + ")";
216-
res += " (architectures=" + architectures + ")";
204+
res += " (version=" + version + ")";
217205
res += " (author=" + author + ")";
218-
res += " (core-dependencies=" + coreDependencies + ")";
219-
res += " (dependencies=" + dependencies + ")";
220-
res += " (email=" + email + ")";
221-
res += " (paragraph=" + paragraph + ")";
206+
res += " (maintainer=" + maintainer + ")";
222207
res += " (sentence=" + sentence + ")";
208+
res += " (paragraph=" + paragraph + ")";
223209
res += " (url=" + url + ")";
224-
res += " (version=" + version + ")";
210+
res += " (architectures=" + architectures + ")";
225211
return res;
226212
}
227213
}

0 commit comments

Comments
 (0)