All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts: avoid redundant re-reading makefiles.
@ 2023-01-04 16:04 Alexander Pantyukhin
  2023-01-05 18:44 ` Miguel Ojeda
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Pantyukhin @ 2023-01-04 16:04 UTC (permalink / raw)
  To: ojeda, rust-for-linux, akpm; +Cc: alexpantyukhin

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


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

end of thread, other threads:[~2023-01-05 23:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-04 16:04 [PATCH] scripts: avoid redundant re-reading makefiles Alexander Pantyukhin
2023-01-05 18:44 ` Miguel Ojeda
2023-01-05 19:51   ` Alexander Pantyukhin
2023-01-05 23:01     ` Miguel Ojeda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.