Skip to contentSkip to conversation

scripts: store Makefiles in dictionary

PATCH In review alexpantyukhin 2 participants 4 messages Jan 3, 2023 – Jan 5, 2023 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: store Makefiles in dictionary

---
Store Makefiles by paths in dictionary and use these if required again

 scripts/generate_rust_analyzer.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
scripts/generate_rust_analyzer.py +7 -1
index ecc7ea9a4dcf..9fafa0397e8b 100755
@@ -98,13 +98,19 @@ def generate_crates(srctree, objtree, sysroot_src):
     # Then, the rest outside of `rust/`.
     #
     # We explicitly mention the top-level folders we want to cover.
+    makefiles_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 makefiles_path_content:
+                with open(makefile_path) as makefile:
+                    makefiles_path_content[makefile_path] = makefile.read()
+
+            if f"{name}.o" not in makefiles_path_content[makefile_path]:
                 continue
 
             logging.info("Adding %s", name)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · alexpantyukhin

Just to confirm: is this your real name? Most Signed-off-by lines are first name + surname (typically capitalized) or written in non-Latin alphabets. Of course, if your name is spelled as you wrote it, then that is fine!

Quoted 1 line

Store Makefiles by paths in dictionary and use these if required again

I think you intended for this to be the commit message, but currently it is after the ---, so the commit message is empty (except for the Signed-off-by).

In any case, the commit message should explain why a change is made. For instance, is this approach faster/simpler/... than the current one? Or, in other words, what was the reason behind the change? (I guess it is meant to make it faster, since you are caching the contents, but by how much etc.?)

Thanks!

Cheers,
Miguel

A message that is not in the archive (sent off-list or not yet received): CAPi66w-wG4vuOQzfYruHp7-+s1ex-snDougUkuW70Lrf-6gKhA@mail.gmail.com

#3 lore raw
Quoted 2 lines · Alexander Pantyukhin

Probably we also have to check if the Makefile exists. Or we can get FileNotFoundError. Do you think it is reasonable? Or we can always be sure that the Makefile for the parent always exists.

On missing Makefiles, please see
https://github.com/Rust-for-Linux/linux/pull/883, which should eventually arrive upstream.

Also https://github.com/Rust-for-Linux/linux/pull/914 is related to this piece of code.

Quoted 1 line

Thank you for your feedback!

My pleasure!

Cheers,
Miguel

A message that is not in the archive (sent off-list or not yet received): CAPi66w_zdf73em8vb7WxCP33ST+R_VzCz-qWvckuZuzLagVQPA@mail.gmail.com

#5 lore raw

Hi Alex,

Quoted 3 lines · Alexander Pantyukhin

I changed the Subject name, so now it became a new letter in the mailing list. Now it's a [PATCH] scripts: avoid redundant re-reading makefiles

Yeah, no worries -- please mark new revisions with a "[PATCH v2]" etc. as needed when you want to signify that (git-format-patch can do this with the -v flag), and ideally add a lore.kernel.org link to the previous version in the new one's changelog or cover letter if you think it may be unclear where it is coming from.

Cheers,
Miguel