Hej!
I would like to supply my own library.json
for a specific library to be “independent” from the project sources and choose only the sources I need in my project.
Do to that in platformio.ini
I added the library git URL and the extra script name which patches the library:
extra_scripts = pre:extra_script.py
lib_deps = https://github.com/KKoovalsky/JunglesDataStructs.git
I created a directory lib_overlay
which contains my own library.json
for that library with the relative path lib_overlay/JunglesDataStructs/library.json
.
Then in my extra_script.py
I perform the actual patching like that:
from shutil import copyfile
from os import path
Import("env")
ROOT_DIR = env['PROJECT_DIR']
PIO_PLATFORM = env['PIOPLATFORM']
LIBDEPS_DIR = env['PROJECT_LIBDEPS_DIR']
JDS_LIB_JSON_SRC_PATH = path.join(
ROOT_DIR, 'lib_overlay/JunglesDataStructs/library.json')
JDS_LIB_JSON_DST_PATH = path.join(
LIBDEPS_DIR, PIO_PLATFORM, 'JunglesDataStructs', 'library.json')
copyfile(JDS_LIB_JSON_SRC_PATH, JDS_LIB_JSON_DST_PATH)
-
The problem with this approach is when the project is compiled for the first time the extra script is run BEFORE the library is downloaded, so the patching will not work. This approach works only if I comment out the
copyfile...
line, when runningplatformio run
for the first time, and then when running for the second time I uncomment the mentioned line. So the question is: is there a clean way of patching the library AFTER it is downloaded, and BEFORE it is compiled? -
In the code of the
extra_script.py
there is a lot of “manual” path handling and so on. Is there a method like:
projenv.get_library_dir("JunglesDataStructs")
which will return the actual path to the library downloaded locally in the project directory? Basically it means to replace all the code which merges the JDS_LIB_JSON_DST_PATH
to a single call.
- Is there some kind of documentation which documents how to use the python modules/methods inside the
extra_scripts
?