Skip to content

hw/gen: --format json, the generator's findings for tools - #144

Merged
teo1747 merged 4 commits into
mainfrom
feat/hwgen-json-diagnostics
Nov 13, 2026
Merged

teo1747 merged 4 commits into
mainfrom
feat/hwgen-json-diagnostics

Conversation

@teo1747

@teo1747 teo1747 commented Nov 12, 2026

Copy link
Copy Markdown
Member

What it adds

emb-hwgen validate, generate and check take --format json. The command then prints a single JSON document on standard output and nothing else. hw/schemas/diagnostics.schema.json defines the document. EmbLink Studio's first stage (S1) reads it, so the IDE never parses text.

{
  "tool": "emb-hwgen", "version": "0.1.0", "format": 1, "command": "validate",
  "status": "errors", "exit_code": 2, "files": [],
  "diagnostics": [
    {"severity": "error", "rule": "HW-002", "file": "boards/st/nucleo_f446re/board.yaml", "line": 26,
     "path": "console.baud", "message": "expected integer, found string 'fast'",
     "text": "boards/st/nucleo_f446re/board.yaml:26: console.baud: expected integer, found string 'fast'"}
  ]
}
  • status and exit_code:
    • ok (exit 0): warnings are still possible;
    • errors (exit 2): the descriptions are wrong;
    • stale (exit 1): check found outdated outputs or hardware facts outside a description;
    • internal-error (exit 3): the generator itself failed. The document carries the exception's type and message, and the traceback goes to stderr. The Python 3.11 crash (hw/gen, ci: the generator's clock errors on Python 3.10 and 3.11 #142) would have reached the IDE this way.
  • Findings:
    • each finding keeps its file, line, node path and message as separate fields, plus the original text line;
    • rule is HW-002, HW-001 or HW-003;
    • HW-003 findings carry the diff.
  • files lists what generate wrote, and boards counts what check checked.
  • format is the document's own version: a new field keeps it, and a changed or removed field bumps it.

Text output is unchanged.

How it's built and tested

  • One parser: findings are split from the existing HW-002 text (file:line: node.path: message) in one place, emb_hwgen/diagnostics.py.
  • Round-trip check: every error that the negative tests raise must rebuild exactly from its parts. That check found node paths containing a compatible (bindings.st,stm32f4-iwdg.class), which the pattern now allows.
  • Seven new tests (110 total) cover every status: OK with warnings, a located description error, generate's file list, stale output with its diff, a board root without boards/, an internal error, and Windows and HW-001 lines. Each document is validated against the schema with the in-tree validator.
  • Python 3.10: five tests fail there, the Fraction bug that hw/gen, ci: the generator's clock errors on Python 3.10 and 3.11 #142 fixes.
  • Docs: docs/engineering/hwgen.md documents the output, with an example taken from a real run, and the docs build passes.

Signed-off-by: teo1747 motsoujunior17@gmail.com

validate, generate and check take --format json: one JSON document on
standard output and nothing else, its shape in
hw/schemas/diagnostics.schema.json. It holds the status and exit code,
every finding with its file, line, node path and message apart (and
the line the text output prints), the rule it concerns (HW-001, HW-002,
HW-003), each outdated generated file's diff, the files written and
the boards checked. A failure of the generator itself, as the Python
3.11 one was, still yields a document (internal-error, exit status 3),
its trace on standard error. EmbLink Studio's first stage reads it.

The findings are taken apart from the HW-002 text in one place
(emb_hwgen/diagnostics.py); every error the negative tests raise must
come back whole from its parts, which found node paths holding a
compatible (bindings.st,stm32f4-iwdg.class). The Diagnostics tests check
each outcome's document against the schema. Text output is unchanged.

Signed-off-by: teo1747 <motsoujunior17@gmail.com>
@teo1747
teo1747 added this pull request to the merge queue Nov 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 13, 2026
@teo1747
teo1747 added this pull request to the merge queue Nov 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 13, 2026
@teo1747
teo1747 added this pull request to the merge queue Nov 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 13, 2026
@teo1747
teo1747 added this pull request to the merge queue Nov 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 13, 2026
@teo1747
teo1747 added this pull request to the merge queue Nov 13, 2026
@teo1747
teo1747 removed this pull request from the merge queue due to a manual request Nov 13, 2026
@teo1747
teo1747 added this pull request to the merge queue Nov 13, 2026
@teo1747
teo1747 removed this pull request from the merge queue due to a manual request Nov 13, 2026
…ostics

Signed-off-by: teo1747 <motsoujunior17@gmail.com>
Main checks every file's header since #143; this one was written
before it.

Signed-off-by: teo1747 <motsoujunior17@gmail.com>
Both changed emb-hwgen.py. Every command now writes through #146's
three-way writer (A126) and takes --format json, a board or a system
alike: an application's description validates and generates with a
document too, a merge conflict generate leaves is an HW-003 finding
(status stale, exit 1), and check reports its stale files as findings
in both formats and counts the systems it checked (the schema gains
'systems'). The text output prints each finding's line, then its diff.
hw/gen's 190 tests pass and check --strict is clean.

Signed-off-by: teo1747 <motsoujunior17@gmail.com>
@teo1747
teo1747 added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit 9b807e3 Nov 13, 2026
63 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.

1 participant