12
12
13
13
import argparse
14
14
import json
15
+ import os
16
+ import shutil
15
17
import subprocess
16
18
from typing import List , Set
17
19
18
20
21
+ cwd = os .path .dirname (os .path .dirname (os .path .realpath (__file__ )))
22
+
23
+
19
24
def run (command : List [str ]) -> str :
20
25
"""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 )
22
27
return result .stdout .decode ()
23
28
24
29
@@ -63,8 +68,18 @@ def main():
63
68
required = True ,
64
69
help = "Buck targets to find the headers of." ,
65
70
)
71
+ parser .add_argument (
72
+ "--output" ,
73
+ help = "Directory to copy the headers to." ,
74
+ )
66
75
args = parser .parse_args ()
67
76
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
+
68
83
targets = [
69
84
target
70
85
for input_target in args .targets
@@ -78,7 +93,14 @@ def main():
78
93
79
94
for header in sorted (headers ):
80
95
# 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 )
82
104
83
105
84
106
if __name__ == "__main__" :
0 commit comments