Skip to content

refactor platformio.ini to eliminate copy-paste duplication#5544

Merged
netmindz merged 2 commits intowled:mainfrom
netmindz:platformio-de-duplication
May 2, 2026
Merged

refactor platformio.ini to eliminate copy-paste duplication#5544
netmindz merged 2 commits intowled:mainfrom
netmindz:platformio-de-duplication

Conversation

@netmindz
Copy link
Copy Markdown
Member

@netmindz netmindz commented Apr 26, 2026

Centralise platform, platform_packages, build_unflags, lib_deps and monitor_filters into the per-chipset abstract sections ([esp8266], [esp32], [esp32s2], [esp32c3], [esp32s3]) and have concrete envs inherit via extends rather than repeating the same values.

  • [esp8266]: add platform, platform_packages, monitor_filters
  • [esp32]: add monitor_filters
  • [esp32s2]: add monitor_filters
  • [esp32c3]: add monitor_filters
  • [esp32s3]: add upload_speed, monitor_filters
  • esp8266 envs (nodemcuv2, esp8266_2m, esp01_1m_full): extends = esp8266
  • esp32dev: extends = esp32
  • esp32dev_8M, esp32dev_16M: extends = env:esp32dev
  • esp32_eth, usermods: extends = esp32 / env:esp32dev
  • esp32_wrover: drop redundant build_unflags, lib_deps (already extends esp32_idf_V4)
  • esp32c3dev: drop redundant platform, platform_packages, framework, build_unflags, lib_deps, board_build.partitions (already extends esp32c3)
  • esp32s3 envs: extends = esp32s3
  • lolin_s2_mini: extends = esp32s2

No functional changes. Verified with pio run across all five chipset families (ESP8266, ESP32, C3, S3, S2).

Summary by CodeRabbit

  • Refactor

    • Consolidated build environment configs to use shared platform groups for ESP8266, ESP32, ESP32-S2, ESP32-S3, and ESP32-C3, reducing duplication.
    • Centralized monitor filter settings and standardized inheritance across environments.
  • Chores

    • Increased default upload speed for ESP32-S3 devices.
    • Updated sample override templates to explicitly reference ESP8266 platform/package variables.

Centralise platform, platform_packages, build_unflags, lib_deps and
monitor_filters into the per-chipset abstract sections ([esp8266],
[esp32], [esp32s2], [esp32c3], [esp32s3]) and have concrete envs
inherit via extends rather than repeating the same values.

- [esp8266]: add platform, platform_packages, monitor_filters
- [esp32]: add monitor_filters
- [esp32s2]: add monitor_filters
- [esp32c3]: add monitor_filters
- [esp32s3]: add upload_speed, monitor_filters
- esp8266 envs (nodemcuv2, esp8266_2m, esp01_1m_full): extends = esp8266
- esp32dev: extends = esp32
- esp32dev_8M, esp32dev_16M: extends = env:esp32dev
- esp32_eth, usermods: extends = esp32 / env:esp32dev
- esp32_wrover: drop redundant build_unflags, lib_deps (already extends esp32_idf_V4)
- esp32c3dev: drop redundant platform, platform_packages, framework,
  build_unflags, lib_deps, board_build.partitions (already extends esp32c3)
- esp32s3 envs: extends = esp32s3
- lolin_s2_mini: extends = esp32s2

No functional changes. Verified with pio run across all five chipset
families (ESP8266, ESP32, C3, S3, S2).
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 26, 2026

Walkthrough

Centralizes monitor_filters and shared platform settings into platform groups ([esp8266], [esp32], [esp32s2], [esp32c3], [esp32s3]) and refactors many build environments to inherit via extends; updates sample override templates to reference the new esp8266 variables.

Changes

PlatformIO configuration refactor

Layer / File(s) Summary
Platform group defaults
platformio.ini ([esp8266], [esp32], [esp32s2], [esp32c3], [esp32s3])
Add centralized monitor_filters entries for ESP exception decoders; add upload_speed = 921600 to [esp32s3]; define shared platform_wled_default / platform_packages for esp8266 group.
Environment inheritance (core)
platformio.ini ([env:nodemcuv2], [env:esp8266_2m], [env:esp01_1m_full], [env:esp32dev], [env:esp32dev_8M], [env:esp32dev_16M], [env:esp32_eth], [env:esp32c3dev], [env:esp32s3dev_16MB_opi], [env:esp32s3dev_8MB_opi], [env:esp32S3_wroom2], [env:esp32s3_4M_qspi], [env:lolin_s2_mini], [env:usermods], ...)
Replace duplicated per-environment platform, platform_packages, platform_packages.*, build_unflags, lib_deps, monitor_filters, and repeated upload_speed with extends = <platform-group> or extends = env:<parent> and keep only env-specific build_flags/board overrides.
Wiring / sample overrides
platformio_override.sample.ini (multiple [env:*] esp8266 stanzas)
Switch sample override variables from ${common.platform_wled_default} / ${common.platform_packages} to ${esp8266.platform_wled_default} / ${esp8266.platform_packages} in many ESP8266 example env blocks.
Documentation / manifest metadata
platformio.ini, platformio_override.sample.ini
Update comments and sample wiring inline with the new inheritance/variable usage.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • softhack007
  • DedeHai
  • willmmiles
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main objective of the changeset—eliminating copy-paste duplication in platformio.ini by centralizing repeated settings and using PlatformIO's inheritance model.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread platformio.ini
lib_deps =
${esp32_idf_V4.lib_deps}
board_build.partitions = ${esp32.large_partitions} ;; default partioning for 8MB flash - can be overridden in build envs
upload_speed = 921600
Copy link
Copy Markdown
Member

@softhack007 softhack007 Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe comment out the upload speed flag. 920kbaud might be too much for boards where the UART-to-USB module gets connected by flimsy dupond wires only.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My $0.02, but I'd prefer to default to the higher speed -- it's much more convenient and failures are easily caught. If a user is doing a custom build and needs to lower the speed, it's straightforward to do in the override file. Try the fast speed first and lower if you have to, instead of the other way around.

(AFAIK these settings don't affect users using the web installer or the like -- just people doing custom builds.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you have no value?

@softhack007
Copy link
Copy Markdown
Member

softhack007 commented Apr 27, 2026

@netmindz I generally like the idea to use "extends = " for reducing the number of copied entries in buildenvs. Actually, I've proposed a similar approach some time ago, but then there was user feedback that people prefer to see "full entries", and "extends = " also created new pitfalls and makes it harder to understand which flags are actually passed to the compiler.

Not sure if this has changed in the meantime?

Comment thread platformio.ini Outdated
Comment on lines +195 to +196
platform = ${common.platform_wled_default}
platform_packages = ${common.platform_packages}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move all the ESP8266 platform definitions in to this section instead of common, since they're not common for all environments. Yes, this will potentially be a breaking change for user platformio_override.ini files for anyone building custom ESP8266 environments; I think that's reasonable for 17.0, to keep our definitions clean (and prepare for a proper HAL).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now is the time to break things, at the very start of the development cycle

Comment thread platformio.ini
lib_deps =
${esp32_idf_V4.lib_deps}
board_build.partitions = ${esp32.large_partitions} ;; default partioning for 8MB flash - can be overridden in build envs
upload_speed = 921600
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My $0.02, but I'd prefer to default to the higher speed -- it's much more convenient and failures are easily caught. If a user is doing a custom build and needs to lower the speed, it's straightforward to do in the override file. Try the fast speed first and lower if you have to, instead of the other way around.

(AFAIK these settings don't affect users using the web installer or the like -- just people doing custom builds.)

@netmindz
Copy link
Copy Markdown
Member Author

netmindz commented May 2, 2026

@netmindz I generally like the idea to use "extends = " for reducing the number of copied entries in buildenvs. Actually, I've proposed a similar approach some time ago, but then there was user feedback that people prefer to see "full entries", and "extends = " also created new pitfalls and makes it harder to understand which flags are actually passed to the compiler.

Not sure if this has changed in the meantime?

I think it's fine so long as we keep it to just one (2 at max) levels of extends. Most things defined at the chipset level, the env is then only setting things like the custom_usermods, filesystem size and not much else really. We no longer need to mess about with lib_deps and build_flags for usermods, so if you really are a power user enough to want to pass custom compiler flags, you should be able to follow some fairly basic ini file settings

Per review feedback: platform_wled_default, platform_packages, and the
arduino_core_* aliases are ESP8266-specific and don't belong in [common].
Note: this is a breaking change for custom platformio_override.ini files
that reference ${common.platform_wled_default} or ${common.platform_packages};
those should be updated to use the ${esp8266.*} prefix.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
platformio.ini (1)

160-651: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Maintainer approval is required before merge for this file.

This platformio.ini refactor looks consistent, but it must receive explicit maintainer/WLED-org approval before merging (global build config gate).

As per coding guidelines: “Modifications to platformio.ini must be explicitly approved by a maintainer or WLED organization member” and “Changes to platformio.ini require maintainer approval”.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@platformio.ini` around lines 160 - 651, This change modifies global build
configuration in platformio.ini (sections like [esp8266], platform_wled_default,
build_flags, and various [env:*] entries) and therefore requires explicit
maintainer/WLED-org approval before merging; get a named maintainer to review
and add an explicit approval comment or GitHub review approval on the PR, update
the PR description to call out "platformio.ini changes require maintainer
approval" and reference the maintainer's sign-off, and do not merge until that
approval is present.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@platformio.ini`:
- Around line 160-651: This change modifies global build configuration in
platformio.ini (sections like [esp8266], platform_wled_default, build_flags, and
various [env:*] entries) and therefore requires explicit maintainer/WLED-org
approval before merging; get a named maintainer to review and add an explicit
approval comment or GitHub review approval on the PR, update the PR description
to call out "platformio.ini changes require maintainer approval" and reference
the maintainer's sign-off, and do not merge until that approval is present.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b74fa100-3d15-43da-b2ec-b9b042a39063

📥 Commits

Reviewing files that changed from the base of the PR and between e37707d and 988254b.

📒 Files selected for processing (2)
  • platformio.ini
  • platformio_override.sample.ini

@netmindz netmindz merged commit d00dbac into wled:main May 2, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants