Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,8 @@ ifeq ($(strip $(SOF_SRC_DIR)),)
endif
ifeq ($(strip $(SOF_SRC_DIR)),)
SOF_CANDIDATES := \
$(WORK_DIR)/sof-dragon-fly/sof-testbench-upstream \
$(WORK_DIR)/sof/sof \
$(WORK_DIR)/sof \
$(WORK_DIR)/sof-dragon-fly/sof-arl \
$(WORK_DIR)/sof-arl/sof-testbench-upstream \
$(WORK_DIR)/sof-arl/sof
$(WORK_DIR)/sof/sof
SOF_SRC_DIR := $(firstword $(foreach d,$(SOF_CANDIDATES),$(if $(wildcard $(d)/Kconfig),$(abspath $(d)))))
endif

Expand Down
7 changes: 4 additions & 3 deletions sof-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ usage: sof-builder [-h] [-d] [--debug-file FILE] [initial_dir]

| Argument / Environment Variable | Description |
| :--- | :--- |
| `initial_dir` / `SOF_TOPOLOGY2_DIR` | Path to the SOF `tools/topology/topology2` directory to load on startup. |
| `SOF_ROOT` | Path to the root of an SOF repository checkout (used to locate `tools/topology/topology2`, `sof_versions.h`, and `sof-testbench4`). |
| `initial_dir` / `SOF_TOPOLOGY2_DIR` | Path to the `sof-topologies/topology2` (or legacy `sof/tools/topology/topology2`) directory to load on startup. |
| `SOF_TOPOLOGIES_DIR` | Path to a `sof-topologies` checkout (auto-detected via `west list sof-topologies` inside a west workspace). |
| `SOF_ROOT` | Path to the root of an SOF repository checkout (auto-detected via `west list sof` inside a west workspace). |
| `ALSATPLG` | Optional explicit path to the `alsatplg` binary (defaults to `PATH` or workspace build). |
| `SOF_TESTBENCH_BIN` | Optional explicit path to the `sof-testbench4` binary (defaults to `<SOF_ROOT>/tools/testbench/build_testbench/sof-testbench4` or `PATH`). |
| `SOF_TESTBENCH_BIN` | Optional explicit path to the `sof-testbench4` binary (defaults to `sof-testbench/build/sof-testbench4` or `PATH`). |
| `-d`, `--debug` | Enable action & command debug logging to `sof-builder-debug.log`. |
| `--debug-file FILE` | Write debug log output to `FILE`. |

Expand Down
23 changes: 17 additions & 6 deletions sof-builder/sof_builder/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
from dataclasses import dataclass, field
from typing import Dict, List, Optional, Tuple

from .model import GraphViewModel, debug_log_command, debug_log_line
from .model import (
GraphViewModel,
debug_log_command,
debug_log_line,
resolve_sof_and_workspace_roots,
)
from .serializer import generate_compilable_conf


Expand Down Expand Up @@ -409,8 +414,7 @@ def __init__(self, topology2_root: str, build_dir: Optional[str] = None):

def _find_alsatplg(self) -> str:
# Check ALSATPLG env var, workspace tools/bin/alsatplg, then PATH
sof_root = os.path.abspath(os.path.join(self.topology2_root, "..", "..", ".."))
workspace_root = os.path.abspath(os.path.join(sof_root, ".."))
_, workspace_root = resolve_sof_and_workspace_roots(self.topology2_root)
candidates = [
os.environ.get("ALSATPLG", ""),
os.path.join(workspace_root, "tools", "bin", "alsatplg"),
Expand All @@ -428,11 +432,18 @@ def _ensure_abi_conf(self) -> str:
return abi_path

get_abi = os.path.join(self.topology2_root, "get_abi.sh")
sof_root = os.path.abspath(os.path.join(self.topology2_root, "..", "..", ".."))
if os.path.isfile(get_abi) and os.path.isdir(os.path.join(sof_root, "src")):
sof_root, _ = resolve_sof_and_workspace_roots(self.topology2_root)
tplg_repo_root = os.path.abspath(os.path.join(self.topology2_root, ".."))
abi_source = ""
if sof_root and os.path.isdir(os.path.join(sof_root, "src")):
abi_source = sof_root
elif os.path.isfile(os.path.join(tplg_repo_root, "include", "kernel", "abi.h")):
abi_source = tplg_repo_root

if os.path.isfile(get_abi) and abi_source:
try:
res = subprocess.run(
[get_abi, sof_root, "ipc4"],
[get_abi, abi_source, "ipc4"],
capture_output=True,
text=True,
check=True,
Expand Down
2 changes: 1 addition & 1 deletion sof-builder/sof_builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def main(argv: Optional[List[str]] = None) -> int:
"initial_dir",
nargs="?",
default=None,
help="Optional path to tools/topology/topology2 directory (or set SOF_TOPOLOGY2_DIR / SOF_ROOT)",
help="Optional path to sof-topologies/topology2 directory (or set SOF_TOPOLOGY2_DIR / SOF_ROOT)",
)
parser.add_argument(
"-d",
Expand Down
131 changes: 131 additions & 0 deletions sof-builder/sof_builder/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass, field
import datetime
import os
import subprocess
import sys
import threading
import traceback
Expand Down Expand Up @@ -535,3 +536,133 @@ def redo(self, current_entry: GraphHistoryEntry) -> Optional[Tuple[GraphHistoryE
if self.on_history_changed:
self.on_history_changed()
return (next_entry, action_desc)


def _run_west_cmd(args: List[str], cwd: Optional[str] = None) -> str:
"""Run a west query command quietly and return stripped stdout, or ''."""
search_cwd = cwd if (cwd and os.path.isdir(cwd)) else os.path.dirname(os.path.abspath(__file__))
try:
res = subprocess.run(
["west", *args],
cwd=search_cwd,
capture_output=True,
text=True,
check=True,
timeout=3,
)
return res.stdout.strip()
except Exception:
return ""


def west_project_path(project: str, cwd: Optional[str] = None) -> str:
"""Return the absolute path of a west project, or '' if unavailable."""
out = _run_west_cmd(["list", "-f", "{abspath}", project], cwd=cwd)
return os.path.abspath(out) if out and os.path.isdir(out) else ""


def west_topdir(cwd: Optional[str] = None) -> str:
"""Return the west workspace top directory, or '' if not inside one."""
out = _run_west_cmd(["topdir"], cwd=cwd)
return os.path.abspath(out) if out and os.path.isdir(out) else ""


def resolve_sof_and_workspace_roots(topology2_root: str = "") -> Tuple[str, str]:
"""Resolve `(sof_root, workspace_root)` across west, standalone sof-topologies, and legacy sof layouts."""
sof_utils_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
sof_root = ""
for env_var in ("SOF_ROOT", "SOF_SRC_DIR"):
cand = os.environ.get(env_var, "").strip()
if cand and os.path.isdir(os.path.join(cand, "src")):
sof_root = os.path.abspath(cand)
break

query_cwd = topology2_root if (topology2_root and os.path.isdir(topology2_root)) else sof_utils_root
if not sof_root:
sof_root = west_project_path("sof", cwd=query_cwd) or west_project_path("sof", cwd=sof_utils_root)

workspace_root = west_topdir(cwd=query_cwd) or west_topdir(cwd=sof_utils_root)

if not sof_root and topology2_root:
norm_t2 = os.path.abspath(topology2_root)
# Legacy in-tree layout: <sof_root>/tools/topology/topology2
legacy_sof = os.path.abspath(os.path.join(norm_t2, "..", "..", ".."))
if os.path.isdir(os.path.join(legacy_sof, "src")):
sof_root = legacy_sof
else:
# Standalone sof-topologies layout: <workspace_root>/sof-topologies/topology2
tplg_repo_parent = os.path.abspath(os.path.join(norm_t2, "..", ".."))
sib_sof = os.path.join(tplg_repo_parent, "sof")
if os.path.isdir(os.path.join(sib_sof, "src")):
sof_root = sib_sof
if not workspace_root:
workspace_root = tplg_repo_parent

if not sof_root:
sib_sof = os.path.abspath(os.path.join(sof_utils_root, "..", "sof"))
if os.path.isdir(os.path.join(sib_sof, "src")):
sof_root = sib_sof

if not workspace_root:
if sof_root:
workspace_root = os.path.abspath(os.path.join(sof_root, ".."))
else:
workspace_root = os.path.abspath(os.path.join(sof_utils_root, ".."))

return (sof_root, workspace_root)


def discover_topology2_dir(initial_dir: Optional[str] = None, saved_dir: str = "") -> str:
"""Locate a topology2 directory across CLI arg, env vars, west workspace, and sibling repos."""
if initial_dir:
abs_init = os.path.abspath(initial_dir)
if os.path.isdir(abs_init):
return abs_init

candidates: List[str] = []
env_tplg2 = os.environ.get("SOF_TOPOLOGY2_DIR", "").strip()
if env_tplg2:
candidates.append(os.path.abspath(env_tplg2))
env_tplg_repo = os.environ.get("SOF_TOPOLOGIES_DIR", "").strip()
if env_tplg_repo:
candidates.append(os.path.abspath(os.path.join(env_tplg_repo, "topology2")))
env_sof = os.environ.get("SOF_ROOT", "").strip()
if env_sof:
candidates.append(os.path.abspath(os.path.join(env_sof, "tools", "topology", "topology2")))
if saved_dir:
candidates.append(saved_dir)

sof_utils_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
for cwd_probe in (os.getcwd(), sof_utils_root):
west_tplg = west_project_path("sof-topologies", cwd=cwd_probe)
if west_tplg:
candidates.append(os.path.join(west_tplg, "topology2"))
west_sof = west_project_path("sof", cwd=cwd_probe)
if west_sof:
candidates.append(os.path.join(west_sof, "tools", "topology", "topology2"))

# Check current working directory and ancestors
cur = os.path.abspath(os.getcwd())
for _ in range(5):
candidates.append(os.path.join(cur, "topology2"))
candidates.append(os.path.join(cur, "tools", "topology", "topology2"))
if os.path.basename(cur) == "topology2" and os.path.isdir(os.path.join(cur, "include")):
candidates.append(cur)
parent = os.path.dirname(cur)
if parent == cur:
break
cur = parent

# Check sibling checkouts relative to sof-utils root
pkg_root = os.path.abspath(os.path.join(sof_utils_root, ".."))
for sib in ("sof-topologies", "sof-topology"):
candidates.append(os.path.join(pkg_root, sib, "topology2"))
candidates.append(os.path.join(pkg_root, "sof", "tools", "topology", "topology2"))

for cand in candidates:
if cand and os.path.isdir(cand) and os.path.isdir(os.path.join(cand, "include")):
return cand
for cand in candidates:
if cand and os.path.isdir(cand):
return cand
return ""
18 changes: 12 additions & 6 deletions sof-builder/sof_builder/testbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
gi.require_version("Pango", "1.0")
from gi.repository import Gdk, GLib, Graphene, Gsk, Gtk, Pango

from .model import debug_log_command, debug_log_line
from .model import (
debug_log_command,
debug_log_line,
resolve_sof_and_workspace_roots,
)
from .tplg_ipc4 import (
SND_SOC_TPLG_TYPE_BYTES,
SND_SOC_TPLG_TYPE_ENUM,
Expand Down Expand Up @@ -2611,18 +2615,20 @@ def map_platform_to_tb_preset(platform_id: str) -> str:

def _find_testbench_bin(self) -> str:
sof_utils_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
sof_root = os.path.abspath(os.path.join(self.topology2_root, "..", "..", ".."))
workspace_root = os.path.abspath(os.path.join(sof_root, ".."))
sof_root, workspace_root = resolve_sof_and_workspace_roots(self.topology2_root)
candidates = [
os.environ.get("SOF_TESTBENCH_BIN", ""),
os.path.join(sof_utils_root, "sof-testbench", "build", "sof-testbench4"),
os.path.join(sof_utils_root, "build", "sof-testbench", "sof-testbench4"),
os.path.join(sof_root, "tools", "testbench", "build_testbench", "sof-testbench4"),
os.path.join(sof_root, "tools", "testbench", "build_testbench", "install", "bin", "sof-testbench4"),
os.path.join(sof_root, "build_testbench", "sof-testbench4"),
os.path.join(workspace_root, "tools", "bin", "sof-testbench4"),
shutil.which("sof-testbench4") or "",
]
if sof_root:
candidates.extend([
os.path.join(sof_root, "tools", "testbench", "build_testbench", "sof-testbench4"),
os.path.join(sof_root, "tools", "testbench", "build_testbench", "install", "bin", "sof-testbench4"),
os.path.join(sof_root, "build_testbench", "sof-testbench4"),
])
for c in candidates:
if c and os.path.isfile(c) and os.access(c, os.X_OK):
return c
Expand Down
59 changes: 14 additions & 45 deletions sof-builder/sof_builder/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
debug_log_action,
debug_log_command,
debug_log_line,
discover_topology2_dir,
resolve_sof_and_workspace_roots,
)
from .parser import Topology2Workspace
from .right_inspector import RightAttributeInspector
Expand Down Expand Up @@ -178,44 +180,8 @@ def __init__(self, app: Gtk.Application, initial_dir: Optional[str] = None):
self.load_topology2_directory(default_dir)

def _discover_default_topology2_dir(self, initial_dir: Optional[str] = None) -> str:
"""Locate a valid tools/topology/topology2 workspace directory without hardcoded user paths."""
if initial_dir:
abs_init = os.path.abspath(initial_dir)
if os.path.isdir(abs_init):
return abs_init
candidates: List[str] = []
env_tplg2 = os.environ.get("SOF_TOPOLOGY2_DIR", "").strip()
if env_tplg2:
candidates.append(os.path.abspath(env_tplg2))
env_sof = os.environ.get("SOF_ROOT", "").strip()
if env_sof:
candidates.append(os.path.abspath(os.path.join(env_sof, "tools", "topology", "topology2")))
if self._saved_topology2_dir:
candidates.append(self._saved_topology2_dir)

# Check current working directory and ancestors for an SOF checkout
cur = os.path.abspath(os.getcwd())
for _ in range(5):
candidates.append(os.path.join(cur, "tools", "topology", "topology2"))
if os.path.basename(cur) == "topology2" and os.path.isdir(os.path.join(cur, "include")):
candidates.append(cur)
parent = os.path.dirname(cur)
if parent == cur:
break
cur = parent

# Also check sibling SOF checkouts relative to the repository root
pkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
for sib in ("sof", "sof-arl/sof-arl", "sof-arl", "sof-ptl", "sof-tgl"):
candidates.append(os.path.join(pkg_root, sib, "tools", "topology", "topology2"))

for cand in candidates:
if cand and os.path.isdir(cand) and os.path.isdir(os.path.join(cand, "include")):
return cand
for cand in candidates:
if cand and os.path.isdir(cand):
return cand
return ""
"""Locate a valid topology2 workspace directory via west, env vars, or sibling checkouts."""
return discover_topology2_dir(initial_dir=initial_dir, saved_dir=self._saved_topology2_dir)

@property
def canvas(self) -> TopologyGraphCanvas:
Expand Down Expand Up @@ -546,17 +512,20 @@ def _collect_version_info(self) -> Dict[str, str]:
if (self.workspace and self.workspace.root_dir)
else self._discover_default_topology2_dir()
)
sof_root = (
os.environ.get("SOF_ROOT", "").strip()
or (os.path.abspath(os.path.join(tplg2_root, "..", "..", "..")) if tplg2_root else "")
)
sof_root, _ = resolve_sof_and_workspace_roots(tplg2_root)
sof_utils_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))

# 1. SOF Version
sof_ver_parts: List[str] = []
sof_ver_h_candidates = [
os.path.join(sof_root, "tools", "testbench", "build_testbench", "sof_ep", "build", "generated", "include", "sof_versions.h"),
os.path.join(sof_root, "build_testbench", "sof_ep", "build", "generated", "include", "sof_versions.h"),
os.path.join(sof_utils_root, "sof-testbench", "build", "sof_lib", "generated", "include", "sof_versions.h"),
os.path.join(sof_utils_root, "build", "sof-testbench", "sof_lib", "generated", "include", "sof_versions.h"),
]
if sof_root:
sof_ver_h_candidates.extend([
os.path.join(sof_root, "tools", "testbench", "build_testbench", "sof_ep", "build", "generated", "include", "sof_versions.h"),
os.path.join(sof_root, "build_testbench", "sof_ep", "build", "generated", "include", "sof_versions.h"),
])
for vh_path in sof_ver_h_candidates:
if os.path.isfile(vh_path):
try:
Expand Down Expand Up @@ -5004,7 +4973,7 @@ def _on_clear_compile_log_clicked(self, _btn: Gtk.Button) -> None:

def _on_open_dir_clicked(self, _btn: Gtk.Button) -> None:
dialog = Gtk.FileDialog.new()
dialog.set_title("Select tools/topology/topology2 Directory")
dialog.set_title("Select topology2 Directory")
dialog.select_folder(self, None, self._on_folder_selected)

def _on_folder_selected(self, dialog: Gtk.FileDialog, result: Gio.AsyncResult) -> None:
Expand Down
6 changes: 1 addition & 5 deletions sof-testbench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,9 @@ if(NOT SOF_SRC_DIR)
set(SOF_SRC_DIR "${_west_sof_dir}")
else()
foreach(_cand
"${CMAKE_CURRENT_SOURCE_DIR}/../../sof-dragon-fly/sof-testbench-upstream"
"${CMAKE_CURRENT_SOURCE_DIR}/../../sof/sof"
"${CMAKE_CURRENT_SOURCE_DIR}/../../sof"
"${CMAKE_CURRENT_SOURCE_DIR}/../../sof/sof"
"${CMAKE_CURRENT_SOURCE_DIR}/../sof"
"${CMAKE_CURRENT_SOURCE_DIR}/../../sof-dragon-fly/sof-arl"
"${CMAKE_CURRENT_SOURCE_DIR}/../../sof-arl/sof-testbench-upstream"
"${CMAKE_CURRENT_SOURCE_DIR}/../../sof-arl/sof"
)
if(EXISTS "${_cand}/Kconfig")
set(SOF_SRC_DIR "${_cand}")
Expand Down
Loading