The PlatformIO Build System uses two built-in construction environments to process each project:
env
, Import("env")
- the global construction environment used
for the Development Platforms and Frameworks build scripts, upload tools,
Library Dependency Finder (LDF), and other internal operations
projenv
, Import("projenv")
- the isolated construction environment
used for processing the project source code in src_dir.
Please note that any build_src_flags specified in
“platformio.ini” (Project Configuration File) will be passed to the projenv
and not to the env
.
Warning
projenv
is available only for POST-type scripts
Flags passed to env
using PRE-type script will affect projenv
too.
my_pre_extra_script.py
:
Import("env")
# access to global construction environment
print(env)
# Dump construction environment (for debug purpose)
print(env.Dump())
# append extra flags to global build environment
# which later will be used to build:
# - project source code
# - frameworks
# - dependent libraries
env.Append(CPPDEFINES=[
"MACRO_1_NAME",
("MACRO_2_NAME", "MACRO_2_VALUE")
])
my_post_extra_script.py
:
Import("env", "projenv")
# access to global construction environment
print(env)
# access to project construction environment
print(projenv)
# Dump construction environments (for debug purpose)
print(env.Dump())
print(projenv.Dump())
# append extra flags to global build environment
# which later will be used to build:
# - frameworks
# - dependent libraries
env.Append(CPPDEFINES=[
"MACRO_1_NAME",
("MACRO_2_NAME", "MACRO_2_VALUE")
])
# append extra flags to only project build environment
projenv.Append(CPPDEFINES=[
"PROJECT_EXTRA_MACRO_1_NAME",
("ROJECT_EXTRA_MACRO_2_NAME", "ROJECT_EXTRA_MACRO_2_VALUE")
])
See examples below how to import construction environments and modify existing data or add new.