diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 119c846a9..80cbe9ed6 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -57,7 +57,8 @@ public class Compiler implements MessageConsumer { private PreferencesMap prefs; private boolean verbose; private boolean sketchIsCompiled; - + private String targetArch; + private RunnerException exception; /** @@ -86,7 +87,8 @@ public class Compiler implements MessageConsumer { if (prefs.get("build.variant.path").length() != 0) includePaths.add(prefs.get("build.variant.path")); for (Library lib : sketch.getImportedLibraries()) - includePaths.add(lib.getSrcFolder().getPath()); + for (File folder : lib.getSrcFolders(targetArch)) + includePaths.add(folder.getPath()); // 1. compile the sketch (already in the buildPath) sketch.setCompilingProgress(30); @@ -131,7 +133,7 @@ public class Compiler implements MessageConsumer { } TargetPlatform targetPlatform = Base.getTargetPlatform(); - + // Merge all the global preference configuration in order of priority PreferencesMap p = new PreferencesMap(); p.putAll(Preferences.getMap()); @@ -144,7 +146,8 @@ public class Compiler implements MessageConsumer { p.put("build.path", _buildPath); p.put("build.project_name", _primaryClassName); - p.put("build.arch", targetPlatform.getName().toUpperCase()); + targetArch = targetPlatform.getName(); + p.put("build.arch", targetArch.toUpperCase()); if (!p.containsKey("compiler.path")) p.put("compiler.path", Base.getAvrBasePath()); @@ -583,11 +586,12 @@ public class Compiler implements MessageConsumer { void compileLibraries(List includePaths) throws RunnerException { File outputPath = new File(prefs.get("build.path")); for (Library lib : sketch.getImportedLibraries()) { - File libFolder = lib.getSrcFolder(); - if (lib.isPre15Lib()) { - compileLibrary(outputPath, libFolder, includePaths); - } else { - recursiveCompileLibrary(outputPath, libFolder, includePaths); + for (File folder : lib.getSrcFolders(targetArch)) { + if (lib.isPre15Lib()) { + compileLibrary(outputPath, folder, includePaths); + } else { + recursiveCompileLibrary(outputPath, folder, includePaths); + } } } } diff --git a/app/src/processing/app/packages/Library.java b/app/src/processing/app/packages/Library.java index f795a1f8b..a01200f7c 100644 --- a/app/src/processing/app/packages/Library.java +++ b/app/src/processing/app/packages/Library.java @@ -15,10 +15,26 @@ public class Library { private String name; private String version; - private File folder, srcFolder; + private String author; + private String email; + private String url; + private String sentence; + private String paragraph; + private List coreDependencies; + private List dependencies; + private File folder, srcFolder, archFolder; private List architectures; private boolean pre15Lib; + private static final List MANDATORY_PROPERTIES = Arrays + .asList(new String[] { "architectures", "author", "core-dependencies", + "dependencies", "email", "name", "paragraph", "sentence", "url", + "version" }); + private static final List OPTIONAL_FOLDERS = Arrays + .asList(new String[] { "arch", "examples", "extras", "src" }); + private static final List OPTIONAL_FILES = Arrays + .asList(new String[] { "keywords.txt", "library.properties" }); + /** * Scans inside a folder and create a Library object out of it. Automatically * detects pre-1.5 libraries. Automatically fills metadata from @@ -52,31 +68,49 @@ public class Library { // --------------------- // 1. Check mandatory properties - if (!properties.containsKey("name")) - return null; - if (!properties.containsKey("version")) - return null; - if (!properties.containsKey("architectures")) - return null; + for (String p : MANDATORY_PROPERTIES) + if (!properties.containsKey(p)) + return null; // 2. Check mandatory folders File srcFolder = new File(libFolder, "src"); if (!srcFolder.exists() && !srcFolder.isDirectory()) return null; - - // TODO: 3. check if root folder contains prohibited stuff - - // Extract metadata info - // TODO: do for all metadata - List archs = new ArrayList(); - for (String arch : properties.get("architectures").split(",")) - archs.add(arch.trim()); + // 3. check if root folder contains prohibited stuff + for (File file : libFolder.listFiles()) { + if (file.isDirectory()) { + if (!OPTIONAL_FOLDERS.contains(file.getName())) + return null; + } else { + if (!OPTIONAL_FILES.contains(file.getName())) + return null; + } + } + + // Extract metadata info Library res = new Library(); res.folder = libFolder; res.srcFolder = srcFolder; + res.archFolder = new File(libFolder, "arch"); res.name = properties.get("name").trim(); + res.author = properties.get("author").trim(); + res.email = properties.get("email").trim(); + res.sentence = properties.get("sentence").trim(); + res.paragraph = properties.get("paragraph").trim(); + res.url = properties.get("url").trim(); + List archs = new ArrayList(); + for (String arch : properties.get("architectures").split(",")) + archs.add(arch.trim()); res.architectures = archs; + List deps = new ArrayList(); + for (String dep : properties.get("dependencies").split(",")) + deps.add(dep.trim()); + res.dependencies = deps; + List coreDeps = new ArrayList(); + for (String dep : properties.get("core-dependencies").split(",")) + coreDeps.add(dep.trim()); + res.coreDependencies = coreDeps; res.version = properties.get("version").trim(); res.pre15Lib = false; return res; @@ -98,9 +132,15 @@ public class Library { return null; List res = new ArrayList(); res.add(srcFolder); - File archSpecificFolder = new File(srcFolder, reqArch); - if (archSpecificFolder.exists() && archSpecificFolder.isDirectory()) + 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; } @@ -133,4 +173,56 @@ public class Library { public File getFolder() { return folder; } + + public List getArchitectures() { + return architectures; + } + + public String getAuthor() { + return author; + } + + public List getCoreDependencies() { + return coreDependencies; + } + + public List getDependencies() { + return dependencies; + } + + public String getEmail() { + return email; + } + + public String getParagraph() { + return paragraph; + } + + public String getSentence() { + return sentence; + } + + public String getUrl() { + return url; + } + + public String getVersion() { + return version; + } + + @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 + ")"; + return res; + } }