I have followd the example in the docs for dynamic build flags using a script. However it appears the python script is not called. I am not sure how to debug this:
In platformio.ini I have added:
build_flags = !python build_flags.py
In the same folder as platformio.ini I have added build_flags.py:
String escaping is tricky. If you get a compile error it seems to me that the script is indeed called and will appear in project tasks “Advanced → Verbose Build” but will not have the correct form of quotes around it.
It it is maybe also preferable to not do a build_flags = !python build_flags.py but use extra_scripts as there you can directly add into the build environment settings (env["CPPDEFINES"] etc.).
Either that, or use the stringifaction macro in your code.
#define stringify(s) _stringifyDo(s)
#define _stringifyDo(s) #s
// use this macro instead
#define GIT_REV_STR stringify(GIT_REV)