From: Alexander Pantyukhin <apantykhin@gmail.com>
To: ojeda@kernel.org, rust-for-linux@vger.kernel.org,
akpm@linux-foundation.org
Cc: alexpantyukhin <apantykhin@gmail.com>
Subject: [PATCH] scripts: avoid redundant re-reading makefiles.
Date: Wed, 4 Jan 2023 21:04:05 +0500 [thread overview]
Message-ID: <20230104160405.5530-1-apantykhin@gmail.com> (raw)
From: alexpantyukhin <apantykhin@gmail.com>
The main goal of the patch is avoid redundant re-reading makefiles
if these were read before. This is performance improvement.
Additional code improvements are using 'with' when read file and check
if file exists.
Signed-off-by: Alexander Pantyukhin <apantykhin@gmail.com>
---
scripts/generate_rust_analyzer.py | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index ecc7ea9a4dcf..e949f32b8123 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -98,13 +98,25 @@ def generate_crates(srctree, objtree, sysroot_src):
# Then, the rest outside of `rust/`.
#
# We explicitly mention the top-level folders we want to cover.
+ makefile_path_content = {}
for folder in ("samples", "drivers"):
for path in (srctree / folder).rglob("*.rs"):
logging.info("Checking %s", path)
name = path.name.replace(".rs", "")
# Skip those that are not crate roots.
- if f"{name}.o" not in open(path.parent / "Makefile").read():
+ makefile_path = path.parent / "Makefile"
+
+ if makefile_path not in makefile_path_content:
+ if makefile_path.is_file():
+ with open(makefile_path) as makefile:
+ makefile_path_content[makefile_path] = makefile.read()
+
+ else:
+ # If file is missing we consider it as empty-content file.
+ makefile_path_content[makefile_path] = ""
+
+ if f"{name}.o" not in makefile_path_content[makefile_path]:
continue
logging.info("Adding %s", name)
--
2.25.1
next reply other threads:[~2023-01-04 16:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-04 16:04 Alexander Pantyukhin [this message]
2023-01-05 18:44 ` [PATCH] scripts: avoid redundant re-reading makefiles Miguel Ojeda
2023-01-05 19:51 ` Alexander Pantyukhin
2023-01-05 23:01 ` 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=20230104160405.5530-1-apantykhin@gmail.com \
--to=apantykhin@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
/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).