Fix BackendDispatcher syntax error and validate toolchain flags - #75
Fix BackendDispatcher syntax error and validate toolchain flags#75swayam-2003 wants to merge 1 commit into
Conversation
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>
There was a problem hiding this comment.
🟡 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
elsepath inBackendDispatcher.configure()and standardize unknown/unhandled backend failures to raiseRuntimeErrorinconfigure()/build(). - Add
toolchain.extra_cflags/toolchain.extra_ldflagsvalidation inload_configto requirelist[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 raisesRuntimeErrorfor unhandled/unknown backends, but the existingtests/ebuild/test_dispatch.py::TestUnknownBackendsuite still assertsValueErrorfor unknown backend names (e.g.bazel,gradle,scons). Unless those tests are intentionally deprecated, this change will break the defaultpytestrun (pytest.ini discoverstests/**/test_*.py). Please update that test suite (and any docs/docstrings that still mentionValueError) 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.
| else: | ||
| raise ValueError( | ||
| raise RuntimeError( | ||
| f"Unknown build backend '{backend}'. " | ||
| f"Supported backends: {', '.join(sorted(ALL_BACKENDS))}" | ||
| ) |
The flags validation is the valuable half, and I confirmed it
Every character becomes a separate compiler flag. The build then fails with something about an unrecognised option Rejecting it at load with a message naming the field is right. It is the same treatment #73 gives a malformed The dispatcher half is supersededThree PRs fix the same Standardising on What I would likeRebase onto #66 and reduce this to the Worth extending while you are there, if you want: VerificationConfirmed the scalar-splitting behaviour on current |
Summary
elseinBackendDispatcher.configure()that caused a SyntaxError and blocked importing the package.RuntimeErrorconsistently inconfigure()/build().toolchain.extra_cflagsandtoolchain.extra_ldflagsas string lists so scalar YAML values cannot silently split into per-character flags.Approach
Followed existing target-field validation patterns in
config.pyand regression tests intests/unit/test_dispatch.py.Testing
21 tests passed locally.
DCO
Signed-off-by: Swayam Nayak 154440440+swayam-2003@users.noreply.github.com