I have been using the particle CLI to compile and flash programs to my photon. This is all working fine.
I want to create a slightly more complex program now that uses libraries and so I want to organise them into separate directories. Is it possible to add the files in these sub folders while maintaining the folder structure?
I can add them to the compilation step using a particle.include file but this results in the files all being in the root directory and not in their original sub folders.
Yes you can keep the file structure as you got it there (since CLI v1.13.0 even without particle.include) but you have to have the include statements as if all files were in the same directory - for the time being.
But I’d suggest you have two sets of include statements (one flat, one structured) and just wrap them in conditional compile blocks like
#define FLAT_PROJECT
#if defined(FLAT_PROJECT)
# include "lib1.h"
# include "lib2.h"
#else
# include "lib1/lib1.h"
# include "lib2/lib2.h"
#endif
Thanks for that. I was using 1.10.0 so when I updated to the latest (1.15.0 I think) it then started picking up all the files in the sub folders.
However now when I compile, it fails but doesn’t give me a reason. Is there a verbose flag or any other option I can give to get more information?
Here is an example output:
$ particle compile p .
Compiling code for p
Including:
...
list of all files in the current folder and sub folders
...
attempting to compile firmware
Compile failed. Exiting.
I can replicate this behaviour with a folder structure of:
Interestingly I’ve tried compiling using the cli source from github with some extra logging added and I am getting an error back from the compile api (ApiClient.compileCode)
....
body:
{ ok: false,
code: 200,
output: 'Compiler timed out or encountered an error',
errors: [] } }
If I move lib1.h up one level under lib/ then it compiles fine.
So maybe there is a bug somewhere where you can only compile files nested 1 level down. That issue you linked to does seem suspiciously relevant. Is the server code available anywhere to look at or is that closed source?
Thanks for this report. That looks like a bug in the compiler service not creating directories recursively. It’s different from the GitHub issue linked above.
We are working on supporting libraries and structured projects better through the cloud compiler. In the mean time please use a project structure with one level of subdirectories if possible.
If you want to follow the project structure documented here you can do particle project create to have the CLI create the project structure for you. It will recursively compile files in src.
You can also just run particle compile photon in a folder that has your code and it will pick up code in sub directories.