Interpolation of Values
In addition to its core functionality, PlatformIO introduces support for interpolation, allowing values to incorporate format strings that reference other values from different sections.
The interpolation feature adheres to the following syntax:
${<variable>}
, where<variable>
represents the name of a supported built-in variable (refer to the table below for details).${<section>.<option>}
, with<section>
denoting a value from the[<section>]
group, and<option>
representing the first item in the pair<option> = value
.
Syntax |
Meaning |
Example |
---|---|---|
|
Incorporate built-in variables using their designated names. The following variables are supported:
|
|
|
Embed operating system environment variable by a name |
|
|
Embed value from Section [platformio] |
|
|
Embed default value from Section [env] |
|
|
Embed value from another section. |
|
|
Embed value from the current section without declaring a section name |
|
|
Embed environment name of the current section. The section must start with |
|
Interpolation can span multiple levels
Interpolation can be applied only for the option’s value
Multiple interpolations are allowed
The Section [platformio] and Section [env] sections are reserved and could not be used as a custom section. Some good section names might be
extra
orcustom
.
Note
If you need to share common configuration options between build environments, please take a look at “Global scope” in Section [env] or extends option which allows extending of other sections.
Example:
; COMMON options
; Each "[env:***]" extends this "[env]" by default
[env]
framework = arduino
build_flags = -D VERSION=1.2.3
; CUSTOM options
; You need manually inject these options into a section
; using ${extra.<name_of_option>} (see below)
[extra]
lib_deps_builtin =
SPI
Wire
lib_deps_external =
bblanchon/ArduinoJson@>5.6.0
[env:uno]
platform = atmelavr
board = uno
lib_deps =
${extra.lib_deps_builtin}
${extra.lib_deps_external}
platform_packages =
platformio/tool-simavr
test_speed = 9600
test_testing_command =
${platformio.packages_dir}/tool-simavr/bin/simavr
-m
atmega328p
-f
16000000L
${platformio.build_dir}/${this.__env__}/firmware.elf
[env:esp32dev]
platform = platformio/espressif32
board = esp32dev
build_flags = ${env.build_flags} -Wall
lib_deps =
${extra.lib_deps_builtin}
${extra.lib_deps_external}
knolleary/PubSubClient @ ~2.6
paulstoffregen/OneWire @ ^2.3.5
; Keep sensitive data in environment variables
;
; Unix
; export WIFI_SSID='\"my\ ssid\ name\"'
; export WIFI_PASS='\"my\ password\"'
;
; Windows
; set WIFI_SSID='"my ssid name"'
; set WIFI_PASS='"my password"'
Warning
Be careful with special characters in system environment variables on Unix systems,
especially when they are used as the value for preprocessor directives.
Symbols like $
, &
, ~
, etc must be explicitly escaped, for example:
export WIFI_PASS='\"my\~p\&a\\\$\$\$\$word\"'