[AMDGPU] prevent shrinking udiv/urem if either operand is in (SignedMax,UnsignedMax...
[llvm-project.git] / llvm / utils / gn / gn.py
blob6b7919b7faeb92478c48b8d64fb750dde363d34f
1 #!/usr/bin/env python3
2 """Calls `gn` with the right --dotfile= and --root= arguments for LLVM."""
4 # GN normally expects a file called '.gn' at the root of the repository.
5 # Since LLVM's GN build isn't supported, putting that file at the root
6 # is deemed inappropriate, which requires passing --dotfile= and -root= to GN.
7 # Since that gets old fast, this script automatically passes these arguments.
9 import os
10 import subprocess
11 import sys
14 THIS_DIR = os.path.dirname(__file__)
15 ROOT_DIR = os.path.join(THIS_DIR, "..", "..", "..")
18 def get_platform():
19 import platform
21 if sys.platform == "darwin":
22 return "mac-amd64" if platform.machine() != "arm64" else "mac-arm64"
23 if platform.machine() not in ("AMD64", "x86_64"):
24 return None
25 if sys.platform.startswith("linux"):
26 return "linux-amd64"
27 if sys.platform == "win32":
28 return "windows-amd64"
31 def print_no_gn(mention_get):
32 print("gn binary not found in PATH")
33 if mention_get:
34 print("run llvm/utils/gn/get.py to download a binary and try again, or")
35 print("follow https://gn.googlesource.com/gn/#getting-started")
36 return 1
39 def main():
40 # Find real gn executable.
41 gn = "gn"
42 if (
43 subprocess.call(
44 "gn --version",
45 stdout=subprocess.DEVNULL,
46 stderr=subprocess.STDOUT,
47 shell=True,
49 != 0
51 # Not on path. See if get.py downloaded a prebuilt binary and run that
52 # if it's there, or suggest to run get.py if it isn't.
53 platform = get_platform()
54 if not platform:
55 return print_no_gn(mention_get=False)
56 gn = os.path.join(os.path.dirname(__file__), "bin", platform, "gn")
57 if not os.path.exists(gn + (".exe" if sys.platform == "win32" else "")):
58 return print_no_gn(mention_get=True)
60 # Compute --dotfile= and --root= args to add.
61 extra_args = []
62 gn_main_arg = next((x for x in sys.argv[1:] if not x.startswith("-")), None)
63 if gn_main_arg != "help": # `gn help` gets confused by the switches.
64 cwd = os.getcwd()
65 dotfile = os.path.relpath(os.path.join(THIS_DIR, ".gn"), cwd)
66 root = os.path.relpath(ROOT_DIR, cwd)
67 extra_args = ["--dotfile=" + dotfile, "--root=" + root]
69 # Run GN command with --dotfile= and --root= added.
70 cmd = [gn] + extra_args + sys.argv[1:]
71 sys.exit(subprocess.call(cmd))
74 if __name__ == "__main__":
75 main()