platformio-core icon indicating copy to clipboard operation
platformio-core copied to clipboard

Options merge through extends-like option

Open turgu1 opened this issue 4 years ago • 12 comments

Version: PlatformIO IDE V2.2.1 Editor: VSCode OS: Linux

Hello, it would be beneficial that the following platformio.ini would merge options, such that in my (over simplified) example below, for [env:device1], there would be two entries in the build_flags option, instead of one (with the current version of platformio, builds_flags in [env:device1] replaces the one from devices when extends is used. I was expecting that there would be some merge option available):

[devices]
build_flags =
  -D MAIN_DEFINE=2

[env:device1]
extends_with_merge = devices
build_flags =
  -D OTHER_DEFINE=1

I could have added ${device.build_flags} under -D OTHER_DEFINE=1 but when you have many of these repeated options, it defeat the purpose of clarity. Here is a real example that would benefit from this feature (don't tell me to use [env] for this, the platformio.ini contains a lot more that can't rely on [env]):

[platformio]
default_envs = inkplate_6

[inkplate_common]
platform               = espressif32
board                  = esp-wrover-kit
framework              = espidf
monitor_speed          = 115200
upload_speed           = 256000
monitor_filters        = colorize
board_build.partitions = partitions.csv
build_flags =
  -O3
  -D DEBUGGING=0
  -D CONFIG_SPIRAM_CACHE_WORKAROUND
  -D EPUB_INKPLATE_BUILD=1
  -D EPUB_LINUX_BUILD=0
  -D INCLUDE_vTaskSuspend=1
  -D SHOW_TIMING=0
  !/usr/bin/pkg-config --cflags --libs lib_freetype/lib/pkgconfig/freetype2.pc
  -std=gnu++17
  -I include_global
lib_extra_dirs =
  lib_esp32
board_build.embed_files =
  embed/favicon.ico
  embed/upload_script.html
lib_deps =
  https://github.com/turgu1/ESP-IDF-InkPlate.git

[env:inkplate_6]
extends_with_merge     = inkplate_common
build_type  = release
build_flags =
  -D INKPLATE_6

[env:inkplate_6plus]
extends_with_merge     = inkplate_common
build_type  = release
build_flags =
  -D INKPLATE_6PLUS

[env:inkplate_10]
extends_with_merge     = inkplate_common
build_type  = release
build_flags =
  -D INKPLATE_10

Did I miss something from what is currently possible with the platform.ini structure? Is there another way to do it without compromising the clarity of the ini file? Maybe a new option named merges or something? Thanks a lot for your help!!

Guy

turgu1 avatar Dec 30 '20 14:12 turgu1

Hello,

You are looking for extends option, see https://docs.platformio.org/en/latest/projectconf/section_env_advanced.html

ivankravets avatar Jan 04 '21 11:01 ivankravets

I'm sorry Ivan, but extends doesn't do the job. Please look closer to my simple example: If I do what you said:

[devices]
build_flags =
  -D MAIN_DEFINE=2

[env:device1]
extends = devices
build_flags =
  -D OTHER_DEFINE=1

In [env:device1], I loose the MAIN_DEFINE definition. Hope this is clearer.

Thanks! Guy

turgu1 avatar Jan 04 '21 12:01 turgu1

See Dynamic variables:

[devices]
build_flags =
  -D MAIN_DEFINE=2

[env:device1]
extends = devices
build_flags =
  -D OTHER_DEFINE=1
  ${devices.build_flags}

ivankravets avatar Jan 04 '21 14:01 ivankravets

That is exactly what I want to avoid. When you have several hundred lines of platformio.ini file, it become quiet combersome.

On Mon, 2021-01-04 at 06:02 -0800, Ivan Kravets wrote:

See Dynamic variables:

[devices] build_flags = -D MAIN_DEFINE=2

[env:device1] extends = devices build_flags = -D OTHER_DEFINE=1 ${devices.build_flags}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

turgu1 avatar Jan 04 '21 14:01 turgu1

Thanks, I moved to PlatformIO Core.

ivankravets avatar Jan 05 '21 10:01 ivankravets

Also see #3952 which is similar but does not limit to build_flags only.

lnlp avatar May 12 '21 12:05 lnlp

@turgu1, @lnlp, @softwaregravy, how about the following syntax?

[foo]
build_flags = -DHELLO

[bar]
lib_deps = ...

[env:myenv]
extends = merge:foo, bar

So, the prefix merge will instruct PlatformIO to merge values and avoid duplicates, and the replace:%name% or %name% will override the option (current behavior).

ivankravets avatar Nov 24 '22 12:11 ivankravets

That seems reasonable

softwaregravy avatar Nov 24 '22 12:11 softwaregravy

This is it! Thanks guys!

turgu1 avatar Nov 24 '22 13:11 turgu1

👍

Jason2866 avatar Nov 24 '22 13:11 Jason2866

@ivankravets any news on this topic?

I have a different use case to merge. Please look at this platformio.ini snippet:

[OTA8266]
upload_protocol = espota
; use secret from _credentials_OTA.ini for later use in [env:My-Device-OTA]
ota_auth = ${secrets.ota_auth}
upload_flags =
  --auth=${ota_auth}
  --port=8266

[env:MyDevice1]
board = esp01_1m

; set device for Config.h
build_flags = ${env.build_flags}
    -DMyDevice1

[env: MyDevice1_OTA]
extends = MyDevice1, OTA8266
upload_port = MyDevice1.local

With the current implementation we get Error: BoardConfig: Board is not defined

But there are no conflicting properties which would be overwritten.

CONSULitAS avatar Feb 15 '23 21:02 CONSULitAS