Post action not running

In platformio.ini in [env] I have declared extra_scripts = post:scripts/postprocessor.py. This in itself appears to work, however when I try to use env.AddPostAction('build', callback) after Import('env'), the callback which should just run a print statement appears to do nothing when the ‘Build All’ task is run from the default project tasks.
Full platformio.ini here.

Regards.

The documentation talks about buildprog not build?

buildprog does not appear to work either.

Works fine. Tested on an Uno.

[env:uno]
platform = atmelavr
board = uno
framework = arduino
extra_scripts = post_build.py
Import("env")

def after_build(source, target, env): 
    print("[From Script] Finished building!!")

env.AddPostAction("buildprog", after_build)

Verbose Build:

RAM:   [          ]   0.4% (used 9 bytes from 2048 bytes)
Flash: [          ]   1.4% (used 444 bytes from 32256 bytes)
.pio\build\uno\firmware.elf  :
...
Total                      4077
after_build(["buildprog"], [".pio\build\uno\firmware.hex"])
[From Script] Finished building!!

From testing with your example, it appears the problem I was facing was with the action only running if the program was actually built. If I don’t alter the source and run the build task, the post action doesn’t run.
I’ve moved away from using this post build action approach for now, but it would be interesting to be able to have the action run like this.

Well for now, even when the firmware is not rebuilt, you can hook the action where the firmware sizes are displayed.

Import("env")

def after_build(source, target, env): 
    print("[From Script] After execution of progsize check!!")

env.AddPostAction("checkprogsize", after_build)

that always runs, irregardless of whether the firmware was actually regenerated or not after doing a “Build”.