Skip to content

Commit 5672402

Browse files
committed
Added compatibity for 1.5 libraries layout on IDE 1.0.x
See #1765
1 parent 9810e89 commit 5672402

File tree

2 files changed

+61
-10
lines changed

2 files changed

+61
-10
lines changed

app/src/processing/app/Sketch.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,11 @@
3333
import static processing.app.I18n._;
3434

3535
import java.awt.*;
36-
import java.awt.event.*;
37-
import java.beans.*;
3836
import java.io.*;
3937
import java.util.*;
4038
import java.util.List;
41-
import java.util.zip.*;
4239

4340
import javax.swing.*;
44-
import javax.swing.border.EmptyBorder;
45-
import javax.swing.border.TitledBorder;
4641

4742

4843
/**

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

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import processing.app.SketchCode;
3030
import processing.core.*;
3131
import processing.app.I18n;
32+
import processing.app.helpers.filefilters.OnlyDirs;
3233
import static processing.app.I18n._;
3334

3435
import java.io.*;
@@ -119,8 +120,14 @@ public boolean compile(Sketch sketch,
119120
List includePaths = new ArrayList();
120121
includePaths.add(corePath);
121122
if (variantPath != null) includePaths.add(variantPath);
122-
for (File file : sketch.getImportedLibraries()) {
123-
includePaths.add(file.getPath());
123+
for (File libFolder : sketch.getImportedLibraries()) {
124+
// Forward compatibility with 1.5 library format
125+
File propertiesFile = new File(libFolder, "library.properties");
126+
File srcFolder = new File(libFolder, "src");
127+
if (propertiesFile.isFile() && srcFolder.isDirectory())
128+
includePaths.add(srcFolder.getPath());
129+
else
130+
includePaths.add(libFolder.getPath());
124131
}
125132

126133
// 1. compile the sketch (already in the buildPath)
@@ -139,8 +146,26 @@ public boolean compile(Sketch sketch,
139146
sketch.setCompilingProgress(40);
140147
for (File libraryFolder : sketch.getImportedLibraries()) {
141148
File outputFolder = new File(buildPath, libraryFolder.getName());
142-
File utilityFolder = new File(libraryFolder, "utility");
143149
createFolder(outputFolder);
150+
151+
// Forward compatibility with 1.5 library format
152+
File propertiesFile = new File(libraryFolder, "library.properties");
153+
File srcFolder = new File(libraryFolder, "src");
154+
if (propertiesFile.exists() && srcFolder.isDirectory()) {
155+
// Is an 1.5 library with "src" folder layout
156+
includePaths.add(srcFolder.getAbsolutePath());
157+
158+
// Recursively compile "src" folder
159+
objectFiles.addAll(recursiveCompile(avrBasePath, srcFolder,
160+
outputFolder, includePaths, boardPreferences));
161+
162+
includePaths.remove(includePaths.size() - 1);
163+
continue;
164+
}
165+
166+
// Otherwise fallback to 1.0 library layout...
167+
168+
File utilityFolder = new File(libraryFolder, "utility");
144169
// this library can use includes in its utility/ folder
145170
includePaths.add(utilityFolder.getAbsolutePath());
146171
objectFiles.addAll(
@@ -251,6 +276,26 @@ public boolean compile(Sketch sketch,
251276
return true;
252277
}
253278

279+
private List<File> recursiveCompile(String avrBasePath, File srcFolder,
280+
File outputFolder, List<File> includePaths,
281+
Map<String, String> boardPreferences) throws RunnerException {
282+
List<File> objectFiles = new ArrayList<File>();
283+
objectFiles.addAll(compileFiles(avrBasePath, outputFolder.getAbsolutePath(), includePaths,
284+
findFilesInFolder(srcFolder, "S", false),
285+
findFilesInFolder(srcFolder, "c", false),
286+
findFilesInFolder(srcFolder, "cpp", false),
287+
boardPreferences));
288+
289+
// Recursively compile sub-folders
290+
for (File srcSubfolder : srcFolder.listFiles(new OnlyDirs())) {
291+
File outputSubfolder = new File(outputFolder, srcSubfolder.getName());
292+
createFolder(outputSubfolder);
293+
objectFiles.addAll(recursiveCompile(avrBasePath, srcSubfolder,
294+
outputSubfolder, includePaths, boardPreferences));
295+
}
296+
297+
return objectFiles;
298+
}
254299

255300
private List<File> compileFiles(String avrBasePath,
256301
String buildPath, List<File> includePaths,
@@ -662,8 +707,19 @@ public boolean accept(File dir, String name) {
662707
return name.endsWith(".h");
663708
}
664709
};
665-
666-
String[] list = (new File(path)).list(onlyHFiles);
710+
File libFolder = new File(path);
711+
712+
// Forward compatibility with 1.5 library format
713+
File propertiesFile = new File(libFolder, "library.properties");
714+
File srcFolder = new File(libFolder, "src");
715+
String[] list;
716+
if (propertiesFile.isFile() && srcFolder.isDirectory()) {
717+
// Is an 1.5 library with "src" folder
718+
list = srcFolder.list(onlyHFiles);
719+
} else {
720+
// Fallback to 1.0 library layout
721+
list = libFolder.list(onlyHFiles);
722+
}
667723
if (list == null) {
668724
throw new IOException();
669725
}

0 commit comments

Comments
 (0)