Import("env")
def thisShouldRun(source, target, env):
print("\n==> this should run\n")
env.AddPreAction("buildprog", thisShouldRun)
print("\n==> but, only this runs...\n")
When running pio run , it only gives but, only this runs...
Probably there is a mistake somewhere but I can’t seem to spot it. Any help?
Observation: When I remove the pre: in the platformio.ini, the callback function is executed after the program is built.
Building in release mode
==> but, only this runs...
..
Checking size .pio\build\esp32\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 4.5% (used 14700 bytes from 327680 bytes)
Flash: [== ] 16.0% (used 209795 bytes from 1310720 bytes)
esptool.py v2.6
thisShouldRun(["buildprog"], [".pio\build\esp32\firmware.bin"])
==> this should run
(second-last line in output due to Verbose Build).
This is correct because without the pre:, the default is post:.
…there might be a sitation, after reading docs, that buildprog is not a known target yet because if you’re doing a pre: the script gets executed before the main platform script, which defines buildprog?
Semantically if you want to run something before the build starts, isn’t the “but only this runs” already the right place? Or do you want a hook before building a specific file to modify it last-minute?
The method in the script fetches some html/css/js files and adds the content to a C header to be included in the build. Depending on the env it should minify the contents or not. I could off course use two different scripts but now I was trying to make one script and catch the env to differentiate in the script.
There are many ways to achieve this, but now I’m intrigued why I can’t make it work using this method.
In projects I know, e.g. esp8266_milight_hub, they also do it directly in the main execution flow of the pre script
Same here, but no confirmed clue why that won’t work. Maybe @ivankravets knows about the possibility/impossibility of using the buildprog target in a the pre: script?
There is no target buildprog BEFORE/PRE build process. So, this is why it does not work.
Why you do not just call your callback in PRE without any actions as @maxgerhardt mentioned?
If you need to call a callback AFTER all actions in PRE script but BEFORE SCons will start building project, please use Redirecting...
So, you can setup “dummy” middleware with the IS_RUN flag. So, the only SCons starts building the first source file, you call your callback and mark IS_RUN=True