[llvm] r351064 - gn build: Add gn.py wrapper script that adds --dotfile= and --root= parameters

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 14 04:50:40 PST 2019


Author: nico
Date: Mon Jan 14 04:50:40 2019
New Revision: 351064

URL: http://llvm.org/viewvc/llvm-project?rev=351064&view=rev
Log:
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

Added:
    llvm/trunk/utils/gn/gn.py
Modified:
    llvm/trunk/utils/gn/.gn
    llvm/trunk/utils/gn/README.rst

Modified: llvm/trunk/utils/gn/.gn
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/.gn?rev=351064&r1=351063&r2=351064&view=diff
==============================================================================
--- llvm/trunk/utils/gn/.gn (original)
+++ llvm/trunk/utils/gn/.gn Mon Jan 14 04:50:40 2019
@@ -1,6 +1,6 @@
-# FIXME: Once it's possible to add files to the root directory of the
-# monorepo, move this file to there.  Until then, you need to pass
-# `--dotfile=llvm/utils/gn/.gn --root=.` to the `gn gen` command.
+# Since this can't be at the toplevel, you either need to pass
+# `--dotfile=llvm/utils/gn/.gn --root=.` to the `gn gen` command
+# or use llvm/utils/gn/build/gn.py which calls gn with these two flags added.
 
 buildconfig = "//llvm/utils/gn/build/BUILDCONFIG.gn"
 

Modified: llvm/trunk/utils/gn/README.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/README.rst?rev=351064&r1=351063&r2=351064&view=diff
==============================================================================
--- llvm/trunk/utils/gn/README.rst (original)
+++ llvm/trunk/utils/gn/README.rst Mon Jan 14 04:50:40 2019
@@ -44,10 +44,12 @@ GN only works in the monorepo layout.
 
 #. Obtain a `gn binary <https://gn.googlesource.com/gn/#getting-started>`_.
 
-#. In the root of the monorepo, run
-   `gn gen --dotfile=$PWD/llvm/utils/gn/.gn --root=. out/gn` (`out/gn` is the
-   build directory, it can have any name, and you can have as many as you want,
-   each with different build settings).
+#. In the root of the monorepo, run `llvm/utils/gn/build/gn.py gen out/gn`.
+   `out/gn` is the build directory, it can have any name, and you can have as
+   many as you want, each with different build settings.  (The `gn.py` script
+   adds `--dotfile=llvm/utils/gn/.gn --root=.` and just runs regular `gn`;
+   you can manually pass these parameters and not use the wrapper if you
+   prefer.)
 
 #. Run e.g. `ninja -C out/gn check-lld` to build all prerequisites for and
    run the LLD tests.
@@ -55,9 +57,9 @@ GN only works in the monorepo layout.
 By default, you get a release build with assertions enabled that targets
 the host arch. You can set various build options by editing `out/gn/args.gn`,
 for example putting `is_debug = true` in there gives you a debug build. Run
-`gn args --list out/gn` to see a list of all possible options. After touching
-`out/gn/args.gn`, just run ninja, it will re-invoke gn before starting the
-build.
+`llvm/utils/gn/build/gn.py args --list out/gn` to see a list of all possible
+options. After touching `out/gn/args.gn`, just run ninja, it will re-invoke gn
+before starting the build.
 
 GN has extensive built-in help; try e.g. `gn help gen` to see the help
 for the `gen` command. The full GN reference is also `available online

Added: llvm/trunk/utils/gn/gn.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/gn/gn.py?rev=351064&view=auto
==============================================================================
--- llvm/trunk/utils/gn/gn.py (added)
+++ llvm/trunk/utils/gn/gn.py Mon Jan 14 04:50:40 2019
@@ -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()




More information about the llvm-commits mailing list