ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
search.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# SPDX-License-Identifier: MIT
3# Copyright (c) 2026 Brighton Sikarskie
4"""Search repository applications, examples, and unit-test targets."""
5
6import sys
7from pathlib import Path
8
9from ra8_apps import _parse_desc, get_apps
10
11REPO_ROOT = Path(__file__).resolve().parents[2]
12MIN_ARGUMENTS = 2
13
14
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():
20 return apps
21 for cmake_file in sorted(host_dir.rglob("CMakeLists.txt")):
22 app_dir = cmake_file.parent
23 name = app_dir.name
24 desc = _parse_desc(str(app_dir)) or f"Host application {name}"
25 apps.append(
26 {
27 "name": name,
28 "group": "host",
29 "dir": str(app_dir),
30 "rel_dir": str(app_dir.relative_to(REPO_ROOT)),
31 "desc": desc,
32 }
33 )
34 return apps
35
36
37def _find_matching_tests(query: str) -> list[str]:
38 """Return sorted unit-test basenames containing the query."""
39 tests: list[str] = []
40 tests_dir = REPO_ROOT / "tests"
41 for suffix in ("c", "cpp"):
42 for path in tests_dir.rglob(f"test_*.{suffix}"):
43 test_name = path.stem
44 if query in test_name.lower():
45 tests.append(test_name)
46 return sorted(tests)
47
48
49def _print_results(
50 query: str,
51 apps: list[dict[str, str]],
52 examples: list[dict[str, str]],
53 tests: list[str],
54) -> None:
55 """Render grouped search results and their canonical Just commands."""
56 total = len(apps) + len(examples) + len(tests)
57 if total == 0:
58 print(f"No results found for '{query}'.")
59 return
60
61 print(f"Search Results for '{query}' ({total} matches):\n")
62 if apps:
63 print(f"APPS ({len(apps)}):")
64 for a in apps:
65 name = a["name"]
66 print(f" {a['desc']}")
67 if a["group"] == "host":
68 print(f" just apps::host::build {name}")
69 else:
70 print(f" just apps::build {name}")
71 print(f" just apps::hardware::flash {name}")
72 print(f" just apps::emulator::run {name}")
73 print()
74
75 if examples:
76 print(f"\n[ EXAMPLES ] ({len(examples)} matches)")
77 for a in examples:
78 name = a["name"]
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}")
83 print()
84
85 if tests:
86 print(f"TESTS ({len(tests)}):")
87 for t in tests:
88 print(f" {t}")
89 print(f" just tests::local {t}")
90 print()
91
92
93def main() -> None:
94 """Search all supported repository target classes."""
95 if len(sys.argv) < MIN_ARGUMENTS:
96 print("Usage: just search <keyword>")
97 sys.exit(1)
98
99 query = sys.argv[1].lower()
100 apps = []
101 examples = []
102
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"]:
108 apps.append(a)
109 else:
110 examples.append(a)
111
112 tests = _find_matching_tests(query)
113 _print_results(query, apps, examples, tests)
114
115
116if __name__ == "__main__":
117 main()
void main(void)
The application entry point Reset_Handler hands control to.
Definition main.c:298