BelaPlatform / Bela

Bela: core code, IDE and lots of fun!
Other
484 stars 138 forks source link

parse `settings.json` from C++ #394

Open giuliomoro opened 6 years ago

giuliomoro commented 6 years ago

Add command-line option --jsopts to pass a path to a .json file containing command-line options. E.g.:

/root/Bela/projects/projectname/projectname --jsopts /root/Bela/projects/projectname/settings.json

Multiple --jsopts should be allowed (to override previous declarations). Intermixing --jsopts and other command-line options should allow to override settings so that only the latest setting specified (be it in a json or at the command line) is applied. This should be built into Bela_getopt_long(), so that there is no change needed to legacy custom main.cpp to support the new feature. core/JSON.cpp should already have all that is needed to parse the JSON.

Caveats: make runide should call

/root/Bela/projects/projectname/projectname --jsopts /root/Bela/projects/projectname/settings.json

Therefore the IDE needs to make sure it has actually finished writing settings.json before it calls make runide.

adanlbenito commented 6 years ago

There is a json.parse in the core code (json.h). Example of usage in scope.cpp

giuliomoro commented 6 years ago

file1.json has CL="-X 2 -C 4" file2.json has CL="-G 0 -D 2" then they should be expanded recursively in place so that

./belaproject -C 2 --jsopts file1.json -C 8 --jsopts file.json

should be equivalent to

./belaproject -C 2 -X 2 -C 4 -C 8 -G 0 -D 2
giuliomoro commented 10 months ago

An additional issue here is that there are now many layers of overriding and this needs to be thought through holistically to reach a rational solution, because things are already complicated enough. The options that are used to configure the program are stored in the BelaInitSettings object in main() (see here). This is populated as follows (in order, with each step overwriting the existing content):

Note: currently the IDE's command line options will set all (or at least most, because some have been deprecated and some others may have been forgotten) command-line options available, which means that the command line options stored in CL= in the userBelaConfig file will most likely be entirely overridden by the contents of settings.json when running from the IDE. This makes sense because as far as the process knows, this is "hard-coded" (on disk) options from userBelaConfig vs "runtime" options passed on the "command-line", so it makes sense that the latter "wins" even though they are actually coming from another file (settings.json)