4"""Search repository applications, examples, and unit-test targets."""
7from pathlib
import Path
9from ra8_apps
import _parse_desc, get_apps
11REPO_ROOT = Path(__file__).resolve().parents[2]
15def get_host_apps() -> list[dict[str, str]]:
16 """Discover host-side CMake applications."""
17 apps: list[dict[str, str]] = []
18 host_dir = REPO_ROOT /
"apps" /
"host"
19 if not host_dir.is_dir():
21 for cmake_file
in sorted(host_dir.rglob(
"CMakeLists.txt")):
22 app_dir = cmake_file.parent
24 desc = _parse_desc(str(app_dir))
or f
"Host application {name}"
30 "rel_dir": str(app_dir.relative_to(REPO_ROOT)),
37def _find_matching_tests(query: str) -> list[str]:
38 """Return sorted unit-test basenames containing the query."""
40 tests_dir = REPO_ROOT /
"tests"
41 for suffix
in (
"c",
"cpp"):
42 for path
in tests_dir.rglob(f
"test_*.{suffix}"):
44 if query
in test_name.lower():
45 tests.append(test_name)
51 apps: list[dict[str, str]],
52 examples: list[dict[str, str]],
55 """Render grouped search results and their canonical Just commands."""
56 total = len(apps) + len(examples) + len(tests)
58 print(f
"No results found for '{query}'.")
61 print(f
"Search Results for '{query}' ({total} matches):\n")
63 print(f
"APPS ({len(apps)}):")
66 print(f
" {a['desc']}")
67 if a[
"group"] ==
"host":
68 print(f
" just apps::host::build {name}")
70 print(f
" just apps::build {name}")
71 print(f
" just apps::hardware::flash {name}")
72 print(f
" just apps::emulator::run {name}")
76 print(f
"\n[ EXAMPLES ] ({len(examples)} matches)")
79 print(f
" {a['desc']} ({name})")
80 print(f
" just apps::build {name}")
81 print(f
" just apps::hardware::flash {name}")
82 print(f
" just apps::emulator::run {name}")
86 print(f
"TESTS ({len(tests)}):")
89 print(f
" just tests::local {t}")
94 """Search all supported repository target classes."""
95 if len(sys.argv) < MIN_ARGUMENTS:
96 print(
"Usage: just search <keyword>")
99 query = sys.argv[1].lower()
103 for a
in get_apps() + get_host_apps():
104 full_id = f
"{a['group'].replace('/', '::')}::{a['name']}".lower()
105 desc = a[
"desc"].lower()
106 if query
in full_id
or query
in desc
or query
in a[
"name"].lower():
107 if "board/stand_alone" in a[
"group"]
or "host" in a[
"group"]:
112 tests = _find_matching_tests(query)
113 _print_results(query, apps, examples, tests)
116if __name__ ==
"__main__":
void main(void)
The application entry point Reset_Handler hands control to.