PlatformIO Community

CPPDEFINES causes total rebuild


#1

I added this to my pre.py custom script:

from datetime import datetime
import getpass
import platform
import subprocess

buildstr = subprocess.check_output(['git', 'describe', '--long', '--dirty', '--tags']).strip() + "-" + getpass.getuser() + "@" + platform.uname()[1] + "-" + datetime.utcnow().strftime('%d/%m/%Y-%H:%M')
print("BUILD VERSION: " + buildstr)
env.Append(CPPDEFINES=[("PIO_BUILD", "\\\"" + buildstr + "\\\"")])

This generates the following on build:
BUILD VERSION: v0.1-1-gc5c911c-dirty-timv@timv-5510-27/04/2019-23:30
which I can include as a string literal in my datalog files with PIO_BUILD

My problem is that this causes PIO to rebuild the entire project, not just compilation units that depend on PIO_BUILD (only one). This makes the build process quite slow, as there are a number of dependencies.

Is there a fix for this, or a better way to approach it?

Thanks
Tim


Advanced scripting
#2

This might be a stupid question, but was there a change to the platformio.ini at the same time? As that usually triggers rebuilds after it is edited.


#3

env.Append(CPPDEFINES.... adds new macro to global build environment including flramework, dependent libraries ,etc. If you need to add this macro only for the project source files, please use projenv contruction environment. See https://docs.platformio.org/en/latest/projectconf/advanced_scripting.html#construction-environments


#4

Excellent, that speeds things up a lot! Thanks for the fix.
Having a build ID string that only triggered recompilation of files that depended on it might be a nice feature for PIO at some point.

Tim