Skip to content

Add an option to copy exported headers to an arbitrary dir preserving the structure. #665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions build/print_exported_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@

import argparse
import json
import os
import shutil
import subprocess
from typing import List, Set


cwd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))


def run(command: List[str]) -> str:
"""Run subprocess and return its output."""
result = subprocess.run(command, capture_output=True, check=True)
result = subprocess.run(command, capture_output=True, check=True, cwd=cwd)
return result.stdout.decode()


Expand Down Expand Up @@ -63,8 +68,18 @@ def main():
required=True,
help="Buck targets to find the headers of.",
)
parser.add_argument(
"--output",
help="Directory to copy the headers to.",
)
args = parser.parse_args()

if args.output:
if os.path.exists(args.output) and os.listdir(args.output):
raise ValueError(
f"Output path '{args.output}' already exists and is not empty."
)

targets = [
target
for input_target in args.targets
Expand All @@ -78,7 +93,14 @@ def main():

for header in sorted(headers):
# Strip off the leading workspace name and //.
print(header.split("//", 1)[-1])
header_path = header.split("//", 1)[-1]
if args.output:
src = os.path.join(cwd, header_path)
dst = os.path.join(args.output, header_path)
os.makedirs(os.path.dirname(dst), exist_ok=True)
shutil.copy2(src, dst)
else:
print(header_path)


if __name__ == "__main__":
Expand Down