Skip to content

Commit 30d94f1

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Add an option to copy exported headers to an arbitrary dir preserving the structure.
Summary: . Differential Revision: D50023905
1 parent d235ba8 commit 30d94f1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

build/print_exported_headers.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@
1212

1313
import argparse
1414
import json
15+
import os
16+
import shutil
1517
import subprocess
1618
from typing import List, Set
1719

1820

21+
cwd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
22+
23+
1924
def run(command: List[str]) -> str:
2025
"""Run subprocess and return its output."""
21-
result = subprocess.run(command, capture_output=True, check=True)
26+
result = subprocess.run(command, capture_output=True, check=True, cwd=cwd)
2227
return result.stdout.decode()
2328

2429

@@ -63,8 +68,18 @@ def main():
6368
required=True,
6469
help="Buck targets to find the headers of.",
6570
)
71+
parser.add_argument(
72+
"--output",
73+
help="Directory to copy the headers to.",
74+
)
6675
args = parser.parse_args()
6776

77+
if args.output:
78+
if os.path.exists(args.output) and os.listdir(args.output):
79+
raise ValueError(
80+
f"Output path '{args.output}' already exists and is not empty."
81+
)
82+
6883
targets = [
6984
target
7085
for input_target in args.targets
@@ -78,7 +93,14 @@ def main():
7893

7994
for header in sorted(headers):
8095
# Strip off the leading workspace name and //.
81-
print(header.split("//", 1)[-1])
96+
header_path = header.split("//", 1)[-1]
97+
if args.output:
98+
src = os.path.join(cwd, header_path)
99+
dst = os.path.join(args.output, header_path)
100+
os.makedirs(os.path.dirname(dst), exist_ok=True)
101+
shutil.copy2(src, dst)
102+
else:
103+
print(header_path)
82104

83105

84106
if __name__ == "__main__":

0 commit comments

Comments
 (0)