2929import processing .app .SketchCode ;
3030import processing .core .*;
3131import processing .app .I18n ;
32+ import processing .app .helpers .filefilters .OnlyDirs ;
3233import static processing .app .I18n ._ ;
3334
3435import 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