Skip to content

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

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

lgirdwood wants to merge 3 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.

… 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>
@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 on lines +1556 to +1558
saved_pipelines = dict(self.pipeline_classes)
saved_modules = dict(self.processing_modules)
saved_bases = dict(self.base_classes)
Comment on lines +969 to +974
if pfile:
lines.append(f"{pad}\t<{pfile}>\n")
else:
bhex = str(ctrl_cfg.get_scalar("bytes_hex", "")).strip()
if bhex:
lines.append(f'{pad}\tObject.Base.data."1" {{\n{pad}\t\tbytes\t"{bhex}"\n{pad}\t}}\n')
# PCMs
pcm_blocks: List[str] = []
for ch in vm.root_config.children:
if ch.key.startswith("Object.PCM.pcm."):
pcm_section = f"\nObject.PCM.pcm [\n" + "\n".join(pcm_blocks) + "\n]\n" if pcm_blocks else ""
route_section = f"\nObject.Base.route [\n" + "\n".join(route_lines) + "\n]\n" if route_lines else ""

conf_text = f"""<searchdir:include>
\t"nvl"\t"platform/intel/ptl.conf"
}}{pipe_container_cls}{inline_cls_txt}

""" + pipelines_section + route_section + pcm_section
Comment on lines +2210 to +2212
fpath = primary_id if (primary_id and os.path.isfile(primary_id)) else source_file
if fpath and os.path.isfile(fpath):
tab = self.open_tplg_file_in_tab(fpath, force_mode="binary")
Comment on lines +3256 to +3257
if active.text_editor.is_modified_in_text:
active.text_editor.commit_to_diagram()
for st in stmts:
if st.key.startswith("Object."):
return True
if st.stmt_type == "block" and (st.key == "{}" or st.key.startswith("IncludeByKey.")):
Comment on lines +1009 to +1014
cur_slice = self.get_text()[s_off:e_off]
if self.regex_btn.get_active():
try:
replacement = pat.sub(rep_raw, cur_slice, count=1)
except re.error:
return False
"""Extract protocol, SOF ABI version, and ALSA manifest version from a parsed .tplg."""
return TplgBinaryVersionInfo(
ipc_protocol=str(getattr(tplg, "ipc_protocol", "") or ""),
sof_abi_major=getattr(tplg, "sof_abi_major", None),
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