Skip to content

Commit bddb47e

Browse files
committed
Library class, round 2
1 parent 7aeb972 commit bddb47e

File tree

2 files changed

+122
-26
lines changed

2 files changed

+122
-26
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public class Compiler implements MessageConsumer {
5757
private PreferencesMap prefs;
5858
private boolean verbose;
5959
private boolean sketchIsCompiled;
60-
60+
private String targetArch;
61+
6162
private RunnerException exception;
6263

6364
/**
@@ -86,7 +87,8 @@ public boolean compile(Sketch _sketch, String _buildPath,
8687
if (prefs.get("build.variant.path").length() != 0)
8788
includePaths.add(prefs.get("build.variant.path"));
8889
for (Library lib : sketch.getImportedLibraries())
89-
includePaths.add(lib.getSrcFolder().getPath());
90+
for (File folder : lib.getSrcFolders(targetArch))
91+
includePaths.add(folder.getPath());
9092

9193
// 1. compile the sketch (already in the buildPath)
9294
sketch.setCompilingProgress(30);
@@ -131,7 +133,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
131133
}
132134

133135
TargetPlatform targetPlatform = Base.getTargetPlatform();
134-
136+
135137
// Merge all the global preference configuration in order of priority
136138
PreferencesMap p = new PreferencesMap();
137139
p.putAll(Preferences.getMap());
@@ -144,7 +146,8 @@ private PreferencesMap createBuildPreferences(String _buildPath,
144146

145147
p.put("build.path", _buildPath);
146148
p.put("build.project_name", _primaryClassName);
147-
p.put("build.arch", targetPlatform.getName().toUpperCase());
149+
targetArch = targetPlatform.getName();
150+
p.put("build.arch", targetArch.toUpperCase());
148151

149152
if (!p.containsKey("compiler.path"))
150153
p.put("compiler.path", Base.getAvrBasePath());
@@ -583,11 +586,12 @@ void compileSketch(List<String> includePaths) throws RunnerException {
583586
void compileLibraries(List<String> includePaths) throws RunnerException {
584587
File outputPath = new File(prefs.get("build.path"));
585588
for (Library lib : sketch.getImportedLibraries()) {
586-
File libFolder = lib.getSrcFolder();
587-
if (lib.isPre15Lib()) {
588-
compileLibrary(outputPath, libFolder, includePaths);
589-
} else {
590-
recursiveCompileLibrary(outputPath, libFolder, includePaths);
589+
for (File folder : lib.getSrcFolders(targetArch)) {
590+
if (lib.isPre15Lib()) {
591+
compileLibrary(outputPath, folder, includePaths);
592+
} else {
593+
recursiveCompileLibrary(outputPath, folder, includePaths);
594+
}
591595
}
592596
}
593597
}

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

Lines changed: 109 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,26 @@ public class Library {
1515

1616
private String name;
1717
private String version;
18-
private File folder, srcFolder;
18+
private String author;
19+
private String email;
20+
private String url;
21+
private String sentence;
22+
private String paragraph;
23+
private List<String> coreDependencies;
24+
private List<String> dependencies;
25+
private File folder, srcFolder, archFolder;
1926
private List<String> architectures;
2027
private boolean pre15Lib;
2128

29+
private static final List<String> MANDATORY_PROPERTIES = Arrays
30+
.asList(new String[] { "architectures", "author", "core-dependencies",
31+
"dependencies", "email", "name", "paragraph", "sentence", "url",
32+
"version" });
33+
private static final List<String> OPTIONAL_FOLDERS = Arrays
34+
.asList(new String[] { "arch", "examples", "extras", "src" });
35+
private static final List<String> OPTIONAL_FILES = Arrays
36+
.asList(new String[] { "keywords.txt", "library.properties" });
37+
2238
/**
2339
* Scans inside a folder and create a Library object out of it. Automatically
2440
* detects pre-1.5 libraries. Automatically fills metadata from
@@ -52,31 +68,49 @@ private static Library createLibrary(File libFolder) {
5268
// ---------------------
5369

5470
// 1. Check mandatory properties
55-
if (!properties.containsKey("name"))
56-
return null;
57-
if (!properties.containsKey("version"))
58-
return null;
59-
if (!properties.containsKey("architectures"))
60-
return null;
71+
for (String p : MANDATORY_PROPERTIES)
72+
if (!properties.containsKey(p))
73+
return null;
6174

6275
// 2. Check mandatory folders
6376
File srcFolder = new File(libFolder, "src");
6477
if (!srcFolder.exists() && !srcFolder.isDirectory())
6578
return null;
66-
67-
// TODO: 3. check if root folder contains prohibited stuff
68-
69-
// Extract metadata info
70-
// TODO: do for all metadata
71-
List<String> archs = new ArrayList<String>();
72-
for (String arch : properties.get("architectures").split(","))
73-
archs.add(arch.trim());
7479

80+
// 3. check if root folder contains prohibited stuff
81+
for (File file : libFolder.listFiles()) {
82+
if (file.isDirectory()) {
83+
if (!OPTIONAL_FOLDERS.contains(file.getName()))
84+
return null;
85+
} else {
86+
if (!OPTIONAL_FILES.contains(file.getName()))
87+
return null;
88+
}
89+
}
90+
91+
// Extract metadata info
7592
Library res = new Library();
7693
res.folder = libFolder;
7794
res.srcFolder = srcFolder;
95+
res.archFolder = new File(libFolder, "arch");
7896
res.name = properties.get("name").trim();
97+
res.author = properties.get("author").trim();
98+
res.email = properties.get("email").trim();
99+
res.sentence = properties.get("sentence").trim();
100+
res.paragraph = properties.get("paragraph").trim();
101+
res.url = properties.get("url").trim();
102+
List<String> archs = new ArrayList<String>();
103+
for (String arch : properties.get("architectures").split(","))
104+
archs.add(arch.trim());
79105
res.architectures = archs;
106+
List<String> deps = new ArrayList<String>();
107+
for (String dep : properties.get("dependencies").split(","))
108+
deps.add(dep.trim());
109+
res.dependencies = deps;
110+
List<String> coreDeps = new ArrayList<String>();
111+
for (String dep : properties.get("core-dependencies").split(","))
112+
coreDeps.add(dep.trim());
113+
res.coreDependencies = coreDeps;
80114
res.version = properties.get("version").trim();
81115
res.pre15Lib = false;
82116
return res;
@@ -98,9 +132,15 @@ public List<File> getSrcFolders(String reqArch) {
98132
return null;
99133
List<File> res = new ArrayList<File>();
100134
res.add(srcFolder);
101-
File archSpecificFolder = new File(srcFolder, reqArch);
102-
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory())
135+
File archSpecificFolder = new File(archFolder, reqArch);
136+
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory()) {
103137
res.add(archSpecificFolder);
138+
} else {
139+
// If specific architecture folder is not found try with "default"
140+
archSpecificFolder = new File(archFolder, "default");
141+
if (archSpecificFolder.exists() && archSpecificFolder.isDirectory())
142+
res.add(archSpecificFolder);
143+
}
104144
return res;
105145
}
106146

@@ -133,4 +173,56 @@ public boolean isPre15Lib() {
133173
public File getFolder() {
134174
return folder;
135175
}
176+
177+
public List<String> getArchitectures() {
178+
return architectures;
179+
}
180+
181+
public String getAuthor() {
182+
return author;
183+
}
184+
185+
public List<String> getCoreDependencies() {
186+
return coreDependencies;
187+
}
188+
189+
public List<String> getDependencies() {
190+
return dependencies;
191+
}
192+
193+
public String getEmail() {
194+
return email;
195+
}
196+
197+
public String getParagraph() {
198+
return paragraph;
199+
}
200+
201+
public String getSentence() {
202+
return sentence;
203+
}
204+
205+
public String getUrl() {
206+
return url;
207+
}
208+
209+
public String getVersion() {
210+
return version;
211+
}
212+
213+
@Override
214+
public String toString() {
215+
String res = "Library:";
216+
res += " (name=" + name + ")";
217+
res += " (architectures=" + architectures + ")";
218+
res += " (author=" + author + ")";
219+
res += " (core-dependencies=" + coreDependencies + ")";
220+
res += " (dependencies=" + dependencies + ")";
221+
res += " (email=" + email + ")";
222+
res += " (paragraph=" + paragraph + ")";
223+
res += " (sentence=" + sentence + ")";
224+
res += " (url=" + url + ")";
225+
res += " (version=" + version + ")";
226+
return res;
227+
}
136228
}

0 commit comments

Comments
 (0)