Skip to content

sof-builder: Add binary .tplg opening, versioned source resolution, and text editor enhancements - #9

Open
lgirdwood wants to merge 5 commits into
mainfrom
feat/sof-builder-tplg-text-editor
Open

lgirdwood wants to merge 5 commits into
mainfrom
feat/sof-builder-tplg-text-editor

Conversation

@lgirdwood

Copy link
Copy Markdown
Member

Summary

This draft PR adds binary .tplg opening/editing with ABI-matched source discovery and upgrades the Topology2 text editor in sof-builder:

  1. Platform feature .conf parsing & IncludeByKey expansion (parser.py, model.py, window.py)

    • Properly renders multi-pipeline platform feature topologies such as dmic-wov-multi.conf instead of empty pipeline containers.
  2. Binary .tplg opening, ABI version matching & full topology export (tplg_ipc4.py, tplg_binary.py, compiler.py, serializer.py, model.py, window.py)

    • Parses ALSA .tplg manifest headers and SOF ABI payloads (IPC4 <3H> and IPC3 <3B>).
    • Matches local topology2 checkouts by kernel/abi.h version and extracts read-only historical git archive snapshots under ~/.cache/sof-builder/versioned-sources/ when an exact local match is unavailable.
    • Identifies matching source .conf / CMake targets with structural & parameter diffs, or decompiles binary pipelines, widgets, routes, kcontrols, and PCMs into an editable graph while preserving decoded sof_abi_bytes on recompile.
  3. TopologyTextEditor core editing & font controls (text_editor.py, window.py)

    • Adds monospace font family dropdown, point-size SpinButton, Wrap toggle, and Ctrl++/Ctrl+-/Ctrl+0/Ctrl+Scroll zoom synced across tabs and persisted in ui_state.json.
    • Attaches a DrawingArea left line-number gutter, active-line background, and matching/mismatched bracket highlights preserved across syntax re-colorization.
    • Adds collapsible Find/Replace (Ctrl+F, Ctrl+H, F3/Shift+F3, case/regex toggles, atomic Replace All) and Go-to-Line (Ctrl+G) bars.
    • Adds auto-indent, multi-line Tab/Shift+Tab, Ctrl+/ line comment toggling, Ctrl+D duplicate line, Ctrl+Shift+K delete line, smart Home, pair typing/backspace, and context-aware Edit menu routing (Undo, Redo, Select All, Cut, Copy, Paste, Delete).

Testing

  • Verified py_compile across all modified Python modules.
  • Verified IPC4 (3.29.1) & IPC3 (3.22.1) binary version decoding, read-only git-snapshot resolution (3.28.0), and alsatplg round-trip recompilation preserving binary ABI bytes.
  • Verified standalone TopologyTextEditor unit checks and headless GTK4 Topology2MainWindow integration tests.

@lgirdwood
lgirdwood requested a balanced review from Copilot December 1, 2026 22:20
@lgirdwood

Copy link
Copy Markdown
Member Author

first commit is missing SOB and commit message.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical defects can silently drop or alter topology data during export, compile stale graphs after rejected edits, and overwrite cached historical sources.

15 open issues
What changed in this PR

Adds binary .tplg opening and export to sof-builder, with ABI-aware source discovery and editable graph reconstruction. It also improves platform topology parsing and the integrated text editor.

Changes:

  • Decode binary topology metadata, locate matching sources, and support full-topology export.
  • Expand conditional configuration parsing and handle file-local topology classes.
  • Add editor search/replace, navigation, editing shortcuts, highlighting, and synchronized font controls.
File Description
sof-builder/​sof_builder/​window.py Integrates binary tabs, export actions, and editor controls.
sof-builder/​sof_builder/​tplg_ipc4.py Decodes ABI metadata and additional topology fields.
sof-builder/​sof_builder/​tplg_binary.py Resolves versioned sources and reconstructs binary graphs.
sof-builder/​sof_builder/​text_editor.py Adds editing, search, navigation, and display features.
sof-builder/​sof_builder/​serializer.py Adds full-topology configuration serialization.
sof-builder/​sof_builder/​parser.py Expands conditional includes and file-local classes.
sof-builder/​sof_builder/​model.py Tracks binary provenance and discovers ABI-aware workspaces.
sof-builder/​sof_builder/​compiler.py Supports binary ABI preservation and explicit export paths.

Review effort: Balanced

Comment thread sof-builder/sof_builder/parser.py Resolved
Comment thread sof-builder/sof_builder/serializer.py Resolved
Comment thread sof-builder/sof_builder/serializer.py Resolved
Comment thread sof-builder/sof_builder/serializer.py Resolved
Comment thread sof-builder/sof_builder/serializer.py Resolved
Comment thread sof-builder/sof_builder/window.py Resolved
Comment thread sof-builder/sof_builder/window.py Resolved
Comment thread sof-builder/sof_builder/parser.py Resolved
Comment thread sof-builder/sof_builder/text_editor.py Resolved
Comment thread sof-builder/sof_builder/tplg_binary.py Resolved
…nsion

- parser.py: Expand inline IncludeByKey blocks via _expand_ast_children_inline() and _match_include_by_key(), evaluate integer arithmetic expressions in _eval_int_arith(), add _has_topology_objects() so files with both Class definitions and instantiated Object blocks render pipelines cleanly instead of short-circuiting to an empty class view, and finalize nested pipeline widgets/routes cleanly.
- model.py, window.py: Support passing a .conf file path directly on the CLI (discovering the enclosing topology2 workspace root in discover_topology2_dir() and opening the file in a tab on startup).

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
… topology export

- Parse ALSA .tplg manifest headers and SOF ABI version bytes (IPC4 <3H> and IPC3 <3B>) in tplg_ipc4.py and tplg_binary.py.
- Discover local topology2 checkouts by ABI version and fall back to read-only git archive snapshots cached under ~/.cache/sof-builder/versioned-sources/.
- Identify matching .conf source / CMake targets with structural & parameter diffing, or decompile binary pipelines/widgets/routes/controls/PCMs directly into an editable GraphViewModel.
- Preserve decoded binary SOF ABI bytes in compiler.py and serialize multi-pipeline topologies to compilable .conf in serializer.py.
- Add banner switching, binary/source open flows, and CLI .tplg loading in window.py.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
…enu support in text editor

- Add monospace font family dropdown, point-size SpinButton, Wrap toggle, and Ctrl++/Ctrl+-/Ctrl+0/Ctrl+Scroll zoom synced across tabs and persisted in ui_state.json.
- Attach a DrawingArea left line-number gutter synchronized with scroll and font metrics, plus current-line and matching bracket highlights preserved across syntax re-colorization.
- Add collapsible Find/Replace bar (Ctrl+F, Ctrl+H, F3/Shift+F3, regex/case toggles, atomic Replace All) and Go-to-Line bar (Ctrl+G).
- Add auto-indent on Return, multi-line Tab/Shift+Tab indent/outdent, Ctrl+/ line comment toggling, Ctrl+D duplicate line, Ctrl+Shift+K delete line, smart Home, and pair editing.
- Route Edit menu Undo/Redo/Select All/Cut/Copy/Paste/Delete and Find/Go-to-Line/Zoom actions to the active TopologyTextEditor in text mode.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
- parser.py, model.py: Isolate TplgClassDef copies via TplgClassDef.clone() before _resolve_pipeline_inheritance(), descend through non-Class conditional blocks in _has_topology_objects(), normalize parser DAI ConfigNode keys, and restore persisted # @sof-builder-manifest metadata.
- tplg_binary.py, tplg_ipc4.py: Normalize undecoded zero SOF ABI fields to None, mark extracted git snapshots read-only with is_versioned_snapshot_path(), compare both input/output audio formats in diff_binary_vs_source(), require all structural fingerprint sets and zero param_diffs for is_exact, fix DAI/pipeline DAPM direction hints, and restore decoded gain/src/asrc/component tokens.
- serializer.py: Prefer decoded bytes_hex over auto-default included_param_file, support parser-generated Object.PCM.pcm keys and quoted pcm_caps formats/rates, round-trip binary manifest metadata comments, and serialize Object.Dai.* sections.
- text_editor.py: Invalidate cached _search_matches immediately on buffer edits and match regex replace_current() against full buffer context for lookbehinds and backreferences.
- window.py: Guard Save against overwriting read-only git snapshots, prevent auto source substitution on format mismatches, restore tplg:source:/tplg:bin: tabs via .tplg path and mode, abort exports/compiles when text commit fails, and preserve binary provenance across text commits.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the feat/sof-builder-tplg-text-editor branch from 30eb7e6 to 1ebdfff Compare December 3, 2026 13:19
@lgirdwood
lgirdwood marked this pull request as ready for review December 3, 2026 20:50
@lgirdwood
lgirdwood requested a balanced review from Copilot December 3, 2026 20:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical reconstruction and serialization defects can silently lose binary settings, export stale topology, and rebuild tabs using another binary’s workspace and compiler.

13 open issues
13 resolved since last review

Review effort: Balanced

Comment thread sof-builder/sof_builder/serializer.py Resolved
Comment thread sof-builder/sof_builder/serializer.py Resolved
Comment thread sof-builder/sof_builder/serializer.py Resolved
Comment thread sof-builder/sof_builder/serializer.py Resolved
Comment thread sof-builder/sof_builder/serializer.py Resolved
Comment thread sof-builder/sof_builder/tplg_binary.py Resolved
Comment thread sof-builder/sof_builder/tplg_binary.py Resolved
Comment thread sof-builder/sof_builder/tplg_binary.py Resolved
Comment thread sof-builder/sof_builder/window.py Resolved
Comment thread sof-builder/sof_builder/window.py Resolved
- serializer.py, parser.py: Check prefer_full_topology before the disk-source fast path, insert/refresh # @sof-builder-manifest: headers across all save paths without duplicating stale lines, serialize CombineArrays pin audio formats and primitive array elements cleanly, preserve nested Object.Widget.pipeline scheduler settings on reparse, emit DAI default_hw_config_id, and unconditionally refresh DAI includes (SAI/UAOL).
- tplg_binary.py: Preserve sample_type and interleaving_style on decoded pin formats, swap reversed DAI_IN/DAI_OUT direction hints, reconstruct all hw_configs alongside default_hw_config_id, and compare gain/SRC/ASRC/kcontrol/bytes-control parameters (and sample_type/interleaving_style) in diff_binary_vs_source().
- window.py: Prevent auto source substitution whenever param_diffs is non-empty, insert/refresh manifest metadata when saving raw text buffers, track and restore resolved workspace/compiler per GraphTabPage, and execute .tplg export compilation asynchronously via GLib.idle_add.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.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.

3 participants