[PATCH v5 12/13] scripts: generate_rust_analyzer.py: define scripts

Tamir Duberstein
2025-03-25T20:06:58Z

Generate rust-project.json entries for scripts written in Rust. This is
possible now that we have a definition for `std` built for the host.

Use `str::rstrip` for consistency.

Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Tested-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Fiona Behrens <me@kloenk.dev>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
scripts/generate_rust_analyzer.py | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index e3f1ec856ecf..5c0056c265bb 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -249,6 +249,20 @@ def generate_crates(
cfg=[],
)

+ scripts = srctree / "scripts"
+ with open(scripts / "Makefile") as f:
+ makefile = f.read()
+ for path in scripts.glob("*.rs"):
+ name = path.name.rstrip(".rs")
+ if f"{name}-rust" not in makefile:
+ continue
+ _script = append_crate(
+ name,
+ path,
+ deps=[host_std],
+ cfg=[],
+ )
+
def is_root_crate(build_file: pathlib.Path, target: str) -> bool:
try:
with open(build_file) as f:
@@ -267,7 +281,7 @@ def generate_crates(
for folder in extra_dirs:
for path in folder.rglob("*.rs"):
logging.info("Checking %s", path)
- name = path.name.replace(".rs", "")
+ name = path.name.rstrip(".rs")

# Skip those that are not crate roots.
if not is_root_crate(path.parent / "Makefile", name) and \

--
2.49.0