[MIParser] Set RegClassOrRegBank during instruction parsing
[llvm-complete.git] / utils / gn / gn.py
bloba6408ec065a359e62838e8ad7078f841ddb57ab8
1 #!/usr/bin/env python
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
20 if platform.machine() not in ('AMD64', 'x86_64'):
21 return None
22 if sys.platform.startswith('linux'):
23 return 'linux-amd64'
24 if sys.platform == 'darwin':
25 return 'mac-amd64'
26 if sys.platform == 'win32':
27 return 'windows-amd64'
30 def print_no_gn(mention_get):
31 print('gn binary not found in PATH')
32 if mention_get:
33 print('run llvm/utils/gn/get.py to download a binary and try again, or')
34 print('follow https://gn.googlesource.com/gn/#getting-started')
35 return 1
38 def main():
39 # Find real gn executable.
40 gn = 'gn'
41 if subprocess.call('gn --version', stdout=open(os.devnull, 'w'),
42 stderr=subprocess.STDOUT,
43 shell=True) != 0:
44 # Not on path. See if get.py downloaded a prebuilt binary and run that
45 # if it's there, or suggest to run get.py if it isn't.
46 platform = get_platform()
47 if not platform:
48 return print_no_gn(mention_get=False)
49 gn = os.path.join(os.path.dirname(__file__), 'bin', platform, 'gn')
50 if not os.path.exists(gn + ('.exe' if sys.platform == 'win32' else '')):
51 return print_no_gn(mention_get=True)
53 # Compute --dotfile= and --root= args to add.
54 extra_args = []
55 gn_main_arg = next((x for x in sys.argv[1:] if not x.startswith('-')), None)
56 if gn_main_arg != 'help': # `gn help` gets confused by the switches.
57 cwd = os.getcwd()
58 dotfile = os.path.relpath(os.path.join(THIS_DIR, '.gn'), cwd)
59 root = os.path.relpath(ROOT_DIR, cwd)
60 extra_args = [ '--dotfile=' + dotfile, '--root=' + root ]
62 # Run GN command with --dotfile= and --root= added.
63 cmd = [gn] + extra_args + sys.argv[1:]
64 sys.exit(subprocess.call(cmd))
67 if __name__ == '__main__':
68 main()