Skip to content

fix(ebuild): validate toolchain extra_cflags/extra_ldflags at config load - #88

Merged
srpatcha merged 2 commits into
embeddedos-org:masterfrom
furqan72672:fix/toolchain-flag-validation
Sep 1, 2026
Merged

fix(ebuild): validate toolchain extra_cflags/extra_ldflags at config load#88
srpatcha merged 2 commits into
embeddedos-org:masterfrom
furqan72672:fix/toolchain-flag-validation

Conversation

@furqan72672

Copy link
Copy Markdown

Summary

load_config() now validates toolchain.extra_cflags and toolchain.extra_ldflags in build.yaml, rejecting non-list values and lists containing non-string items at config load time instead of letting them leak into toolchain resolution / build generation.

Type of Change

  • fix — Bug fix
  • test — Add or fix tests

Issue being addressed

toolchain.extra_cflags / extra_ldflags were accepted verbatim. A scalar string (e.g. extra_cflags: -mcpu=cortex-m4) would silently become a list of characters when the value is later treated as a sequence, producing malformed compiler arguments.

Approach

Validate the two fields the same way target flag fields (cflags, ldflags, sources, etc.) are already validated: require a list, and require every item to be a string, otherwise raise ConfigError. Failing fast at parse time is consistent with the existing parser behaviour.

Changes

  • Added _parse_toolchain_flag_list() in ebuild/core/config.py, mirroring the existing target-field validation style.
  • _parse_toolchain() now validates both flag fields before constructing ToolchainConfig.
  • Added 4 parametrized regression tests in tests/ebuild/test_config_validation.py covering scalar and non-string cases for both fields.

Testing

  • py -m pytest tests/ebuild/test_config_validation.py -q → 18 passed
  • py -m flake8 ebuild/core/config.py tests/ebuild/test_config_validation.py → no new violations (3 pre-existing E501s remain, unrelated)
  • py -m pytest tests/ebuild/test_smoke_imports.py -q → 45 passed, 1 failed (pre-existing SyntaxError in ebuild/build/dispatch.py, see below)

Pre-Submission Checklist

  • New tests added for new functionality
  • Commit message follows type(scope): description convention
  • DCO sign-off included
  • All existing tests pass — blocked by pre-existing dispatch.py issue

Additional Notes / Limitations

  • Behaviour change: existing build.yaml files that used a scalar string for these fields will now fail fast. Intentional, and consistent with the target flag fields.
  • While running the smoke import check I found a pre-existing defect in ebuild/build/dispatch.py (duplicate unreachable else: causing a SyntaxError at line 133). It is out of scope here and recorded in TASKS.md as T-002. It also surfaces a conflict between tests/ebuild/test_dispatch.py (expects ValueError) and tests/unit/test_dispatch.py (expects RuntimeError), which needs a design decision before it can be fixed.

toolchain.extra_cflags and toolchain.extra_ldflags were accepted as-is, so a scalar string silently became a list of characters when later treated as a sequence. Reject non-list values and non-string items during config loading, matching the existing validation for target flag fields.

Signed-off-by: Furqan Munir <furqan72672@gmail.com>
Copilot AI lite review requested due to automatic review settings August 30, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The changes are small, consistent with existing target-field validation patterns, and are covered by focused regression tests for the newly enforced constraints.

Pull request overview

This PR tightens configuration validation in load_config() by rejecting invalid toolchain.extra_cflags / toolchain.extra_ldflags values at parse time, preventing scalar strings (and other non-list / non-string cases) from later being misinterpreted as sequences and producing malformed compiler/linker arguments.

Changes:

  • Added _parse_toolchain_flag_list() to validate toolchain flag fields as list[str] and raise ConfigError on invalid input.
  • Updated _parse_toolchain() to use the new validation for extra_cflags and extra_ldflags.
  • Added parametrized regression tests ensuring both fields reject non-lists and lists containing non-strings.

Verification

  • Reviewer: NOT RUN (no tests or linters executed in this review).
  • Author-reported (from PR description): tests/ebuild/test_config_validation.py and tests/ebuild/test_smoke_imports.py were run; the remaining failure is described as pre-existing and out of scope.
File summaries
File Description
ebuild/core/config.py Adds parse-time validation for toolchain extra flag lists and wires it into toolchain parsing.
tests/ebuild/test_config_validation.py Adds regression coverage for invalid toolchain extra flag field types/contents.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

srpatcha
srpatcha previously approved these changes Sep 1, 2026
Copilot AI review requested due to automatic review settings September 1, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@srpatcha
srpatcha merged commit a9251f9 into embeddedos-org:master Sep 1, 2026
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