From: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: rust-for-linux@vger.kernel.org, "Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>
Subject: [PATCH] scripts: read cfgs from Makefile for rust-analyzer
Date: Wed, 22 Feb 2023 23:59:24 -0300 [thread overview]
Message-ID: <20230223025924.526200-1-yakoyoku@gmail.com> (raw)
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
next reply other threads:[~2023-02-23 2:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 2:59 Martin Rodriguez Reboredo [this message]
2023-04-10 0:16 ` [PATCH] scripts: read cfgs from Makefile for rust-analyzer Martin Rodriguez Reboredo
2023-04-10 20:37 ` Miguel Ojeda
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230223025924.526200-1-yakoyoku@gmail.com \
--to=yakoyoku@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).