rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: read cfgs from Makefile for rust-analyzer
@ 2023-02-23  2:59 Martin Rodriguez Reboredo
  2023-04-10  0:16 ` Martin Rodriguez Reboredo
  2023-04-10 20:37 ` Miguel Ojeda
  0 siblings, 2 replies; 3+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-02-23  2:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: rust-for-linux, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Boqun Feng, Gary Guo, Björn Roy Baron

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`.

Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
---
 scripts/generate_rust_analyzer.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index ecc7ea9a4dcf..8bfadd688ebc 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -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(
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: read cfgs from Makefile for rust-analyzer
  2023-02-23  2:59 [PATCH] scripts: read cfgs from Makefile for rust-analyzer Martin Rodriguez Reboredo
@ 2023-04-10  0:16 ` Martin Rodriguez Reboredo
  2023-04-10 20:37 ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Martin Rodriguez Reboredo @ 2023-04-10  0:16 UTC (permalink / raw)
  To: linux-kernel
  Cc: rust-for-linux, Miguel Ojeda, Alex Gaynor, Wedson Almeida Filho,
	Boqun Feng, Gary Guo, Björn Roy Baron

On 2/22/23 23:59, Martin Rodriguez Reboredo wrote:
> 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`.
> 
> Signed-off-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
> ---
>  scripts/generate_rust_analyzer.py | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index ecc7ea9a4dcf..8bfadd688ebc 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -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(

Bump, I think this can fit into rust-fixes for 6.3.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: read cfgs from Makefile for rust-analyzer
  2023-02-23  2:59 [PATCH] scripts: read cfgs from Makefile for rust-analyzer Martin Rodriguez Reboredo
  2023-04-10  0:16 ` Martin Rodriguez Reboredo
@ 2023-04-10 20:37 ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2023-04-10 20:37 UTC (permalink / raw)
  To: Martin Rodriguez Reboredo
  Cc: linux-kernel, rust-for-linux, Miguel Ojeda, Alex Gaynor,
	Wedson Almeida Filho, Boqun Feng, Gary Guo, Björn Roy Baron

On Thu, Feb 23, 2023 at 3:59 AM Martin Rodriguez Reboredo
<yakoyoku@gmail.com> wrote:
>
> 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`.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-04-10 20:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-23  2:59 [PATCH] scripts: read cfgs from Makefile for rust-analyzer Martin Rodriguez Reboredo
2023-04-10  0:16 ` Martin Rodriguez Reboredo
2023-04-10 20:37 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).