29
29
import processing .app .SketchCode ;
30
30
import processing .core .*;
31
31
import processing .app .I18n ;
32
+ import processing .app .helpers .filefilters .OnlyDirs ;
32
33
import static processing .app .I18n ._ ;
33
34
34
35
import java .io .*;
@@ -119,8 +120,14 @@ public boolean compile(Sketch sketch,
119
120
List includePaths = new ArrayList ();
120
121
includePaths .add (corePath );
121
122
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 ());
124
131
}
125
132
126
133
// 1. compile the sketch (already in the buildPath)
@@ -139,8 +146,26 @@ public boolean compile(Sketch sketch,
139
146
sketch .setCompilingProgress (40 );
140
147
for (File libraryFolder : sketch .getImportedLibraries ()) {
141
148
File outputFolder = new File (buildPath , libraryFolder .getName ());
142
- File utilityFolder = new File (libraryFolder , "utility" );
143
149
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" );
144
169
// this library can use includes in its utility/ folder
145
170
includePaths .add (utilityFolder .getAbsolutePath ());
146
171
objectFiles .addAll (
@@ -251,6 +276,26 @@ public boolean compile(Sketch sketch,
251
276
return true ;
252
277
}
253
278
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
+ }
254
299
255
300
private List <File > compileFiles (String avrBasePath ,
256
301
String buildPath , List <File > includePaths ,
@@ -662,8 +707,19 @@ public boolean accept(File dir, String name) {
662
707
return name .endsWith (".h" );
663
708
}
664
709
};
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
+ }
667
723
if (list == null ) {
668
724
throw new IOException ();
669
725
}
0 commit comments