I have a library with a few sample programs (esp32, Arduino, but that probably doesn’t matter).
I have an
extra_script.py that creates a version-file from git information and it adds some defines to
env["BUILD_FLAGS"] and a few other modifications.
If I run this script for my samples (by specifying
extra_scripts = pre:extra_script.py in my
platformio.ini) it works perfectly fine.
But if I run the script through my
build.extraScript parameter it does not work.
The script does run: the version file is created, and the script prints logging messages that I get. But the changes to
env are somehow not honoured.
Any suggestions on what I could be doing wrong?
Thank you @maxgerhardt , that was indeed the issue: I was using
Import("env") but I should use
DefaultEnvironment() in this case. I had overlooked the relevant sentence in the documentation:
If you use library.json and extraScript, the
Import("env") refers to the library’s isolated environment from which a script was called (not to the global environemnt). Please use
env = DefaultEnvironment() instead to access the global environemnt.
DefaultEnvironment() does’t seem to work.
One problem is that any changes I make to
BUILD_FLAGS (for example appending
-DMY_VERSION=42) aren’t actually picked up by the builds.
But moreover for some boards I seem to break the build process in a more serious way by modifying the
DefaultEnvironment(). Building for the
nodemcuv2 board for example it will not create the
local.eagle.app.v6.common.ld script if I make any changes. Running with
pio ci -v indeed shows that the step is skipped…
Shouldn’t that be in in
@maxgerhardt indeed. I was modifying
BUILD_FLAGS, which works for running your extra-script through
platformio.ini but doesn’t work if it is run through
By changing this to modifying
CPPFLAGS and ensuring I modify both
DefaultEnvironment() it now works everywhere.