mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Library class, round 2
This commit is contained in:
@ -57,6 +57,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
private PreferencesMap prefs;
|
private PreferencesMap prefs;
|
||||||
private boolean verbose;
|
private boolean verbose;
|
||||||
private boolean sketchIsCompiled;
|
private boolean sketchIsCompiled;
|
||||||
|
private String targetArch;
|
||||||
|
|
||||||
private RunnerException exception;
|
private RunnerException exception;
|
||||||
|
|
||||||
@ -86,7 +87,8 @@ public class Compiler implements MessageConsumer {
|
|||||||
if (prefs.get("build.variant.path").length() != 0)
|
if (prefs.get("build.variant.path").length() != 0)
|
||||||
includePaths.add(prefs.get("build.variant.path"));
|
includePaths.add(prefs.get("build.variant.path"));
|
||||||
for (Library lib : sketch.getImportedLibraries())
|
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)
|
// 1. compile the sketch (already in the buildPath)
|
||||||
sketch.setCompilingProgress(30);
|
sketch.setCompilingProgress(30);
|
||||||
@ -144,7 +146,8 @@ public class Compiler implements MessageConsumer {
|
|||||||
|
|
||||||
p.put("build.path", _buildPath);
|
p.put("build.path", _buildPath);
|
||||||
p.put("build.project_name", _primaryClassName);
|
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"))
|
if (!p.containsKey("compiler.path"))
|
||||||
p.put("compiler.path", Base.getAvrBasePath());
|
p.put("compiler.path", Base.getAvrBasePath());
|
||||||
@ -583,11 +586,12 @@ public class Compiler implements MessageConsumer {
|
|||||||
void compileLibraries(List<String> includePaths) throws RunnerException {
|
void compileLibraries(List<String> includePaths) throws RunnerException {
|
||||||
File outputPath = new File(prefs.get("build.path"));
|
File outputPath = new File(prefs.get("build.path"));
|
||||||
for (Library lib : sketch.getImportedLibraries()) {
|
for (Library lib : sketch.getImportedLibraries()) {
|
||||||
File libFolder = lib.getSrcFolder();
|
for (File folder : lib.getSrcFolders(targetArch)) {
|
||||||
if (lib.isPre15Lib()) {
|
if (lib.isPre15Lib()) {
|
||||||
compileLibrary(outputPath, libFolder, includePaths);
|
compileLibrary(outputPath, folder, includePaths);
|
||||||
} else {
|
} else {
|
||||||
recursiveCompileLibrary(outputPath, libFolder, includePaths);
|
recursiveCompileLibrary(outputPath, folder, includePaths);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,26 @@ public class Library {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String version;
|
private String version;
|
||||||
private File folder, srcFolder;
|
private String author;
|
||||||
|
private String email;
|
||||||
|
private String url;
|
||||||
|
private String sentence;
|
||||||
|
private String paragraph;
|
||||||
|
private List<String> coreDependencies;
|
||||||
|
private List<String> dependencies;
|
||||||
|
private File folder, srcFolder, archFolder;
|
||||||
private List<String> architectures;
|
private List<String> architectures;
|
||||||
private boolean pre15Lib;
|
private boolean pre15Lib;
|
||||||
|
|
||||||
|
private static final List<String> MANDATORY_PROPERTIES = Arrays
|
||||||
|
.asList(new String[] { "architectures", "author", "core-dependencies",
|
||||||
|
"dependencies", "email", "name", "paragraph", "sentence", "url",
|
||||||
|
"version" });
|
||||||
|
private static final List<String> OPTIONAL_FOLDERS = Arrays
|
||||||
|
.asList(new String[] { "arch", "examples", "extras", "src" });
|
||||||
|
private static final List<String> OPTIONAL_FILES = Arrays
|
||||||
|
.asList(new String[] { "keywords.txt", "library.properties" });
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 pre-1.5 libraries. Automatically fills metadata from
|
||||||
@ -52,31 +68,49 @@ public class Library {
|
|||||||
// ---------------------
|
// ---------------------
|
||||||
|
|
||||||
// 1. Check mandatory properties
|
// 1. Check mandatory properties
|
||||||
if (!properties.containsKey("name"))
|
for (String p : MANDATORY_PROPERTIES)
|
||||||
return null;
|
if (!properties.containsKey(p))
|
||||||
if (!properties.containsKey("version"))
|
return null;
|
||||||
return null;
|
|
||||||
if (!properties.containsKey("architectures"))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
// 2. Check mandatory folders
|
// 2. Check mandatory folders
|
||||||
File srcFolder = new File(libFolder, "src");
|
File srcFolder = new File(libFolder, "src");
|
||||||
if (!srcFolder.exists() && !srcFolder.isDirectory())
|
if (!srcFolder.exists() && !srcFolder.isDirectory())
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// TODO: 3. check if root folder contains prohibited stuff
|
// 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
|
// Extract metadata info
|
||||||
// TODO: do for all metadata
|
|
||||||
List<String> archs = new ArrayList<String>();
|
|
||||||
for (String arch : properties.get("architectures").split(","))
|
|
||||||
archs.add(arch.trim());
|
|
||||||
|
|
||||||
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.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<String> archs = new ArrayList<String>();
|
||||||
|
for (String arch : properties.get("architectures").split(","))
|
||||||
|
archs.add(arch.trim());
|
||||||
res.architectures = archs;
|
res.architectures = archs;
|
||||||
|
List<String> deps = new ArrayList<String>();
|
||||||
|
for (String dep : properties.get("dependencies").split(","))
|
||||||
|
deps.add(dep.trim());
|
||||||
|
res.dependencies = deps;
|
||||||
|
List<String> coreDeps = new ArrayList<String>();
|
||||||
|
for (String dep : properties.get("core-dependencies").split(","))
|
||||||
|
coreDeps.add(dep.trim());
|
||||||
|
res.coreDependencies = coreDeps;
|
||||||
res.version = properties.get("version").trim();
|
res.version = properties.get("version").trim();
|
||||||
res.pre15Lib = false;
|
res.pre15Lib = false;
|
||||||
return res;
|
return res;
|
||||||
@ -98,9 +132,15 @@ public class Library {
|
|||||||
return null;
|
return null;
|
||||||
List<File> res = new ArrayList<File>();
|
List<File> res = new ArrayList<File>();
|
||||||
res.add(srcFolder);
|
res.add(srcFolder);
|
||||||
File archSpecificFolder = new File(srcFolder, reqArch);
|
File archSpecificFolder = new File(archFolder, reqArch);
|
||||||
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory())
|
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory()) {
|
||||||
res.add(archSpecificFolder);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,4 +173,56 @@ public class Library {
|
|||||||
public File getFolder() {
|
public File getFolder() {
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getArchitectures() {
|
||||||
|
return architectures;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getCoreDependencies() {
|
||||||
|
return coreDependencies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user