-
Notifications
You must be signed in to change notification settings - Fork 233
/
buck2.py
executable file
·76 lines (58 loc) · 2.04 KB
/
buck2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
import argparse
import platform
import subprocess
from typing import List, Tuple
def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
parser = argparse.ArgumentParser(
description="Builds buck2 locally and then runs it.",
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument(
"--run-isolation-dir",
type=str,
default="",
help="Isolation dir for the inner command",
)
parser.add_argument(
"--echo-run-cmd",
action="store_true",
help="Echo the run command before executing",
)
return parser.parse_known_args()
def get_extra_build_params(args: argparse.Namespace) -> List[str]:
system_platform = platform.system()
if system_platform == "Windows":
return ["@fbcode//mode/opt-win"]
params = ["-m", "opt"]
arch_platform = platform.machine()
if arch_platform == "x86_64":
params.extend(["-m", "x86_64"])
elif arch_platform == "arm64":
params.extend(["-m", "arm64"])
return params
def build_command(args: argparse.Namespace, extra_args: List[str]) -> List[str]:
cmd = ["buck2", "run", "fbcode//buck2:buck2"]
inner_buck_isolation_dir = (
args.run_isolation_dir if args.run_isolation_dir else "v2.self"
)
inner_buck_isolation_dir_arg = [f"--isolation-dir={inner_buck_isolation_dir}"]
cmd.extend(get_extra_build_params(args))
cmd.append("--")
cmd.extend(inner_buck_isolation_dir_arg)
cmd.extend(extra_args)
if args.echo_run_cmd:
print(" ".join(cmd))
return cmd
def main() -> None:
args, extra_args = parse_arguments()
cmd = build_command(args, extra_args)
subprocess.run(cmd)
if __name__ == "__main__":
main()