Global defines from extra_script not applied

Hi,

I also created an issue here: extra_script global defines not working · Issue #5146 · platformio/platformio-core

But i figured i might as well ask here if anyone got global defines working in a python build script?

I followed the example here: extraScript — PlatformIO latest documentation

But it just isn’t working, the defines are not added to the compilation arguments.

Any help is appreciated
Thanks.

Hi levi_g!

Can you describe what you are trying to solve?

Sure, i need to define 2 global defines to change platform behavior. currently i have the users add:

build_flags =
-D USBCON
-D HAL_PCD_MODULE_ENABLED

to their ini file, but it is really tedious, so i tried to use a library extra_script to add the global define like the example, and they are added to the python environment but then they are not added to the compilation arguments having no effect on the actual build.

I attached the script and build arguments in the issue that might be easier to understand.

So if i log the print(global_env.get(‘CPPDEFINES’)) i get:

(...)('VARIANT_H', '\\"variant_generic.h\\"'), ('VECT_TAB_OFFSET', '0x0'), ('USBCON', 1), ('HAL_PCD_MODULE_ENABLED', 1), 'USBCON'])

which is expected, but then in the actual build i get:

(...)-DVARIANT_H=\"variant_generic.h\" -DVECT_TAB_OFFSET=0x0 -Iinclude -Isrc (...)

So nor my defines nor flags are where they should be. (and the build fails)