From e93760abc4fd1850d40c877ae05fcce693173e0c Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Tue, 24 Dec 2013 16:07:41 +0100 Subject: [PATCH] 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 --- app/src/processing/app/debug/Compiler.java | 72 ++++----- app/src/processing/app/packages/Library.java | 146 +++++++++---------- 2 files changed, 103 insertions(+), 115 deletions(-) diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 5bdb7d2e9..08926e435 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -96,9 +96,8 @@ public class Compiler implements MessageConsumer { if (verbose) System.out.println(I18n .format(_("Using library {0} in folder: {1} {2}"), lib.getName(), - lib.getFolder(), lib.isPre15Lib() ? "(pre-1.5)" : "")); - for (File folder : lib.getSrcFolders(targetArch)) - includePaths.add(folder.getPath()); + lib.getFolder(), lib.isLegacy() ? "(legacy)" : "")); + includePaths.add(lib.getSrcFolder().getPath()); } if (verbose) System.out.println(); @@ -615,47 +614,50 @@ public class Compiler implements MessageConsumer { // 2. compile the libraries, outputting .o files to: // // void compileLibraries(List includePaths) throws RunnerException { - File outputPath = new File(prefs.get("build.path")); for (Library lib : sketch.getImportedLibraries()) { - for (File folder : lib.getSrcFolders(targetArch)) { - if (lib.isPre15Lib()) { - compileLibrary(outputPath, folder, includePaths); - } else { - recursiveCompileLibrary(outputPath, folder, includePaths); - } - } + compileLibrary(lib, includePaths); } } - private void recursiveCompileLibrary(File outputPath, File libraryFolder, List includePaths) throws RunnerException { - File newOutputPath = compileFilesInFolder(outputPath, libraryFolder, includePaths); - for (File subFolder : libraryFolder.listFiles(new OnlyDirs())) { - recursiveCompileLibrary(newOutputPath, subFolder, includePaths); + private void compileLibrary(Library lib, List 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 { + // 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"); + + includePaths.add(utilityFolder.getAbsolutePath()); + compileFilesInFolder(libBuildFolder, libFolder, includePaths); + compileFilesInFolder(utilityBuildFolder, utilityFolder, includePaths); + + // other libraries should not see this library's utility/ folder + includePaths.remove(utilityFolder.getAbsolutePath()); } } - private File compileFilesInFolder(File outputPath, File libraryFolder, List includePaths) throws RunnerException { - File outputFolder = new File(outputPath, libraryFolder.getName()); - createFolder(outputFolder); - objectFiles.addAll(compileFiles(outputFolder.getAbsolutePath(), libraryFolder, false, includePaths)); - return outputFolder; + private void recursiveCompileFilesInFolder(File srcBuildFolder, File srcFolder, List 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 compileLibrary(File outputPath, File libraryFolder, List 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()); - - 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 - includePaths.remove(includePaths.size() - 1); + private void compileFilesInFolder(File buildFolder, File srcFolder, List includePaths) throws RunnerException { + createFolder(buildFolder); + List objects = compileFiles(buildFolder.getAbsolutePath(), srcFolder, false, includePaths); + objectFiles.addAll(objects); } // 3. compile the core, outputting .o files to and then diff --git a/app/src/processing/app/packages/Library.java b/app/src/processing/app/packages/Library.java index a6322ab44..9fc96720f 100644 --- a/app/src/processing/app/packages/Library.java +++ b/app/src/processing/app/packages/Library.java @@ -17,24 +17,23 @@ public class Library { private String name; private String version; private String author; - private String email; - private String url; + private String maintainer; private String sentence; private String paragraph; - private List coreDependencies; - private List dependencies; - private File folder, srcFolder, archFolder; + private String url; private List architectures; - private boolean pre15Lib; + private File folder; + private File srcFolder; + private boolean useRecursion; + private boolean isLegacy; private static final List MANDATORY_PROPERTIES = Arrays - .asList(new String[] { "architectures", "author", "core-dependencies", - "dependencies", "email", "name", "paragraph", "sentence", "url", - "version" }); + .asList(new String[] { "name", "version", "author", "maintainer", + "sentence", "paragraph", "url" }); /** * 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. * * @param libFolder @@ -45,7 +44,7 @@ public class Library { // "library.properties" File check = new File(libFolder, "library.properties"); if (!check.exists() || !check.isFile()) - return createPre15Library(libFolder); + return createLegacyLibrary(libFolder); else return createLibrary(libFolder); } @@ -60,14 +59,34 @@ public class Library { // --------------------- // 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) if (!properties.containsKey(p)) throw new IOException("Missing '" + p + "' from library"); - // 2. Check mandatory folders + // 2. Check layout + boolean useRecursion; 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 for (File file : libFolder.listFiles()) { @@ -81,65 +100,38 @@ public class Library { } // Extract metadata info + String architectures = properties.get("architectures"); + if (architectures == null) + architectures = "*"; // defaults to "any" List archs = new ArrayList(); - for (String arch : properties.get("architectures").split(",")) + for (String arch : architectures.split(",")) archs.add(arch.trim()); - List coreDeps = new ArrayList(); - for (String dep : properties.get("core-dependencies").split(",")) - coreDeps.add(dep.trim()); - - List dependencies = new ArrayList(); - for (String dependency : properties.get("dependencies").split(",")) { - dependency = dependency.trim(); - if (!dependency.equals("")) { - dependencies.add(dependency); - } - } - Library res = new Library(); res.folder = libFolder; res.srcFolder = srcFolder; - res.archFolder = new File(libFolder, "arch"); res.name = properties.get("name").trim(); + res.version = properties.get("version").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.paragraph = properties.get("paragraph").trim(); res.url = properties.get("url").trim(); res.architectures = archs; - res.coreDependencies = coreDeps; - res.dependencies = dependencies; - res.version = properties.get("version").trim(); - res.pre15Lib = false; + res.useRecursion = useRecursion; + res.isLegacy = false; return res; } - private static Library createPre15Library(File libFolder) { + private static Library createLegacyLibrary(File libFolder) { // construct an old style library Library res = new Library(); res.folder = libFolder; res.srcFolder = libFolder; + res.useRecursion = false; res.name = libFolder.getName(); res.architectures = Arrays.asList("*"); - res.pre15Lib = true; - return res; - } - - public List getSrcFolders(String reqArch) { - if (!supportsArchitecture(reqArch)) - return null; - List res = new ArrayList(); - 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); - } + res.isLegacy = true; return res; } @@ -157,18 +149,10 @@ public class Library { } }; - public File getSrcFolder() { - return srcFolder; - } - public String getName() { return name; } - public boolean isPre15Lib() { - return pre15Lib; - } - public File getFolder() { return folder; } @@ -181,18 +165,6 @@ public class Library { return author; } - public List getCoreDependencies() { - return coreDependencies; - } - - public List getDependencies() { - return dependencies; - } - - public String getEmail() { - return email; - } - public String getParagraph() { return paragraph; } @@ -209,19 +181,33 @@ public class Library { return version; } + public String getMaintainer() { + return maintainer; + } + + public boolean useRecursion() { + return useRecursion; + } + + public File getSrcFolder() { + return srcFolder; + } + + public boolean isLegacy() { + return isLegacy; + } + @Override public String toString() { String res = "Library:"; 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 += " (author=" + author + ")"; + res += " (maintainer=" + maintainer + ")"; + res += " (sentence=" + sentence + ")"; + res += " (paragraph=" + paragraph + ")"; + res += " (url=" + url + ")"; + res += " (architectures=" + architectures + ")"; return res; } }