Skip to content

fix(ebuild): repair SyntaxError in dispatch.py and unify backend errors - #78

Open
prakhar7017 wants to merge 1 commit into
embeddedos-org:masterfrom
prakhar7017:fix/dispatch-syntax-error-merge-artifact
Open

fix(ebuild): repair SyntaxError in dispatch.py and unify backend errors#78
prakhar7017 wants to merge 1 commit into
embeddedos-org:masterfrom
prakhar7017:fix/dispatch-syntax-error-merge-artifact

Conversation

@prakhar7017

Copy link
Copy Markdown

Summary

Fix a syntax error in ebuild/build/dispatch.py caused by duplicate else: clauses in BackendDispatcher.configure().

The merge conflict left two different unknown-backend guards in the same if chain, causing ebuild build, ebuild configure, and ebuild clean to fail during import.

Changes

  • Removed the duplicated else: and consolidated the backend validation logic.
  • Added UnknownBackendError, inheriting from both ValueError and RuntimeError, to preserve the existing caller contracts.
  • Added explicit backend lists for each dispatcher operation:
    • CONFIGURE_BACKENDS
    • BUILD_BACKENDS
    • CLEAN_BACKENDS
  • Removed ninja from the configure no-op path so unsupported ninja configuration fails with an actionable error.
  • Kept ninja supported for clean, where no toolchain is required.
  • Added six regression tests covering:
    • Dual ValueError/RuntimeError inheritance
    • ninja rejection during configure
    • Actionable error message
    • Correct backend lists in error messages
    • clean("ninja") continuing to work
    • Existing cargo, make, and kbuild no-op behavior

Testing

Targeted tests

pytest tests/ebuild/test_dispatch.py tests/unit/test_dispatch.py
31 passed

## Problem

`ebuild/build/dispatch.py` does not parse. `BackendDispatcher.configure()`
carries two `else:` clauses attached to the same `if` chain:

    File "ebuild/build/dispatch.py", line 133
        else:
        ^^^^
    SyntaxError: invalid syntax

Every `ebuild` command that reaches the dispatcher imports this module, so
on master `ebuild build`, `ebuild configure` and `ebuild clean` all fail at
import, and pytest aborts collection with 2 errors before running anything.

The cause is a merge, not a typo. Two branches independently added an
unhandled-backend guard to `configure()` — one raising `ValueError` listing
`ALL_BACKENDS`, one raising `RuntimeError` with a ninja-specific hint. The
merge kept both bodies. Their two test suites survived as well and disagree:
`tests/ebuild/test_dispatch.py` expects `ValueError`, `tests/unit/test_dispatch.py`
expects `RuntimeError`.

Two further defects were preserved in the same chain:

- `configure()` listed `ninja` alongside make/kbuild as a silent no-op.
  `ebuild build` routes `backend: ninja` with no `targets` into the
  dispatcher (`commands.py`: `if resolved_backend != "ninja" or not
  cfg.targets`), which has no ninja configure step. Returning quietly there
  is the exact false-success the `RuntimeError` guard was written to stop.
- The `ValueError` message advertised `ALL_BACKENDS`, which contains
  `ninja`, so rejecting `ninja` produced a message naming `ninja` as
  supported.

## Fix

- Remove the duplicated `else:` and consolidate the two guards into one.
- Add `UnknownBackendError(ValueError, RuntimeError)`. Deriving from both
  keeps each pre-existing caller contract intact rather than silently
  dropping one, and it is load-bearing beyond the tests: `ebuild build`
  handles this through `except RuntimeError`, so a plain `ValueError` would
  reach the user as a traceback instead of a clean `exit 1`.
- Name the backends each step actually handles (`CONFIGURE_BACKENDS`,
  `BUILD_BACKENDS`, `CLEAN_BACKENDS`) and report those in the message, so it
  can no longer contradict the rejection. `clean` keeps `ninja`; it only
  removes a build directory and needs no toolchain.
- Drop `ninja` from the `configure()` no-op branch so it raises, carrying the
  actionable "requires 'targets' in build.yaml" hint.

Behaviour change: `BackendDispatcher.configure("ninja")` previously returned
None and now raises. Nothing in-tree relies on the old behaviour — the CLI
`configure` command routes ninja to `_configure_ninja_backend` before the
dispatcher is constructed.

## Testing

- `pytest tests/ebuild/test_dispatch.py tests/unit/test_dispatch.py` —
  31 passed. Both previously-conflicting suites pass unmodified.
- Full suite: 196 passed, 1 skipped, 11 failed. All 11 failures are
  pre-existing and unrelated (`_object_path` missing from `NinjaBackend`,
  initramfs integration, build-failure output); they were present before
  this change and are unaffected by it.
- End-to-end, a `build.yaml` with `backend: ninja` and no `targets`:

      [error] Unknown build backend 'ninja'. BackendDispatcher can
      configure: cargo, cmake, kbuild, make, meson. ebuild's own ninja
      backend is invoked directly rather than through BackendDispatcher,
      and requires 'targets' in build.yaml -- add targets or choose
      another backend.
      EXIT=1

  Clean message, correct exit code, no traceback.
- Six regression tests added covering the dual-inheritance contract, the
  ninja rejection, the actionable hint, the non-contradictory backend list,
  `clean("ninja")` still working, and cargo/make/kbuild remaining no-ops.

Signed-off-by: Prakhar Maheshwari <mpr@stordocktech.com>
Signed-off-by: Prakhar Maheshwari <prakharmaheshwari96@gmail.com>
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.

1 participant