Inheriting Environments

As environments multiply the platformio.ini file starts to feel a little bloated.

I assume that in the platformio.ini environments you can freely use field values from other environments by using, for example, framework = ${other.framework}. But is it also possible to inherit all the fields - an entire environment from another one, and then just apply changes within the new environment? An inherit = other property might do the trick.

If this isn’t possible now, then I suggest adding the capability. For future PlatformIO also consider making the platformio.ini file hierarchical, either in JSON or YML format, so that environments can simply be nested within other environments. That would be the most economical way to arrange it, and should not be too much harder to parse.

In the meantime, for the sake of making abstract (inherit-only) environments that don’t show up in the Tasks/Build menu, a hidden property would also be useful.

I think it’s on the way… in version 4.0 [env] will have both a global and local scope.

https://docs.platformio.org/en/latest/projectconf/section_env.html

1 Like

Hi, I think this functionality isn’t implemented in Platformio but I found it very useful, an example can be better for understending:

[env:esp32]
extra_scripts = git_script.py
platform = espressif32
framework = arduino
monitor_speed = 115200
lib_deps = 
  ; Common libreries shared whit all ESP32 .....
testing_framework = unity
build_src_filter = 
  -<.>
  +<common>
  +<esp>

[env:esp32dev]
extend = env:esp
board = esp32dev
lib_deps = 
  ${env:esp.lib_deps}
  ;PLUS ESP32 Dev specific libraries

[env:esp32wrover]
extend = env:esp
board = esp32wrover
lib_deps = 
  ${env:esp.lib_deps}
  ;PLUS ESP32 wrover specific libraries

[env:pico]
platform = raspberry
board = pico
build_src_filter = 
  -<.>
  +<common>
  +<pico>
;....

In this case there is a project with two families of uC (Espressif32 and RP2040), and also multiple targets on the same family, like ESP32 Dev and ESP32 WRover, in this case an environment for the ESP32 may be useful, but at the same time this can’t be use for compile because some crucial information like the target device are missing, so isn’t useful to have this in the list of available envs.

A tip can be to create a new special key like ‘virtual’ and an example for the specific env can be:

[env:esp32]
extra_scripts = git_script.py
platform = espressif32
framework = arduino
monitor_speed = 115200
lib_deps = 
  ; Common libreries shared whit all ESP32 .....
testing_framework = unity
build_src_filter = 
  -<.>
  +<common>
  +<esp>
virtual = true

Alan

For completeness, as a followup to my original post…

  • In 4.x we got the extends field to inherit from other named blocks.
  • Only environments starting with “env:” are shown in the PlatformIO panel and Tasks/Build list.
1 Like

Super great!
This can be super useful!

Alan