PIO is ignoring per-environment sdkconfig files

I have a sdkconfig.defaults and sdkconfig.TCPLUS. When building the TCPLUS environment, the resultant sdkconfig file is based on sdkconfig.defaults, and sdkconfig.TCPLUS is ignored.

In the build log (below), you will see:

-- Project sdkconfig file /home/epoulsen/workspaces/tc/.pio/build/TCPLUS/sdkconfig
Loading defaults file /home/epoulsen/workspaces/tc/sdkconfig.defaults...

and then a bit later:

-- Project sdkconfig file /home/epoulsen/workspaces/tc/sdkconfig.TCPLUS

However, the resultant file in .pio/build/TCPLUS/sdkconfig is based on sdkconfig.defaults and NOT sdkconfig.TCPLUS

It appears (from the log) that PIO is running some cmake script twice. The first time, it’s pulling the defaults and writing it to the build dir sdkconfig, and the 2nd time it’s not updating sdkconfig b/c it already exists, but that’s just speculation on my part.

Here is my platformio.ini file:

[platformio]
src_dir = src
default_envs = 
    TC
    TCPLUS

[env] ## Defaults
monitor_speed = 115200

board = esp32dev
framework = espidf
platform = espressif32@6.7.0
platform_packages = framework-espidf@file://submodules/esp-idf-ssr/esp-idf-ssr.zip

; platform_packages = /home/epoulsen/workspaces/TC/esp-idf-ssr

monitor_port = /dev/ttyUSB3
upload_port = /dev/ttyUSB1

board_upload.flash_size = 16MB

board_build.partitions = src/partitions.csv
build_flags = -Isrc -DSSR_PLATFORM_TC=1

custom_version_header_file = src/version.hh
custom_version_text_file = version.txt
extra_scripts = 
	pre:generate_version_info.py

## If you add files here, you must also add them
## to  src/CMakelists.txt
board_build.embed_txtfiles = 
    src/certs/servercert.pem
    src/certs/prvtkey.pem

[env:TC]

[env:TCPLUS]

Here is (some of) the pio build output with -v:

BUILD_TYPE=tcplus-dev BUILD_DATE=2024-10-03T16-49-50 /home/epoulsen/.platformio/penv/bin/pio run -e TCPLUS -t buildprog
Processing TCPLUS (monitor_speed: 115200; board: esp32dev; framework: espidf; platform: espressif32@6.7.0; platform_packages: framework-espidf@file://submodules/esp-idf-ssr/esp-idf-ssr.zip; monitor_port: /dev/ttyUSB3; upload_port: /dev/ttyUSB1; board_upload.flash_size: 16MB; board_build.partitions: src/partitions.csv; build_flags: -Isrc -DSSR_PLATFORM_TC=1; custom_version_header_file: src/version.hh; custom_version_text_file: version.txt; extra_scripts: pre:generate_version_info.py; board_build.embed_txtfiles: 
src/certs/servercert.pem
src/certs/prvtkey.pem)
--------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 (6.7.0) > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf @ 3.50102.240122 (5.1.2, file://submodules/esp-idf-ssr/esp-idf-ssr.zip) 
 - tool-cmake @ 3.16.4 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - tool-ninja @ 1.7.1 
 - tool-riscv32-esp-elf-gdb @ 12.1.0+20221002 
 - tool-xtensa-esp-elf-gdb @ 12.1.0+20221002 
 - toolchain-esp32ulp @ 1.23500.220830 (2.35.0) 
 - toolchain-xtensa-esp-elf @ 13.2.0+20230928
Reading CMake configuration...
-- Found Git: /usr/bin/git (found version "2.43.0") 
-- git rev-parse returned 'fatal: not a git repository (or any of the parent directories): .git'
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-gcc
-- Check for working C compiler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-gcc
-- Check for working C compiler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-g++
-- Check for working CXX compiler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Building ESP-IDF components for target esp32
-- Project sdkconfig file /home/epoulsen/workspaces/tc/.pio/build/TCPLUS/sdkconfig
Loading defaults file /home/epoulsen/workspaces/tc/sdkconfig.defaults...
/home/epoulsen/workspaces/tc/sdkconfig.defaults:387 CONFIG_COMPILER_OPTIMIZATION_DEFAULT was replaced with CONFIG_COMPILER_OPTIMIZATION_DEBUG
/home/epoulsen/workspaces/tc/sdkconfig.defaults:714 CONFIG_ESP_SLEEP_DEEP_SLEEP_WAKEUP_DELAY was replaced with CONFIG_ESP_SLEEP_WAIT_FLASH_READY_EXTRA_DELAY
-- Compiler supported targets: xtensa-esp-elf
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of time_t
-- Check size of time_t - done
-- Found Python3: /home/epoulsen/.platformio/penv/.espidf-5.1.2/bin/python (found version "3.12.3") found components: Interpreter 
-- Performing Test C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS
-- Performing Test C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS - Success
-- App "TC_SB" version: 1.0.2-222-g385436c7-dirty
-- Adding linker script /home/epoulsen/workspaces/tc/.pio/build/TCPLUS/esp-idf/esp_system/ld/memory.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_system/ld/esp32/sections.ld.in
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.api.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.newlib-data.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.syscalls.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/soc/esp32/ld/esp32.peripherals.ld
-- Components: KSZ8794ethChip MC2HardwareLib MC2ICs __pio_env app_trace app_update bootloader bootloader_support bt cmock console cxx driver efuse esp-tls esp_adc esp_app_format esp_bootloader_format esp_coex esp_common esp_eth esp_event esp_gdbstub esp_hid esp_http_client esp_http_server esp_https_ota esp_https_server esp_hw_support esp_lcd esp_local_ctrl esp_mm esp_netif esp_netif_stack esp_partition esp_phy esp_pm esp_psram esp_ringbuf esp_rom esp_system esp_timer esp_wifi espcoredump esptool_py fatfs freertos hal heap http_parser idf_test ieee802154 json log lwip mbedtls mqtt newlib nvs_flash nvs_sec_provider openthread partition_table perfmon protobuf-c protocomm pthread sdmmc soc spi_flash spiffs src ssr-hal tcp_transport ulp unity usb vfs wear_levelling wifi_provisioning wpa_supplicant xtensa
-- Component paths: /home/epoulsen/workspaces/tc/components/KSZ8794ethChip /home/epoulsen/workspaces/tc/components/MC2HardwareLib /home/epoulsen/workspaces/tc/components/MC2ICs /home/epoulsen/.platformio/packages/framework-espidf/components/__pio_env /home/epoulsen/.platformio/packages/framework-espidf/components/app_trace /home/epoulsen/.platformio/packages/framework-espidf/components/app_update /home/epoulsen/.platformio/packages/framework-espidf/components/bootloader /home/epoulsen/.platformio/packages/framework-espidf/components/bootloader_support /home/epoulsen/.platformio/packages/framework-espidf/components/bt /home/epoulsen/.platformio/packages/framework-espidf/components/cmock /home/epoulsen/.platformio/packages/framework-espidf/components/console /home/epoulsen/.platformio/packages/framework-espidf/components/cxx /home/epoulsen/.platformio/packages/framework-espidf/components/driver /home/epoulsen/.platformio/packages/framework-espidf/components/efuse /home/epoulsen/.platformio/packages/framework-espidf/components/esp-tls /home/epoulsen/.platformio/packages/framework-espidf/components/esp_adc /home/epoulsen/.platformio/packages/framework-espidf/components/esp_app_format /home/epoulsen/.platformio/packages/framework-espidf/components/esp_bootloader_format /home/epoulsen/.platformio/packages/framework-espidf/components/esp_coex /home/epoulsen/.platformio/packages/framework-espidf/components/esp_common /home/epoulsen/.platformio/packages/framework-espidf/components/esp_eth /home/epoulsen/.platformio/packages/framework-espidf/components/esp_event /home/epoulsen/.platformio/packages/framework-espidf/components/esp_gdbstub /home/epoulsen/.platformio/packages/framework-espidf/components/esp_hid /home/epoulsen/.platformio/packages/framework-espidf/components/esp_http_client /home/epoulsen/.platformio/packages/framework-espidf/components/esp_http_server /home/epoulsen/.platformio/packages/framework-espidf/components/esp_https_ota /home/epoulsen/.platformio/packages/framework-espidf/components/esp_https_server /home/epoulsen/.platformio/packages/framework-espidf/components/esp_hw_support /home/epoulsen/.platformio/packages/framework-espidf/components/esp_lcd /home/epoulsen/.platformio/packages/framework-espidf/components/esp_local_ctrl /home/epoulsen/.platformio/packages/framework-espidf/components/esp_mm /home/epoulsen/.platformio/packages/framework-espidf/components/esp_netif /home/epoulsen/.platformio/packages/framework-espidf/components/esp_netif_stack /home/epoulsen/.platformio/packages/framework-espidf/components/esp_partition /home/epoulsen/.platformio/packages/framework-espidf/components/esp_phy /home/epoulsen/.platformio/packages/framework-espidf/components/esp_pm /home/epoulsen/.platformio/packages/framework-espidf/components/esp_psram /home/epoulsen/.platformio/packages/framework-espidf/components/esp_ringbuf /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom /home/epoulsen/.platformio/packages/framework-espidf/components/esp_system /home/epoulsen/.platformio/packages/framework-espidf/components/esp_timer /home/epoulsen/.platformio/packages/framework-espidf/components/esp_wifi /home/epoulsen/.platformio/packages/framework-espidf/components/espcoredump /home/epoulsen/.platformio/packages/framework-espidf/components/esptool_py /home/epoulsen/.platformio/packages/framework-espidf/components/fatfs /home/epoulsen/.platformio/packages/framework-espidf/components/freertos /home/epoulsen/.platformio/packages/framework-espidf/components/hal /home/epoulsen/.platformio/packages/framework-espidf/components/heap /home/epoulsen/.platformio/packages/framework-espidf/components/http_parser /home/epoulsen/.platformio/packages/framework-espidf/components/idf_test /home/epoulsen/.platformio/packages/framework-espidf/components/ieee802154 /home/epoulsen/.platformio/packages/framework-espidf/components/json /home/epoulsen/.platformio/packages/framework-espidf/components/log /home/epoulsen/.platformio/packages/framework-espidf/components/lwip /home/epoulsen/.platformio/packages/framework-espidf/components/mbedtls /home/epoulsen/.platformio/packages/framework-espidf/components/mqtt /home/epoulsen/.platformio/packages/framework-espidf/components/newlib /home/epoulsen/.platformio/packages/framework-espidf/components/nvs_flash /home/epoulsen/.platformio/packages/framework-espidf/components/nvs_sec_provider /home/epoulsen/.platformio/packages/framework-espidf/components/openthread /home/epoulsen/.platformio/packages/framework-espidf/components/partition_table /home/epoulsen/.platformio/packages/framework-espidf/components/perfmon /home/epoulsen/.platformio/packages/framework-espidf/components/protobuf-c /home/epoulsen/.platformio/packages/framework-espidf/components/protocomm /home/epoulsen/.platformio/packages/framework-espidf/components/pthread /home/epoulsen/.platformio/packages/framework-espidf/components/sdmmc /home/epoulsen/.platformio/packages/framework-espidf/components/soc /home/epoulsen/.platformio/packages/framework-espidf/components/spi_flash /home/epoulsen/.platformio/packages/framework-espidf/components/spiffs /home/epoulsen/workspaces/tc/src /home/epoulsen/workspaces/tc/components/ssr-hal /home/epoulsen/.platformio/packages/framework-espidf/components/tcp_transport /home/epoulsen/.platformio/packages/framework-espidf/components/ulp /home/epoulsen/.platformio/packages/framework-espidf/components/unity /home/epoulsen/.platformio/packages/framework-espidf/components/usb /home/epoulsen/.platformio/packages/framework-espidf/components/vfs /home/epoulsen/.platformio/packages/framework-espidf/components/wear_levelling /home/epoulsen/.platformio/packages/framework-espidf/components/wifi_provisioning /home/epoulsen/.platformio/packages/framework-espidf/components/wpa_supplicant /home/epoulsen/.platformio/packages/framework-espidf/components/xtensa
-- Configuring done
-- Generating done
-- Build files have been written to: /home/epoulsen/workspaces/tc/.pio/build/TCPLUS

fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository: /home/epoulsen/.platformio/packages/framework-espidf/components/openthread/openthread/../../../.git/modules/components/openthread/openthread

-- Found Git: /usr/bin/git (found version "2.43.0") 
-- git rev-parse returned 'fatal: not a git repository (or any of the parent directories): .git'
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-gcc
-- Check for working C compiler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-gcc
-- Check for working C compiler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-g++
-- Check for working CXX compiler: /home/epoulsen/.platformio/packages/toolchain-xtensa-esp-elf/bin/xtensa-esp32-elf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- git rev-parse returned 'fatal: not a git repository (or any of the parent directories): .git'
-- Could not use 'git describe' to determine PROJECT_VER.
-- Building ESP-IDF components for target esp32
-- Project sdkconfig file /home/epoulsen/workspaces/tc/sdkconfig.TCPLUS
-- Compiler supported targets: xtensa-esp-elf
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of time_t
-- Check size of time_t - done
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/soc/esp32/ld/esp32.peripherals.ld
-- Bootloader project name: "bootloader" version: 1
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.api.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.libgcc.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom/esp32/ld/esp32.rom.newlib-funcs.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/bootloader/subproject/main/ld/esp32/bootloader.ld
-- Adding linker script /home/epoulsen/.platformio/packages/framework-espidf/components/bootloader/subproject/main/ld/esp32/bootloader.rom.ld
-- Components: bootloader bootloader_support efuse esp_app_format esp_bootloader_format esp_common esp_hw_support esp_rom esp_system esptool_py freertos hal log main micro-ecc newlib partition_table soc spi_flash xtensa
-- Component paths: /home/epoulsen/.platformio/packages/framework-espidf/components/bootloader /home/epoulsen/.platformio/packages/framework-espidf/components/bootloader_support /home/epoulsen/.platformio/packages/framework-espidf/components/efuse /home/epoulsen/.platformio/packages/framework-espidf/components/esp_app_format /home/epoulsen/.platformio/packages/framework-espidf/components/esp_bootloader_format /home/epoulsen/.platformio/packages/framework-espidf/components/esp_common /home/epoulsen/.platformio/packages/framework-espidf/components/esp_hw_support /home/epoulsen/.platformio/packages/framework-espidf/components/esp_rom /home/epoulsen/.platformio/packages/framework-espidf/components/esp_system /home/epoulsen/.platformio/packages/framework-espidf/components/esptool_py /home/epoulsen/.platformio/packages/framework-espidf/components/freertos /home/epoulsen/.platformio/packages/framework-espidf/components/hal /home/epoulsen/.platformio/packages/framework-espidf/components/log /home/epoulsen/.platformio/packages/framework-espidf/components/bootloader/subproject/main /home/epoulsen/.platformio/packages/framework-espidf/components/bootloader/subproject/components/micro-ecc /home/epoulsen/.platformio/packages/framework-espidf/components/newlib /home/epoulsen/.platformio/packages/framework-espidf/components/partition_table /home/epoulsen/.platformio/packages/framework-espidf/components/soc /home/epoulsen/.platformio/packages/framework-espidf/components/spi_flash /home/epoulsen/.platformio/packages/framework-espidf/components/xtensa
-- Configuring done
-- Generating done
-- Build files have been written to: /home/epoulsen/workspaces/tc/.pio/build/TCPLUS/bootloader

fatal: not a git repository (or any of the parent directories): .git
CMake Warning:
  Manually-specified variables were not used by the project:

    LEGACY_INCLUDE_COMMON_HEADERS



/home/epoulsen/.platformio/packages/tool-cmake/bin/cmake -DDATA_FILE=/home/epoulsen/workspaces/tc/.pio/build/TCPLUS/x509_crt_bundle -DSOURCE_FILE=/home/epoulsen/workspaces/tc/.pio/build/TCPLUS/x509_crt_bundle.S -DFILE_TYPE=BINARY -P /home/epoulsen/.platformio/packages/framework-espidf/tools/cmake/scripts/data_file_embed_asm.cmake
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
/home/epoulsen/.platformio/pack

If you don’t want anythign from the sdkconfig.defaults to apply in this case, try something with this technique:

I tried this, and it did work.

But is my understanding about environments and the sdkconfig files correct? e.g. that sdkconfig.defaults is just defaults, and an environment-specific config should override?