Re: [PATCH v5 1/2] scripts: generate_rust_analyzer.py: add versioning infrastructure

From: Jesung Yang

Date: Sat May 02 2026 - 03:41:09 EST


On Thu, Apr 30, 2026 at 11:14 PM Tamir Duberstein <tamird@xxxxxxxxxx> wrote:
> On Thu, Apr 30, 2026 at 8:15 AM Jesung Yang via B4 Relay
> <devnull+y.j3ms.n.gmail.com@xxxxxxxxxx> wrote:
> >
> > +def map_ra_version_baseline(ra_version_output: str) -> RaVersionInfo:
> > + baselines = reversed(RaVersionInfo)
> > +
> > + version_match = re.search(r"\d+\.\d+\.\d+", ra_version_output)
> > + if version_match:
> > + version_string = version_match.group()
> > + found_version = tuple(map(int, version_string.split(".")))
> > +
> > + # `rust-analyzer --version` shows a different version string depending on how the binary
> > + # is built: it may print either the Rust version or the rust-analyzer version itself.
> > + # To distinguish between them, we leverage rust-analyzer's versioning convention.
> > + #
> > + # See:
> > + # - https://github.com/rust-lang/rust-analyzer/blob/fad5c3d2d642/xtask/src/dist.rs#L19-L21
> > + is_ra_version = version_string.startswith(("0.3", "0.4", "0.5"))
> > + if is_ra_version:
> > + for info in baselines:
> > + if found_version >= info.ra_version:
> > + return info
> > + else:
> > + for info in baselines:
> > + if found_version >= info.rust_version:
> > + return info
> > +
> > + date_match = re.search(r"\d{4}-\d{2}-\d{2}", ra_version_output)
> > + if date_match:
> > + found_date = datetime.strptime(date_match.group(), "%Y-%m-%d")
>
> datetime.strptime throws ValueError on invalid input; perhaps we can
> catch that instead of using a regex match.

I think we still need to use regex to extract the date substring, right?
Since `ra_version_output` is the uncleaned CLI output, `date.strptime`
would always fail if passed the whole string.

Best regards,
Jesung