blob: f80873b3be80dfa2655b605b69038300304b5a60 [file] [log] [blame]
Nico Weber38ab6cd2019-01-14 12:50:40 +00001#!/usr/bin/env python
2"""Calls `gn` with the right --dotfile= and --root= arguments for LLVM."""
3
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.
8
9import os
10import subprocess
11import sys
12
13
14THIS_DIR = os.path.dirname(__file__)
15ROOT_DIR = os.path.join(THIS_DIR, '..', '..', '..')
16
17
18def main():
19 # Find real gn executable. For now, just assume it's on PATH.
20 # FIXME: Probably need to append '.exe' on Windows.
21 gn = 'gn'
22
23 # Compute --dotfile= and --root= args to add.
24 extra_args = []
25 gn_main_arg = next((x for x in sys.argv[1:] if not x.startswith('-')), None)
26 if gn_main_arg != 'help': # `gn help` gets confused by the switches.
27 cwd = os.getcwd()
28 dotfile = os.path.relpath(os.path.join(THIS_DIR, '.gn'), cwd)
29 root = os.path.relpath(ROOT_DIR, cwd)
30 extra_args = [ '--dotfile=' + dotfile, '--root=' + root ]
31
32 # Run GN command with --dotfile= and --root= added.
33 cmd = [gn] + extra_args + sys.argv[1:]
34 sys.exit(subprocess.call(cmd))
35
36
37if __name__ == '__main__':
38 main()