From fa74a6490e8d4ff571bfbe80e55e8873f7177092 Mon Sep 17 00:00:00 2001 From: Anthony Shoumikhin Date: Thu, 27 Feb 2025 15:08:08 -0800 Subject: [PATCH] Cache Buck targets when traversing the tree of deps looking for the headers --- build/print_exported_headers.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/build/print_exported_headers.py b/build/print_exported_headers.py index b24100c7a94..dc0102ff00b 100755 --- a/build/print_exported_headers.py +++ b/build/print_exported_headers.py @@ -38,8 +38,15 @@ def query(buck2: str, target: str, attribute: str) -> str: raise SystemExit("Error: " + str(e)) +# Cache to store results for exported headers per target. +_exported_headers_cache = {} + + def exported_headers(buck2: str, target: str) -> Set[str]: - """Get all exported headers of a target and its dependencies.""" + """Get all exported headers of a target and its dependencies, with caching.""" + if target in _exported_headers_cache: + return _exported_headers_cache[target] + deps = query(buck2, target, "exported_deps") headers = set(query(buck2, target, "exported_headers")) headers.update( @@ -48,13 +55,14 @@ def exported_headers(buck2: str, target: str) -> Set[str]: for header in exported_headers(buck2, dep.split()[0]) if header.endswith(".h") ) + _exported_headers_cache[target] = headers return headers def expand_target(buck2: str, target: str) -> List[str]: """Expand a target into a list of targets if applicable.""" output = run([buck2, "cquery", target]) - # Buck's output format is " ()", we take only the target part. + # Buck's output format is " ()", so we take only the target part. targets = [line.split(" ")[0] for line in output.strip().split("\n")] return targets