Skip to content

Fix BackendDispatcher syntax error and validate toolchain flags - #75

Open
swayam-2003 wants to merge 1 commit into
embeddedos-org:masterfrom
swayam-2003:fix/dispatch-and-toolchain-validation
Open

Fix BackendDispatcher syntax error and validate toolchain flags#75
swayam-2003 wants to merge 1 commit into
embeddedos-org:masterfrom
swayam-2003:fix/dispatch-and-toolchain-validation

Conversation

@swayam-2003

Copy link
Copy Markdown

Summary

  • Remove duplicate else in BackendDispatcher.configure() that caused a SyntaxError and blocked importing the package.
  • Unknown backends now raise RuntimeError consistently in configure()/build().
  • Validate toolchain.extra_cflags and toolchain.extra_ldflags as string lists so scalar YAML values cannot silently split into per-character flags.

Approach

Followed existing target-field validation patterns in config.py and regression tests in tests/unit/test_dispatch.py.

Testing

python -m pip install -e ".[dev]"
python -m pytest tests/unit/test_dispatch.py tests/ebuild/test_config_validation.py -v

21 tests passed locally.

DCO

Signed-off-by: Swayam Nayak 154440440+swayam-2003@users.noreply.github.com

Remove the duplicate else branch in configure() that made the module unimportable, and align unknown-backend handling with RuntimeError in build(). Validate toolchain extra_cflags/extra_ldflags as string lists so scalar YAML values cannot silently split into per-character flags.

Signed-off-by: Swayam Nayak <154440440+swayam-2003@users.noreply.github.com>
@swayam-2003
swayam-2003 requested a review from srpatcha as a code owner August 29, 2026 18:22
Copilot AI lite review requested due to automatic review settings August 29, 2026 18:22

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.

🟡 Changes recommended

Existing repo tests still assert ValueError for unknown backends and the build() error message currently presents a contradictory supported-backend list for ninja, so the test suite and messaging need alignment.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes a Python syntax error in BackendDispatcher.configure() that prevented importing the package, and tightens config parsing so toolchain flag fields are validated as lists of strings (avoiding accidental per-character flag splitting from scalar YAML values).

Changes:

  • Remove the duplicate else path in BackendDispatcher.configure() and standardize unknown/unhandled backend failures to raise RuntimeError in configure()/build().
  • Add toolchain.extra_cflags / toolchain.extra_ldflags validation in load_config to require list[str].
  • Add regression tests for toolchain flag type validation and document the behavior in the changelog.
File summaries
File Description
tests/ebuild/test_config_validation.py Adds regression tests ensuring toolchain flag fields are lists of strings.
ebuild/core/config.py Validates extra_cflags/extra_ldflags types before constructing ToolchainConfig.
ebuild/build/dispatch.py Fixes configure() syntax error and changes unknown/unhandled backend failures to RuntimeError.
CHANGELOG.md Documents the dispatcher import fix and new toolchain flag validation rules.
Review details

Suppressed comments (1)

ebuild/build/dispatch.py:131

  • configure() now raises RuntimeError for unhandled/unknown backends, but the existing tests/ebuild/test_dispatch.py::TestUnknownBackend suite still asserts ValueError for unknown backend names (e.g. bazel, gradle, scons). Unless those tests are intentionally deprecated, this change will break the default pytest run (pytest.ini discovers tests/**/test_*.py). Please update that test suite (and any docs/docstrings that still mention ValueError) to match the new exception type/contract.
        else:
            raise RuntimeError(
                f"BackendDispatcher cannot configure backend '{backend}'. "
                "This dispatcher only handles cmake, meson, and cargo "
                "(make/kbuild need no configure step). ebuild's own ninja "
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

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

Comment thread ebuild/build/dispatch.py
Comment on lines 181 to 185
else:
raise ValueError(
raise RuntimeError(
f"Unknown build backend '{backend}'. "
f"Supported backends: {', '.join(sorted(ALL_BACKENDS))}"
)
@srpatcha

Copy link
Copy Markdown
Member

The flags validation is the valuable half, and I confirmed it

extra_cflags: -O2 -Wall is the natural thing to write, and YAML gives you a string. ToolchainConfig annotates the field List[str] and nothing enforces it, so the string is passed straight through to code that iterates it:

YAML gives:        '-O2 -Wall'  (str)
iterating it:      ['-', 'O', '2', ' ', '-', 'W', 'a', 'l', ...]

Every character becomes a separate compiler flag. The build then fails with something about an unrecognised option -, which points at nothing the developer wrote. A type annotation is documentation, not a check, and this is the case that shows the difference.

Rejecting it at load with a message naming the field is right. It is the same treatment #73 gives a malformed packages: section, and the same class as several others in this repo: a value of the wrong shape silently accepted, and the consequence surfacing somewhere unrelated.

The dispatcher half is superseded

Three PRs fix the same SyntaxError: #66, #70 and this one. I have approved #66 — it came first and is the wider change. My own #70 I have marked superseded for the same reason.

Standardising on RuntimeError for unknown backends is correct and is what #66 does too, so that part lands either way.

What I would like

Rebase onto #66 and reduce this to the config.py validation plus its tests. That should be a small branch with no conflicts, and I will merge it — the flags bug is not fixed by #66 or by anything else open, and it is the piece that would otherwise be lost.

Worth extending while you are there, if you want: extra_ldflags and extra_cflags are not the only List[str] fields that a scalar would break. sources, includes, defines and depends on a target have the same shape, and sources: src/main.c is at least as easy to write as the list form.

Verification

Confirmed the scalar-splitting behaviour on current master with a direct YAML load. Not verified this branch merged — it conflicts with #66 in dispatch.py, which is the overlap described above.

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