summaryrefslogtreecommitdiffstats
path: root/llvm/utils/gn/gn.py
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2019-01-14 12:50:40 +0000
committerNico Weber <nicolasweber@gmx.de>2019-01-14 12:50:40 +0000
commitceabe8b02f4cd355d018e34d93deef357aa80715 (patch)
treed0044c4a6e9c9081dd8c6063117f3d8765c23b79 /llvm/utils/gn/gn.py
parentd2a749a92b310ea158431f9fd9594427483e029e (diff)
downloadbcm5719-llvm-ceabe8b02f4cd355d018e34d93deef357aa80715.tar.gz
bcm5719-llvm-ceabe8b02f4cd355d018e34d93deef357aa80715.zip
gn build: Add gn.py wrapper script that adds --dotfile= and --root= parameters
Since people weren't enthused about moving the .gn file to the toplevel in D56419, here's a script to make gn at least somewhat more pleasant to invoke (useful for gn clean, gn args --list, gn desc, etc). Differential Revision: https://reviews.llvm.org/D56565 llvm-svn: 351064
Diffstat (limited to 'llvm/utils/gn/gn.py')
-rw-r--r--llvm/utils/gn/gn.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/llvm/utils/gn/gn.py b/llvm/utils/gn/gn.py
new file mode 100644
index 00000000000..f80873b3be8
--- /dev/null
+++ b/llvm/utils/gn/gn.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+"""Calls `gn` with the right --dotfile= and --root= arguments for LLVM."""
+
+# GN normally expects a file called '.gn' at the root of the repository.
+# Since LLVM's GN build isn't supported, putting that file at the root
+# is deemed inappropriate, which requires passing --dotfile= and -root= to GN.
+# Since that gets old fast, this script automatically passes these arguments.
+
+import os
+import subprocess
+import sys
+
+
+THIS_DIR = os.path.dirname(__file__)
+ROOT_DIR = os.path.join(THIS_DIR, '..', '..', '..')
+
+
+def main():
+ # Find real gn executable. For now, just assume it's on PATH.
+ # FIXME: Probably need to append '.exe' on Windows.
+ gn = 'gn'
+
+ # Compute --dotfile= and --root= args to add.
+ extra_args = []
+ gn_main_arg = next((x for x in sys.argv[1:] if not x.startswith('-')), None)
+ if gn_main_arg != 'help': # `gn help` gets confused by the switches.
+ cwd = os.getcwd()
+ dotfile = os.path.relpath(os.path.join(THIS_DIR, '.gn'), cwd)
+ root = os.path.relpath(ROOT_DIR, cwd)
+ extra_args = [ '--dotfile=' + dotfile, '--root=' + root ]
+
+ # Run GN command with --dotfile= and --root= added.
+ cmd = [gn] + extra_args + sys.argv[1:]
+ sys.exit(subprocess.call(cmd))
+
+
+if __name__ == '__main__':
+ main()
OpenPOWER on IntegriCloud