mirror of https://github.com/noisymime/Arduino.git
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
This commit is contained in:
parent
660c7d86fd
commit
e93760abc4
|
@ -96,9 +96,8 @@ public class Compiler implements MessageConsumer {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.out.println(I18n
|
System.out.println(I18n
|
||||||
.format(_("Using library {0} in folder: {1} {2}"), lib.getName(),
|
.format(_("Using library {0} in folder: {1} {2}"), lib.getName(),
|
||||||
lib.getFolder(), lib.isPre15Lib() ? "(pre-1.5)" : ""));
|
lib.getFolder(), lib.isLegacy() ? "(legacy)" : ""));
|
||||||
for (File folder : lib.getSrcFolders(targetArch))
|
includePaths.add(lib.getSrcFolder().getPath());
|
||||||
includePaths.add(folder.getPath());
|
|
||||||
}
|
}
|
||||||
if (verbose)
|
if (verbose)
|
||||||
System.out.println();
|
System.out.println();
|
||||||
|
@ -615,47 +614,50 @@ public class Compiler implements MessageConsumer {
|
||||||
// 2. compile the libraries, outputting .o files to:
|
// 2. compile the libraries, outputting .o files to:
|
||||||
// <buildPath>/<library>/
|
// <buildPath>/<library>/
|
||||||
void compileLibraries(List<String> includePaths) throws RunnerException {
|
void compileLibraries(List<String> includePaths) throws RunnerException {
|
||||||
File outputPath = new File(prefs.get("build.path"));
|
|
||||||
for (Library lib : sketch.getImportedLibraries()) {
|
for (Library lib : sketch.getImportedLibraries()) {
|
||||||
for (File folder : lib.getSrcFolders(targetArch)) {
|
compileLibrary(lib, includePaths);
|
||||||
if (lib.isPre15Lib()) {
|
}
|
||||||
compileLibrary(outputPath, folder, includePaths);
|
}
|
||||||
|
|
||||||
|
private void compileLibrary(Library lib, List<String> includePaths)
|
||||||
|
throws RunnerException {
|
||||||
|
File libFolder = lib.getSrcFolder();
|
||||||
|
File libBuildFolder = new File(prefs.get("build.path"), lib.getName());
|
||||||
|
|
||||||
|
if (lib.useRecursion()) {
|
||||||
|
// libBuildFolder == {build.path}/LibName
|
||||||
|
// libFolder == {lib.path}/src
|
||||||
|
recursiveCompileFilesInFolder(libBuildFolder, libFolder, includePaths);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
recursiveCompileLibrary(outputPath, folder, includePaths);
|
// libFolder == {lib.path}/
|
||||||
}
|
// utilityFolder == {lib.path}/utility
|
||||||
}
|
// libBuildFolder == {build.path}/LibName
|
||||||
}
|
// utilityBuildFolder == {build.path}/LibName/utility
|
||||||
}
|
File utilityFolder = new File(libFolder, "utility");
|
||||||
|
File utilityBuildFolder = new File(libBuildFolder, "utility");
|
||||||
|
|
||||||
private void recursiveCompileLibrary(File outputPath, File libraryFolder, List<String> includePaths) throws RunnerException {
|
|
||||||
File newOutputPath = compileFilesInFolder(outputPath, libraryFolder, includePaths);
|
|
||||||
for (File subFolder : libraryFolder.listFiles(new OnlyDirs())) {
|
|
||||||
recursiveCompileLibrary(newOutputPath, subFolder, includePaths);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private File compileFilesInFolder(File outputPath, File libraryFolder, List<String> includePaths) throws RunnerException {
|
|
||||||
File outputFolder = new File(outputPath, libraryFolder.getName());
|
|
||||||
createFolder(outputFolder);
|
|
||||||
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(), libraryFolder, false, includePaths));
|
|
||||||
return outputFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void compileLibrary(File outputPath, File libraryFolder, List<String> includePaths) throws RunnerException {
|
|
||||||
File outputFolder = new File(outputPath, libraryFolder.getName());
|
|
||||||
File utilityFolder = new File(libraryFolder, "utility");
|
|
||||||
createFolder(outputFolder);
|
|
||||||
// this library can use includes in its utility/ folder
|
|
||||||
includePaths.add(utilityFolder.getAbsolutePath());
|
includePaths.add(utilityFolder.getAbsolutePath());
|
||||||
|
compileFilesInFolder(libBuildFolder, libFolder, includePaths);
|
||||||
|
compileFilesInFolder(utilityBuildFolder, utilityFolder, includePaths);
|
||||||
|
|
||||||
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(),
|
|
||||||
libraryFolder, false, includePaths));
|
|
||||||
outputFolder = new File(outputFolder, "utility");
|
|
||||||
createFolder(outputFolder);
|
|
||||||
objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(),
|
|
||||||
utilityFolder, false, includePaths));
|
|
||||||
// other libraries should not see this library's utility/ folder
|
// other libraries should not see this library's utility/ folder
|
||||||
includePaths.remove(includePaths.size() - 1);
|
includePaths.remove(utilityFolder.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void recursiveCompileFilesInFolder(File srcBuildFolder, File srcFolder, List<String> includePaths) throws RunnerException {
|
||||||
|
compileFilesInFolder(srcBuildFolder, srcFolder, includePaths);
|
||||||
|
for (File subFolder : srcFolder.listFiles(new OnlyDirs())) {
|
||||||
|
File subBuildFolder = new File(srcBuildFolder, subFolder.getName());
|
||||||
|
recursiveCompileFilesInFolder(subBuildFolder, subFolder, includePaths);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void compileFilesInFolder(File buildFolder, File srcFolder, List<String> includePaths) throws RunnerException {
|
||||||
|
createFolder(buildFolder);
|
||||||
|
List<File> objects = compileFiles(buildFolder.getAbsolutePath(), srcFolder, false, includePaths);
|
||||||
|
objectFiles.addAll(objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. compile the core, outputting .o files to <buildPath> and then
|
// 3. compile the core, outputting .o files to <buildPath> and then
|
||||||
|
|
|
@ -17,24 +17,23 @@ public class Library {
|
||||||
private String name;
|
private String name;
|
||||||
private String version;
|
private String version;
|
||||||
private String author;
|
private String author;
|
||||||
private String email;
|
private String maintainer;
|
||||||
private String url;
|
|
||||||
private String sentence;
|
private String sentence;
|
||||||
private String paragraph;
|
private String paragraph;
|
||||||
private List<String> coreDependencies;
|
private String url;
|
||||||
private List<String> dependencies;
|
|
||||||
private File folder, srcFolder, archFolder;
|
|
||||||
private List<String> architectures;
|
private List<String> architectures;
|
||||||
private boolean pre15Lib;
|
private File folder;
|
||||||
|
private File srcFolder;
|
||||||
|
private boolean useRecursion;
|
||||||
|
private boolean isLegacy;
|
||||||
|
|
||||||
private static final List<String> MANDATORY_PROPERTIES = Arrays
|
private static final List<String> MANDATORY_PROPERTIES = Arrays
|
||||||
.asList(new String[] { "architectures", "author", "core-dependencies",
|
.asList(new String[] { "name", "version", "author", "maintainer",
|
||||||
"dependencies", "email", "name", "paragraph", "sentence", "url",
|
"sentence", "paragraph", "url" });
|
||||||
"version" });
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scans inside a folder and create a Library object out of it. Automatically
|
* Scans inside a folder and create a Library object out of it. Automatically
|
||||||
* detects pre-1.5 libraries. Automatically fills metadata from
|
* detects legacy libraries. Automatically fills metadata from
|
||||||
* library.properties file if found.
|
* library.properties file if found.
|
||||||
*
|
*
|
||||||
* @param libFolder
|
* @param libFolder
|
||||||
|
@ -45,7 +44,7 @@ public class Library {
|
||||||
// "library.properties"
|
// "library.properties"
|
||||||
File check = new File(libFolder, "library.properties");
|
File check = new File(libFolder, "library.properties");
|
||||||
if (!check.exists() || !check.isFile())
|
if (!check.exists() || !check.isFile())
|
||||||
return createPre15Library(libFolder);
|
return createLegacyLibrary(libFolder);
|
||||||
else
|
else
|
||||||
return createLibrary(libFolder);
|
return createLibrary(libFolder);
|
||||||
}
|
}
|
||||||
|
@ -60,14 +59,34 @@ public class Library {
|
||||||
// ---------------------
|
// ---------------------
|
||||||
|
|
||||||
// 1. Check mandatory properties
|
// 1. Check mandatory properties
|
||||||
|
|
||||||
|
// provide compatibility with 1.5 rev.1 libs
|
||||||
|
// ("email" field changed to "maintainer")
|
||||||
|
if (!properties.containsKey("maintainer"))
|
||||||
|
properties.put("maintainer", properties.get("email"));
|
||||||
|
|
||||||
for (String p : MANDATORY_PROPERTIES)
|
for (String p : MANDATORY_PROPERTIES)
|
||||||
if (!properties.containsKey(p))
|
if (!properties.containsKey(p))
|
||||||
throw new IOException("Missing '" + p + "' from library");
|
throw new IOException("Missing '" + p + "' from library");
|
||||||
|
|
||||||
// 2. Check mandatory folders
|
// 2. Check layout
|
||||||
|
boolean useRecursion;
|
||||||
File srcFolder = new File(libFolder, "src");
|
File srcFolder = new File(libFolder, "src");
|
||||||
if (!srcFolder.exists() || !srcFolder.isDirectory())
|
|
||||||
throw new IOException("Missing 'src' folder");
|
if (srcFolder.exists() && srcFolder.isDirectory()) {
|
||||||
|
// Layout with a single "src" folder and recursive compilation
|
||||||
|
useRecursion = true;
|
||||||
|
|
||||||
|
File utilFolder = new File(libFolder, "utility");
|
||||||
|
if (utilFolder.exists() && utilFolder.isDirectory()) {
|
||||||
|
throw new IOException(
|
||||||
|
"Library can't use both 'src' and 'utility' folders.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Layout with source code on library's root and "utility" folders
|
||||||
|
srcFolder = libFolder;
|
||||||
|
useRecursion = false;
|
||||||
|
}
|
||||||
|
|
||||||
// 3. Warn if root folder contains development leftovers
|
// 3. Warn if root folder contains development leftovers
|
||||||
for (File file : libFolder.listFiles()) {
|
for (File file : libFolder.listFiles()) {
|
||||||
|
@ -81,65 +100,38 @@ public class Library {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract metadata info
|
// Extract metadata info
|
||||||
|
String architectures = properties.get("architectures");
|
||||||
|
if (architectures == null)
|
||||||
|
architectures = "*"; // defaults to "any"
|
||||||
List<String> archs = new ArrayList<String>();
|
List<String> archs = new ArrayList<String>();
|
||||||
for (String arch : properties.get("architectures").split(","))
|
for (String arch : architectures.split(","))
|
||||||
archs.add(arch.trim());
|
archs.add(arch.trim());
|
||||||
|
|
||||||
List<String> coreDeps = new ArrayList<String>();
|
|
||||||
for (String dep : properties.get("core-dependencies").split(","))
|
|
||||||
coreDeps.add(dep.trim());
|
|
||||||
|
|
||||||
List<String> dependencies = new ArrayList<String>();
|
|
||||||
for (String dependency : properties.get("dependencies").split(",")) {
|
|
||||||
dependency = dependency.trim();
|
|
||||||
if (!dependency.equals("")) {
|
|
||||||
dependencies.add(dependency);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Library res = new Library();
|
Library res = new Library();
|
||||||
res.folder = libFolder;
|
res.folder = libFolder;
|
||||||
res.srcFolder = srcFolder;
|
res.srcFolder = srcFolder;
|
||||||
res.archFolder = new File(libFolder, "arch");
|
|
||||||
res.name = properties.get("name").trim();
|
res.name = properties.get("name").trim();
|
||||||
|
res.version = properties.get("version").trim();
|
||||||
res.author = properties.get("author").trim();
|
res.author = properties.get("author").trim();
|
||||||
res.email = properties.get("email").trim();
|
res.maintainer = properties.get("maintainer").trim();
|
||||||
res.sentence = properties.get("sentence").trim();
|
res.sentence = properties.get("sentence").trim();
|
||||||
res.paragraph = properties.get("paragraph").trim();
|
res.paragraph = properties.get("paragraph").trim();
|
||||||
res.url = properties.get("url").trim();
|
res.url = properties.get("url").trim();
|
||||||
res.architectures = archs;
|
res.architectures = archs;
|
||||||
res.coreDependencies = coreDeps;
|
res.useRecursion = useRecursion;
|
||||||
res.dependencies = dependencies;
|
res.isLegacy = false;
|
||||||
res.version = properties.get("version").trim();
|
|
||||||
res.pre15Lib = false;
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Library createPre15Library(File libFolder) {
|
private static Library createLegacyLibrary(File libFolder) {
|
||||||
// construct an old style library
|
// construct an old style library
|
||||||
Library res = new Library();
|
Library res = new Library();
|
||||||
res.folder = libFolder;
|
res.folder = libFolder;
|
||||||
res.srcFolder = libFolder;
|
res.srcFolder = libFolder;
|
||||||
|
res.useRecursion = false;
|
||||||
res.name = libFolder.getName();
|
res.name = libFolder.getName();
|
||||||
res.architectures = Arrays.asList("*");
|
res.architectures = Arrays.asList("*");
|
||||||
res.pre15Lib = true;
|
res.isLegacy = true;
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<File> getSrcFolders(String reqArch) {
|
|
||||||
if (!supportsArchitecture(reqArch))
|
|
||||||
return null;
|
|
||||||
List<File> res = new ArrayList<File>();
|
|
||||||
res.add(srcFolder);
|
|
||||||
File archSpecificFolder = new File(archFolder, reqArch);
|
|
||||||
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory()) {
|
|
||||||
res.add(archSpecificFolder);
|
|
||||||
} else {
|
|
||||||
// If specific architecture folder is not found try with "default"
|
|
||||||
archSpecificFolder = new File(archFolder, "default");
|
|
||||||
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory())
|
|
||||||
res.add(archSpecificFolder);
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,18 +149,10 @@ public class Library {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public File getSrcFolder() {
|
|
||||||
return srcFolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPre15Lib() {
|
|
||||||
return pre15Lib;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getFolder() {
|
public File getFolder() {
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
@ -181,18 +165,6 @@ public class Library {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getCoreDependencies() {
|
|
||||||
return coreDependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getDependencies() {
|
|
||||||
return dependencies;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getParagraph() {
|
public String getParagraph() {
|
||||||
return paragraph;
|
return paragraph;
|
||||||
}
|
}
|
||||||
|
@ -209,19 +181,33 @@ public class Library {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMaintainer() {
|
||||||
|
return maintainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean useRecursion() {
|
||||||
|
return useRecursion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getSrcFolder() {
|
||||||
|
return srcFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLegacy() {
|
||||||
|
return isLegacy;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String res = "Library:";
|
String res = "Library:";
|
||||||
res += " (name=" + name + ")";
|
res += " (name=" + name + ")";
|
||||||
res += " (architectures=" + architectures + ")";
|
|
||||||
res += " (author=" + author + ")";
|
|
||||||
res += " (core-dependencies=" + coreDependencies + ")";
|
|
||||||
res += " (dependencies=" + dependencies + ")";
|
|
||||||
res += " (email=" + email + ")";
|
|
||||||
res += " (paragraph=" + paragraph + ")";
|
|
||||||
res += " (sentence=" + sentence + ")";
|
|
||||||
res += " (url=" + url + ")";
|
|
||||||
res += " (version=" + version + ")";
|
res += " (version=" + version + ")";
|
||||||
|
res += " (author=" + author + ")";
|
||||||
|
res += " (maintainer=" + maintainer + ")";
|
||||||
|
res += " (sentence=" + sentence + ")";
|
||||||
|
res += " (paragraph=" + paragraph + ")";
|
||||||
|
res += " (url=" + url + ")";
|
||||||
|
res += " (architectures=" + architectures + ")";
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue