Skip to content

Commit fa74a64

Browse files
authored
Cache Buck targets when traversing the tree of deps looking for the headers
1 parent 2516478 commit fa74a64

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

build/print_exported_headers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ def query(buck2: str, target: str, attribute: str) -> str:
3838
raise SystemExit("Error: " + str(e))
3939

4040

41+
# Cache to store results for exported headers per target.
42+
_exported_headers_cache = {}
43+
44+
4145
def exported_headers(buck2: str, target: str) -> Set[str]:
42-
"""Get all exported headers of a target and its dependencies."""
46+
"""Get all exported headers of a target and its dependencies, with caching."""
47+
if target in _exported_headers_cache:
48+
return _exported_headers_cache[target]
49+
4350
deps = query(buck2, target, "exported_deps")
4451
headers = set(query(buck2, target, "exported_headers"))
4552
headers.update(
@@ -48,13 +55,14 @@ def exported_headers(buck2: str, target: str) -> Set[str]:
4855
for header in exported_headers(buck2, dep.split()[0])
4956
if header.endswith(".h")
5057
)
58+
_exported_headers_cache[target] = headers
5159
return headers
5260

5361

5462
def expand_target(buck2: str, target: str) -> List[str]:
5563
"""Expand a target into a list of targets if applicable."""
5664
output = run([buck2, "cquery", target])
57-
# Buck's output format is "<target> (<build platform>)", we take only the target part.
65+
# Buck's output format is "<target> (<build platform>)", so we take only the target part.
5866
targets = [line.split(" ")[0] for line in output.strip().split("\n")]
5967
return targets
6068

0 commit comments

Comments
 (0)