mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
scripts: generate_rust_analyzer.py: drop "is_proc_macro": false
Add a dedicated `append_proc_macro_crate` function to reduce overloading in `append_crate`. This has the effect of removing `"is_proc_macro": false` from the output; this field is interpreted as false if absent[1] so this doesn't change the behavior of rust-analyzer. Use the `/` operator on `pathlib.Path` rather than directly crafting a string. This is consistent with all other path manipulation in this script. Link: https://github.com/rust-lang/rust-analyzer/blob/8d01570b5e812a49daa1f08404269f6ea5dd73a1/crates/project-model/src/project_json.rs#L372-L373 [1] Tested-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com> Reviewed-by: Trevor Gross <tmgross@umich.edu> Reviewed-by: Jesung Yang <y.j3ms.n@gmail.com> Tested-by: Jesung Yang <y.j3ms.n@gmail.com> Link: https://patch.msgid.link/20260122-rust-analyzer-types-v1-2-29cc2e91dcd5@kernel.org Signed-off-by: Tamir Duberstein <tamird@kernel.org>
This commit is contained in:
@@ -42,20 +42,17 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
|
||||
*,
|
||||
cfg,
|
||||
is_workspace_member,
|
||||
is_proc_macro,
|
||||
edition,
|
||||
):
|
||||
cfg = cfg if cfg is not None else []
|
||||
is_workspace_member = (
|
||||
is_workspace_member if is_workspace_member is not None else True
|
||||
)
|
||||
is_proc_macro = is_proc_macro if is_proc_macro is not None else False
|
||||
edition = edition if edition is not None else "2021"
|
||||
crate = {
|
||||
return {
|
||||
"display_name": display_name,
|
||||
"root_module": str(root_module),
|
||||
"is_workspace_member": is_workspace_member,
|
||||
"is_proc_macro": is_proc_macro,
|
||||
"deps": [{"crate": crates_indexes[dep], "name": dep} for dep in deps],
|
||||
"cfg": cfg,
|
||||
"edition": edition,
|
||||
@@ -63,13 +60,47 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
|
||||
"RUST_MODFILE": "This is only for rust-analyzer"
|
||||
}
|
||||
}
|
||||
if is_proc_macro:
|
||||
proc_macro_dylib_name = subprocess.check_output(
|
||||
[os.environ["RUSTC"], "--print", "file-names", "--crate-name", display_name, "--crate-type", "proc-macro", "-"],
|
||||
|
||||
def append_proc_macro_crate(
|
||||
display_name,
|
||||
root_module,
|
||||
deps,
|
||||
*,
|
||||
cfg=None,
|
||||
is_workspace_member=None,
|
||||
edition=None,
|
||||
):
|
||||
crate = build_crate(
|
||||
display_name,
|
||||
root_module,
|
||||
deps,
|
||||
cfg=cfg,
|
||||
is_workspace_member=is_workspace_member,
|
||||
edition=edition,
|
||||
)
|
||||
proc_macro_dylib_name = (
|
||||
subprocess.check_output(
|
||||
[
|
||||
os.environ["RUSTC"],
|
||||
"--print",
|
||||
"file-names",
|
||||
"--crate-name",
|
||||
display_name,
|
||||
"--crate-type",
|
||||
"proc-macro",
|
||||
"-",
|
||||
],
|
||||
stdin=subprocess.DEVNULL,
|
||||
).decode('utf-8').strip()
|
||||
crate["proc_macro_dylib_path"] = f"{objtree}/rust/{proc_macro_dylib_name}"
|
||||
return crate
|
||||
)
|
||||
.decode("utf-8")
|
||||
.strip()
|
||||
)
|
||||
proc_macro_crate = {
|
||||
**crate,
|
||||
"is_proc_macro": True,
|
||||
"proc_macro_dylib_path": str(objtree / "rust" / proc_macro_dylib_name),
|
||||
}
|
||||
return register_crate(proc_macro_crate)
|
||||
|
||||
def register_crate(crate):
|
||||
crates_indexes[crate["display_name"]] = len(crates)
|
||||
@@ -82,7 +113,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
|
||||
*,
|
||||
cfg=None,
|
||||
is_workspace_member=None,
|
||||
is_proc_macro=None,
|
||||
edition=None,
|
||||
):
|
||||
return register_crate(
|
||||
@@ -92,7 +122,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
|
||||
deps,
|
||||
cfg=cfg,
|
||||
is_workspace_member=is_workspace_member,
|
||||
is_proc_macro=is_proc_macro,
|
||||
edition=edition,
|
||||
)
|
||||
)
|
||||
@@ -172,11 +201,10 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
|
||||
cfg=crates_cfgs["syn"],
|
||||
)
|
||||
|
||||
append_crate(
|
||||
append_proc_macro_crate(
|
||||
"macros",
|
||||
srctree / "rust" / "macros" / "lib.rs",
|
||||
["std", "proc_macro", "proc_macro2", "quote", "syn"],
|
||||
is_proc_macro=True,
|
||||
)
|
||||
|
||||
append_crate(
|
||||
@@ -185,12 +213,11 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
|
||||
["core", "compiler_builtins"],
|
||||
)
|
||||
|
||||
append_crate(
|
||||
append_proc_macro_crate(
|
||||
"pin_init_internal",
|
||||
srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs",
|
||||
["std", "proc_macro", "proc_macro2", "quote", "syn"],
|
||||
cfg=["kernel"],
|
||||
is_proc_macro=True,
|
||||
)
|
||||
|
||||
append_crate(
|
||||
@@ -216,7 +243,6 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs, core_edit
|
||||
deps,
|
||||
cfg=cfg,
|
||||
is_workspace_member=True,
|
||||
is_proc_macro=False,
|
||||
edition=None,
|
||||
)
|
||||
crate["env"]["OBJTREE"] = str(objtree.resolve(True))
|
||||
|
||||
Reference in New Issue
Block a user