Skip to content

Commit 2f0abf6

Browse files
committed
Refactor "Interpolation of Values"
1 parent 66f67cb commit 2f0abf6

File tree

10 files changed

+140
-116
lines changed

10 files changed

+140
-116
lines changed

envvars.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Examples:
177177
178178
.. warning::
179179

180-
Consider using :ref:`projectconf_dynamic_vars` instead of ``PLATFORMIO_BUILD_FLAGS``
180+
Consider using :ref:`projectconf_interpolation` instead of ``PLATFORMIO_BUILD_FLAGS``
181181
environment variable if additional build flags contain preprocessor directive with
182182
special characters (``$``, ``&``, ``~``, etc) in its value.
183183

platforms/atmelavr_extra.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Configuration for the programmers:
4444
upload_flags =
4545
-C
4646
; use "tool-avrdude-megaavr" for the atmelmegaavr platform
47-
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
47+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
4848
-p
4949
$BOARD_MCU
5050
-P
@@ -67,7 +67,7 @@ Configuration for the programmers:
6767
upload_flags =
6868
-C
6969
; use "tool-avrdude-megaavr" for the atmelmegaavr platform
70-
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
70+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
7171
-p
7272
$BOARD_MCU
7373
-P
@@ -92,7 +92,7 @@ Configuration for the programmers:
9292
upload_flags =
9393
-C
9494
; use "tool-avrdude-megaavr" for the atmelmegaavr platform
95-
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
95+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
9696
-p
9797
$BOARD_MCU
9898
-c
@@ -112,7 +112,7 @@ Configuration for the programmers:
112112
upload_flags =
113113
-C
114114
; use "tool-avrdude-megaavr" for the atmelmegaavr platform
115-
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
115+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
116116
-p
117117
$BOARD_MCU
118118
-P
@@ -135,7 +135,7 @@ Configuration for the programmers:
135135
upload_flags =
136136
-C
137137
; use "tool-avrdude-megaavr" for the atmelmegaavr platform
138-
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
138+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
139139
-p
140140
$BOARD_MCU
141141
-P
@@ -155,7 +155,7 @@ Configuration for the programmers:
155155
upload_flags =
156156
-C
157157
; use "tool-avrdude-megaavr" for the atmelmegaavr platform
158-
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
158+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
159159
-p
160160
$BOARD_MCU
161161
-c
@@ -176,7 +176,7 @@ Configuration for the programmers:
176176
upload_flags =
177177
-C
178178
; use "tool-avrdude-megaavr" for the atmelmegaavr platform
179-
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
179+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
180180
-p
181181
$BOARD_MCU
182182
-P

projectconf/index.rst

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ sections and their allowed contents:
4040

4141
section_platformio
4242
section_env
43+
interpolation
4344
build_configurations
44-
dynamic_variables
4545
examples
4646

4747
**Example**
@@ -53,9 +53,8 @@ For more examples, see :ref:`projectconf_examples`.
5353
[platformio]
5454
default_envs = nodemcuv2
5555
56-
; You MUST inject these options into [env:] section
57-
; using ${common_env_data.***} (see below)
58-
[common_env_data]
56+
; Set/override default options for each "[env:***]"
57+
[env]
5958
build_flags =
6059
-D VERSION=1.2.3
6160
-D DEBUG=1
@@ -74,14 +73,14 @@ For more examples, see :ref:`projectconf_examples`.
7473
7574
; Build options
7675
build_flags =
77-
${common_env_data.build_flags}
76+
${env.build_flags}
7877
-DSSID_NAME=HELLO
7978
-DSSID_PASWORD=WORLD
8079
8180
; Library options
8281
lib_deps =
83-
${common_env_data.lib_deps_builtin}
84-
${common_env_data.lib_deps_external}
82+
${env.lib_deps_builtin}
83+
${env.lib_deps_external}
8584
https://github.com/me-no-dev/ESPAsyncTCP.git
8685
PubSubClient@2.6
8786
OneWire
@@ -100,17 +99,13 @@ For more examples, see :ref:`projectconf_examples`.
10099
framework = arduino
101100
board = bluepill_f103c8
102101
103-
; Build options
104-
build_flags = ${common_env_data.build_flags}
105-
106102
; Library options
107-
lib_deps =
108-
${common_env_data.lib_deps_external}
103+
lib_deps = ${env.lib_deps_external}
109104
110105
; Debug options
111106
debug_tool = custom
112107
debug_server =
113-
JLinkGDBServer
108+
${platformio.packages_dir}/tool-jlink/JLinkGDBServer
114109
-singlerun
115110
-if
116111
SWD

projectconf/dynamic_variables.rst renamed to projectconf/interpolation.rst

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,43 @@
99
See the License for the specific language governing permissions and
1010
limitations under the License.
1111
12-
.. _projectconf_dynamic_vars:
12+
.. _projectconf_interpolation:
1313

14-
Dynamic variables
15-
-----------------
14+
Interpolation of Values
15+
-----------------------
1616

17-
Dynamic variables (interpolations) are useful when you have a custom
18-
configuration data between build environments. For examples, extra
19-
:ref:`projectconf_build_flags` or project dependencies :ref:`projectconf_lib_deps`.
17+
On top of the core functionality, PlatformIO supports interpolation. It enables values
18+
to contain format strings which refer to other values from foreign sections.
2019

21-
Each variable should have a next format: ``${<section>.<option>}``, where
20+
Interpolation has the next syntax – ``${<section>.<option>}``, where
2221
``<section>`` is a value from ``[<section>]`` group, and ``<option>`` is a
2322
first item from pair ``<option> = value``.
2423

25-
You can inject system environment variable using ``sysenv`` as a ``section``.
26-
For example, ``${sysenv.HOME}``.
24+
.. list-table::
25+
:header-rows: 1
2726

28-
* Variable can be applied only for the option's value
29-
* Multiple variables are allowed
27+
* - Syntax
28+
- Meaning
29+
30+
* - ``${sysenv.<name>}``
31+
- Embed system environment variable by a name. For example,
32+
``${sysenv.HOME}`` refers to user home directory on Unix machine
33+
34+
* - ``${platformio.<option>}``
35+
- Embed value from :ref:`projectconf_section_platformio`. For example,
36+
``${platformio.packages_dir}`` refers to a path of :ref:`projectconf_pio_packages_dir`
37+
38+
* - ``${env.<option>}``
39+
- Embed default value from :ref:`projectconf_section_env`. For example,
40+
``${env.debug_build_flags}`` refers to the default debugging flags.
41+
42+
* - ``${<section>.<option>}``
43+
- Embed value from another section. For example, ``${extra.lib_deps}`` embeds
44+
library dependencies declared in the section named ``extra``.
45+
46+
* Interpolation can span multiple levels
47+
* Interpolation can be applied only for the option's value
48+
* Multiple interpolations are allowed
3049
* The :ref:`projectconf_section_platformio` and :ref:`projectconf_section_env`
3150
sections are reserved and could not be used as a custom section. Some good
3251
section names might be ``extra`` or ``custom``.
@@ -37,7 +56,7 @@ For example, ``${sysenv.HOME}``.
3756
:ref:`projectconf_section_env` or :ref:`projectconf_env_extends` option which
3857
allows extending of other sections.
3958

40-
Example:
59+
**Example:**
4160

4261
.. code-block:: ini
4362

projectconf/section_env_advanced.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ in :ref:`projectconf`. Multiple items are allowed, split them with ``,`` or
2626
with a new line.
2727

2828
If you need to extend only a few options from some section, please take a look at
29-
:ref:`projectconf_dynamic_vars`.
29+
:ref:`projectconf_interpolation`.
3030

3131
Example:
3232

projectconf/section_env_build.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ You can inject the built-in variables into your build flags, such as:
160160
* ``$PROJECT_BUILD_DIR``, project build directory per all environments
161161
* ``$BUILD_DIR``, build directory per current environment
162162

163-
See the `full list of PlatformIO variables <https://github.com/platformio/platformio-core/blob/develop/platformio/builder/main.py#L99:L120>`_.
163+
See the `full list of PlatformIO variables <https://github.com/platformio/platformio-core/blob/develop/platformio/builder/main.py>`_.
164164

165165
Please use target ``envdump`` for the :option:`pio run --target`
166166
command to see ALL variable values for a build environment.

projectconf/section_env_debug.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ with a debugging server that is compatible with "on-board" debugging tool
237237
* First line is an executable path of debugging server
238238
* 2-nd and the next lines are arguments for executable file
239239

240-
**Example:**
240+
**Examples:**
241241

242242
.. code-block:: ini
243243
@@ -251,6 +251,15 @@ with a debugging server that is compatible with "on-board" debugging tool
251251
...
252252
argN
253253
254+
[env:debug_openocd]
255+
platform = ...
256+
board = ...
257+
debug_tool = custom
258+
debug_server =
259+
${platformio.packages_dir}/tool-openocd/openocd
260+
-f
261+
${platformio.packages_dir}/tool-openocd/scripts/board/stm32f103zet6_warship.cfg
262+
254263
.. _projectconf_debug_port:
255264

256265
``debug_port``

projectconf/section_env_library.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Specify project dependencies that should be installed automatically to
3434
:ref:`projectconf_pio_libdeps_dir` before environment processing.
3535

3636
If you have multiple build environments that depend on the same libraries,
37-
you can use :ref:`projectconf_dynamic_vars` to use common configuration.
37+
you can use :ref:`projectconf_interpolation` to use common configuration.
3838

3939
**Valid forms**
4040

projectconf/section_env_upload.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Default upload commands are declared in ``build/main.py`` script file of
173173
``some-flash-bin-tool $UPLOADERFLAGS $SOURCE``, where
174174
``$SOURCE`` will be replaced by a real program/firmware binary.
175175

176-
``$PROJECT_PACKAGES_DIR`` build variable points to :ref:`projectconf_pio_packages_dir`.
176+
``${platformio.packages_dir}`` template points to :ref:`projectconf_pio_packages_dir`.
177177

178178
.. code-block:: ini
179179
@@ -184,7 +184,7 @@ Default upload commands are declared in ``build/main.py`` script file of
184184
upload_protocol = custom
185185
upload_flags =
186186
-C
187-
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
187+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
188188
-p
189189
atmega328p
190190
-P
@@ -206,7 +206,7 @@ Default upload commands are declared in ``build/main.py`` script file of
206206
upload_protocol = custom
207207
upload_flags =
208208
-C
209-
$PROJECT_PACKAGES_DIR/tool-avrdude/avrdude.conf
209+
${platformio.packages_dir}/tool-avrdude/avrdude.conf
210210
-p
211211
atmega328p
212212
-Pusb
@@ -223,4 +223,4 @@ Default upload commands are declared in ``build/main.py`` script file of
223223
framework = stm32cube
224224
board = bluepill_f103c6
225225
upload_protocol = custom
226-
upload_command = $PROJECT_PACKAGES_DIR/tool-stlink/st-flash write $SOURCE 0x8000000
226+
upload_command = ${platformio.packages_dir}/tool-stlink/st-flash write $SOURCE 0x8000000

0 commit comments

Comments
 (0)