Stack symbolization: Replace functools.cache
Use lru_cache(maxsize=None) instead which is equivalent,
and is available on older python versions as well.
Also fix a bug where null "lib" variable was dereferenced.
Bug: 204507951
Bug: 171980804
Test: Run script with python3.7
Change-Id: I922ee48451ad3c60c2237fb0554e1838c1bf81af
diff --git a/scripts/stack_core.py b/scripts/stack_core.py
index e703cc9..6e84db3 100755
--- a/scripts/stack_core.py
+++ b/scripts/stack_core.py
@@ -313,7 +313,7 @@
return None, None
# Find all files in the symbols directory and group them by basename (without directory).
- @functools.cache
+ @functools.lru_cache(maxsize=None)
def GlobSymbolsDir(self, symbols_dir):
files_by_basename = {}
for path in sorted(pathlib.Path(symbols_dir).glob("**/*")):
@@ -321,7 +321,7 @@
return files_by_basename
# Use the "file" command line tool to find the bitness and build_id of given ELF file.
- @functools.cache
+ @functools.lru_cache(maxsize=None)
def GetLibraryInfo(self, lib):
stdout = subprocess.check_output(["file", lib], text=True)
match = self.file_tool_output.search(stdout)
@@ -330,7 +330,7 @@
return None
# Search for a library with the given basename and build_id anywhere in the symbols directory.
- @functools.cache
+ @functools.lru_cache(maxsize=None)
def GetLibraryByBuildId(self, symbols_dir, basename, build_id):
for candidate in self.GlobSymbolsDir(symbols_dir).get(basename):
info = self.GetLibraryInfo(candidate)
@@ -484,10 +484,11 @@
if build_id:
# If we have the build_id, do a brute-force search of the symbols directory.
- lib = self.GetLibraryByBuildId(symbol.SYMBOLS_DIR, os.path.basename(lib), build_id)
+ basename = os.path.basename(lib)
+ lib = self.GetLibraryByBuildId(symbol.SYMBOLS_DIR, basename, build_id)
if not lib:
print("WARNING: Cannot find {} with build id {} in symbols directory."
- .format(os.path.basename(lib), build_id))
+ .format(basename, build_id))
else:
# When using atest, test paths are different between the out/ directory
# and device. Apply fixups.