[1/3] scripts/machine-summary: improve layer_path

Message ID 20220126191253.1844130-1-ross.burton@arm.com
State New
Headers show
Series [1/3] scripts/machine-summary: improve layer_path | expand

Commit Message

Ross Burton Jan. 26, 2022, 7:12 p.m. UTC
As this can get called lots but the data doesn't change, cache
the responses.  Also return a pathlib.Path, as this is 2022.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 scripts/machine-summary.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Jon Mason Jan. 27, 2022, 2:52 p.m. UTC | #1
On Wed, 26 Jan 2022 19:12:51 +0000, Ross Burton wrote:
> As this can get called lots but the data doesn't change, cache
> the responses.  Also return a pathlib.Path, as this is 2022.

Applied, thanks!

[1/3] scripts/machine-summary: improve layer_path
      commit: b1e4cff75df54ab6d49c3b1a67e4fef806de571d
[2/3] scripts/machine-summary: link patches to cgit
      commit: 57f03491be7838279999a537384e0c9987e052d7
[3/3] CI: enable memory-resident bitbake
      commit: 828ad702acf6ea00907a9bdcd6537b32cc0ff78b

Best regards,

Patch

diff --git a/scripts/machine-summary.py b/scripts/machine-summary.py
index 4888a007..c07c2d15 100755
--- a/scripts/machine-summary.py
+++ b/scripts/machine-summary.py
@@ -30,16 +30,23 @@  def safe_patches(patches):
             return False
     return True
 
-def layer_path(layername, d):
+def layer_path(layername: str, d) -> pathlib.Path:
     """
     Return the path to the specified layer, or None if the layer isn't present.
     """
-    import re
+    if not hasattr(layer_path, "cache"):
+        # Don't use functools.lru_cache as we don't want d changing to invalidate the cache
+        layer_path.cache = {}
+
+    if layername in layer_path.cache:
+        return layer_path.cache[layername]
+
     bbpath = d.getVar("BBPATH").split(":")
     pattern = d.getVar('BBFILE_PATTERN_' + layername)
     for path in reversed(sorted(bbpath)):
         if re.match(pattern, path + "/"):
-            return path
+            layer_path.cache[layername] = pathlib.Path(path)
+            return layer_path.cache[layername]
     return None
 
 def extract_patch_info(src_uri, d):