Re: [PATCH v7 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure
From: Tamir Duberstein
Date: Thu May 07 2026 - 12:24:22 EST
On Thu, 07 May 2026 23:47:24 +0900, Jesung Yang <y.j3ms.n@xxxxxxxxx> wrote:
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index d5f9a0ca742c..79c69004aed1 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -343,6 +346,161 @@ def generate_crates(
> [ ... skip 117 lines ... ]
> + .decode("utf-8")
> + .strip()
> + )
> + return ra_version_output
> + except FileNotFoundError:
> + return None
This needs to also catch subprocess.CalledProcessError because rustup
may provide the `rust-analyzer` binstub even when the component is not
installed:
% rustup component remove rust-analyzer
% which rust-analyzer
/opt/homebrew/opt/rustup/bin/rust-analyzer
% rust-analyzer --version
I can fix this on apply; this diff fixed the problem for me (includes
more correct warning logging):
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 8629dd186891..9dee5151cb45 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -531,7 +531,27 @@ def query_ra_version() -> Optional[str]:
)
return ra_version_output
except FileNotFoundError:
- return None
+ logging.warning(
+ "Failed to find rust-analyzer in $PATH; "
+ "falling back to `rust-project.json` for rust-analyzer "
+ "%s, %s (shipped with Rust %s)",
+ ".".join(map(str, RaVersionInfo.MSRV.ra_version)),
+ RaVersionInfo.MSRV.release_date,
+ ".".join(map(str, RaVersionInfo.MSRV.rust_version)),
+ )
+ except subprocess.CalledProcessError as exc:
+ logging.warning(
+ "Failed to query rust-analyzer version; "
+ "`rust-analyzer --version` exited with status %s; "
+ "falling back to `rust-project.json` for rust-analyzer "
+ "%s, %s (shipped with Rust %s)",
+ exc.returncode,
+ ".".join(map(str, RaVersionInfo.MSRV.ra_version)),
+ RaVersionInfo.MSRV.release_date,
+ ".".join(map(str, RaVersionInfo.MSRV.rust_version)),
+ )
+
+ return None
def map_ra_version_baseline(ra_version_output: str) -> RaVersionInfo:
baselines = list(reversed(RaVersionInfo))
@@ -596,18 +616,11 @@ def main() -> None:
)
ra_version_output = query_ra_version()
- if ra_version_output:
- compatible_ra_version = map_ra_version_baseline(ra_version_output)
- else:
- logging.warning(
- "Failed to find rust-analyzer in $PATH; " \
- "falling back to `rust-project.json` for rust-analyzer " \
- "%s, %s (shipped with Rust %s)",
- ".".join(map(str, RaVersionInfo.MSRV.ra_version)),
- RaVersionInfo.MSRV.release_date,
- ".".join(map(str, RaVersionInfo.MSRV.rust_version)),
- )
- compatible_ra_version = RaVersionInfo.MSRV
+ compatible_ra_version = (
+ map_ra_version_baseline(ra_version_output)
+ if ra_version_output is not None
+ else RaVersionInfo.MSRV
+ )
rust_project = generate_rust_project(
compatible_ra_version,
Reviewed-by: Tamir Duberstein <tamird@xxxxxxxxxx>
--
Tamir Duberstein <tamird@xxxxxxxxxx>