scripts: read cfgs from Makefile for rust-analyzer
Subsystems (2)
PATCH 1/1 scripts: read cfgs from Makefile for rust-analyzer
Both core and alloc had their cfgs missing in rust-project.json, to remedy this generate_rust_analyzer.py scans the Makefile from inside the rust directory for them to be added to a dictionary that each key corresponds to a crate and each value, to an array of cfgs.
--- scripts/generate_rust_analyzer.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
scripts/generate_rust_analyzer.py +22 -0
@@ -9,6 +9,24 @@ import logging import pathlib import sys +def makefile_crate_cfgs(makefile): + # Get configurations from a Makefile. + cfgs = {} + with open(makefile) as fd: + for line in fd: + if line.endswith("-cfgs = \\\n"): + crate = line.replace("-cfgs = \\\n", "") + cfg = [] + for l in map(lambda l: l.strip(), fd): + if not l: + cfgs[crate] = cfg + break + l = l.replace("--cfg ", "") + l = l.replace(" \\", "") + cfg.append(l) + + return cfgs + def generate_crates(srctree, objtree, sysroot_src): # Generate the configuration list. cfg = []
@@ -24,6 +42,8 @@ def generate_crates(srctree, objtree, sysroot_src): crates = [] crates_indexes = {} + makefile_cfgs = makefile_crate_cfgs(srctree / "rust" / "Makefile") + def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False): crates_indexes[display_name] = len(crates) crates.append({
@@ -44,6 +64,7 @@ def generate_crates(srctree, objtree, sysroot_src): "core", sysroot_src / "core" / "src" / "lib.rs", [], + cfg=makefile_cfgs.get("core", []), is_workspace_member=False, )
@@ -57,6 +78,7 @@ def generate_crates(srctree, objtree, sysroot_src): "alloc", srctree / "rust" / "alloc" / "lib.rs", ["core", "compiler_builtins"], + cfg=makefile_cfgs.get("alloc", []), ) append_crate(
Signature · 1 line
2.39.2
Quoted 57 lines · Martin Rodriguez Reboredo
Both
coreandallochad theircfgsmissing inrust-project.json, to remedy thisgenerate_rust_analyzer.pyscans theMakefilefrom inside therustdirectory for them to be added to a dictionary that each key corresponds to a crate and each value, to an array ofcfgs.Signed-off-by Martin Rodriguez Reboredo <[email protected]>--- scripts/generate_rust_analyzer.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)scripts/generate_rust_analyzer.py +21
-0@@ -9,6 +9,24 @@ import logging import pathlib import sys +def makefile_crate_cfgs(makefile): + # Get configurations from a Makefile. + cfgs = {} + with open(makefile) as fd: + for line in fd: + if line.endswith("-cfgs = \\\n"): + crate = line.replace("-cfgs = \\\n", "") + cfg = [] + for l in map(lambda l: l.strip(), fd): + if not l: + cfgs[crate] = cfg + break + l = l.replace("--cfg ", "") + l = l.replace(" \\", "") + cfg.append(l) + + return cfgs + def generate_crates(srctree, objtree, sysroot_src): # Generate the configuration list. cfg = []@@ -24,6 +42,8 @@ def generate_crates(srctree, objtree, sysroot_src): crates = [] crates_indexes = {} + makefile_cfgs = makefile_crate_cfgs(srctree / "rust" / "Makefile") + def append_crate(display_name, root_module, deps, cfg=[], is_workspace_member=True, is_proc_macro=False): crates_indexes[display_name] = len(crates) crates.append({@@ -44,6 +64,7 @@ def generate_crates(srctree, objtree, sysroot_src): "core", sysroot_src / "core" / "src" / "lib.rs", [], + cfg=makefile_cfgs.get("core", []), is_workspace_member=False, )
scripts/generate_rust_analyzer.py def generate_crates(srctree, objtree, sysroot_src): · line 84
Quoted 7 lines
scripts/generate_rust_analyzer.py +1
-0@@ -57,6 +78,7 @@ def generate_crates(srctree, objtree, sysroot_src): "alloc", srctree / "rust" / "alloc" / "lib.rs", ["core", "compiler_builtins"], + cfg=makefile_cfgs.get("alloc", []), ) append_crate(
Bump, I think this can fit into rust-fixes for 6.3.
Quoted 5 lines · Martin Rodriguez Reboredo
Both
coreandallochad theircfgsmissing inrust-project.json, to remedy thisgenerate_rust_analyzer.pyscans theMakefilefrom inside therustdirectory for them to be added to a dictionary that each key corresponds to a crate and each value, to an array ofcfgs.
We should pass the values to the script instead, rather than relying on how our Makefile is written, even if we control it.
Cheers,
Miguel