I would like to see in my firmware its version and build time. So I found a python file that sets a defyne with this text and just output it to the UART:
But the problem is that now the project is rebuilt from scratch every time. If you fix BUILD_FLAGS to BUILD_FLAGS_ in the script, this behavior stops, so I think this is a consequence of the BUILD_FLAGS modification. But I couldn’t go any further in analyzing this problem.
The script itself looks like this:
It smells like it’s comming from the OpenDTU project?!
I think the reason for the complete rebuild is, that build_flags are modified, which applies to every source file (including the framework source files)
Modifying the build_src_flags instead should be the solution.
Unfortunately I’m not familiar with SCons and python and tried to set build_src_flags from within the script for 2 hours now without any success .
It works exactly the same way, also forcing you to rebuild all the code. I realize that the macro changes every second, but it only affects one file, and I expected that only that file would be compiled every time I build the project.
What if I modify the script so that it records the time in an .h file, which I then add to my code via #include?
It should be possible to use SRC_BUILD_FLAGS instead of BUILD_FLAGS in an extra script. There is also an alternative way of adding build flags to a specific file via a middleware function, more info here.
AFAIR there is no docs for BUILD_FLAGS or SRC_BUILD_FLAGS mainly because we don’t encourage developers to use environment variables used by PlatformIO build system internally, although it should be safe to do so. I’d rather recommend using a proper environment variable called PLATFORMIO_BUILD_SRC_FLAGS.
It’s interesting, but for some reason the SRC_BUILD_FLAGS option causes a few more files in the ui folder to be built each time. But of course this is not even a tenth of the project, but the behavior is strange.
That’s expected behavior because build_src_flags are applied all project source files.
Afaik the only way to avoid this is your second approach by creating a temporary header file which has the version string and include this to your source file.