Re: [PATCH v5 07/13] scripts: generate_rust_analyzer.py: avoid optional arguments

Tamir Duberstein
2025-04-01T13:35:01Z

On Tue, Apr 1, 2025 at 8:59 AM Daniel Almeida
<daniel.almeida@collabora.com> wrote:
>
> Hi Tamir,
>
> This patch looks good to me but,
>
> > On 25 Mar 2025, at 17:06, Tamir Duberstein <tamird@gmail.com> wrote:
> >
> > Make all arguments required to reduce the probability of incorrect
> > implicit behavior. Use keyword arguments for clarity.
> >
> > Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> > ---
> > scripts/generate_rust_analyzer.py | 90 +++++++++++++++++++++++++++------------
> > 1 file changed, 62 insertions(+), 28 deletions(-)
> >
> > diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> > index b37d8345486a..badcef4126cf 100755
> > --- a/scripts/generate_rust_analyzer.py
> > +++ b/scripts/generate_rust_analyzer.py
> > @@ -69,9 +69,10 @@ def generate_crates(
> > def build_crate(
> > display_name: str,
> > root_module: pathlib.Path,
> > + *,
> > deps: List[str],
> > - cfg: List[str] = [],
> > - is_workspace_member: bool = True,
> > + cfg: List[str],
> > + is_workspace_member: bool,
> > ) -> Crate:
> > return {
> > "display_name": display_name,
> > @@ -92,21 +93,34 @@ def generate_crates(
> > def append_crate(
> > display_name: str,
> > root_module: pathlib.Path,
> > + *,
> > deps: List[str],
> > - cfg: List[str] = [],
> > - is_workspace_member: bool = True,
> > + cfg: List[str],
> > ) -> None:
> > register_crate(
> > - build_crate(display_name, root_module, deps, cfg, is_workspace_member)
> > + build_crate(
> > + display_name,
> > + root_module,
> > + deps=deps,
> > + cfg=cfg,
> > + is_workspace_member=True,
> > + )
> > )
> >
> > def append_proc_macro_crate(
> > display_name: str,
> > root_module: pathlib.Path,
> > + *,
> > deps: List[str],
> > - cfg: List[str] = [],
> > + cfg: List[str],
> > ) -> None:
> > - crate = build_crate(display_name, root_module, deps, cfg)
> > + crate = build_crate(
> > + display_name,
> > + root_module,
> > + deps=deps,
> > + cfg=cfg,
> > + is_workspace_member=True,
> > + )
> > proc_macro_dylib_name = (
> > subprocess.check_output(
> > [
> > @@ -133,66 +147,75 @@ def generate_crates(
> >
> > def append_sysroot_crate(
> > display_name: str,
> > + *,
> > deps: List[str],
> > - cfg: List[str] = [],
> > + cfg: List[str],
> > ) -> None:
> > - append_crate(
> > - display_name,
> > - sysroot_src / display_name / "src" / "lib.rs",
> > - deps,
> > - cfg,
> > - is_workspace_member=False,
> > + register_crate(
> > + build_crate(
> > + display_name,
> > + sysroot_src / display_name / "src" / "lib.rs",
> > + deps=deps,
> > + cfg=cfg,
> > + is_workspace_member=False,
> > + )
> > )
>
> Why the change from append to register+build here? Maybe this change
> should be in another patch?

The reason is that `append_crate` has lost its `is_workspace_member`
parameter, so the only way to pass `False` now is to use
`build_crate`. I chose to remove the argument from `append_crate`
because the alternative would have introduced many instances of
`is_workspace_member=True`, which I judged to be less-good than this.

Cheers.
Tamir