Nico Weber | 38ab6cd | 2019-01-14 12:50:40 +0000 | [diff] [blame] | 1 | #!/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 | |
| 9 | import os |
| 10 | import subprocess |
| 11 | import sys |
| 12 | |
| 13 | |
| 14 | THIS_DIR = os.path.dirname(__file__) |
| 15 | ROOT_DIR = os.path.join(THIS_DIR, '..', '..', '..') |
| 16 | |
| 17 | |
| 18 | def 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 | |
| 37 | if __name__ == '__main__': |
| 38 | main() |