llvm.org GIT mirror llvm / 38ab6cd
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351064 91177308-0d34-0410-b5e6-96231b3b80d8 Nico Weber 9 months ago
3 changed file(s) with 50 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
None # FIXME: Once it's possible to add files to the root directory of the
1 # monorepo, move this file to there. Until then, you need to pass
2 # `--dotfile=llvm/utils/gn/.gn --root=.` to the `gn gen` command.
0 # Since this can't be at the toplevel, you either need to pass
1 # `--dotfile=llvm/utils/gn/.gn --root=.` to the `gn gen` command
2 # or use llvm/utils/gn/build/gn.py which calls gn with these two flags added.
33
44 buildconfig = "//llvm/utils/gn/build/BUILDCONFIG.gn"
55
4343
4444 #. Obtain a `gn binary `_.
4545
46 #. In the root of the monorepo, run
47 `gn gen --dotfile=$PWD/llvm/utils/gn/.gn --root=. out/gn` (`out/gn` is the
48 build directory, it can have any name, and you can have as many as you want,
49 each with different build settings).
46 #. In the root of the monorepo, run `llvm/utils/gn/build/gn.py gen out/gn`.
47 `out/gn` is the build directory, it can have any name, and you can have as
48 many as you want, each with different build settings. (The `gn.py` script
49 adds `--dotfile=llvm/utils/gn/.gn --root=.` and just runs regular `gn`;
50 you can manually pass these parameters and not use the wrapper if you
51 prefer.)
5052
5153 #. Run e.g. `ninja -C out/gn check-lld` to build all prerequisites for and
5254 run the LLD tests.
5456 By default, you get a release build with assertions enabled that targets
5557 the host arch. You can set various build options by editing `out/gn/args.gn`,
5658 for example putting `is_debug = true` in there gives you a debug build. Run
57 `gn args --list out/gn` to see a list of all possible options. After touching
58 `out/gn/args.gn`, just run ninja, it will re-invoke gn before starting the
59 build.
59 `llvm/utils/gn/build/gn.py args --list out/gn` to see a list of all possible
60 options. After touching `out/gn/args.gn`, just run ninja, it will re-invoke gn
61 before starting the build.
6062
6163 GN has extensive built-in help; try e.g. `gn help gen` to see the help
6264 for the `gen` command. The full GN reference is also `available online
0 #!/usr/bin/env python
1 """Calls `gn` with the right --dotfile= and --root= arguments for LLVM."""
2
3 # GN normally expects a file called '.gn' at the root of the repository.
4 # Since LLVM's GN build isn't supported, putting that file at the root
5 # is deemed inappropriate, which requires passing --dotfile= and -root= to GN.
6 # Since that gets old fast, this script automatically passes these arguments.
7
8 import os
9 import subprocess
10 import sys
11
12
13 THIS_DIR = os.path.dirname(__file__)
14 ROOT_DIR = os.path.join(THIS_DIR, '..', '..', '..')
15
16
17 def main():
18 # Find real gn executable. For now, just assume it's on PATH.
19 # FIXME: Probably need to append '.exe' on Windows.
20 gn = 'gn'
21
22 # Compute --dotfile= and --root= args to add.
23 extra_args = []
24 gn_main_arg = next((x for x in sys.argv[1:] if not x.startswith('-')), None)
25 if gn_main_arg != 'help': # `gn help` gets confused by the switches.
26 cwd = os.getcwd()
27 dotfile = os.path.relpath(os.path.join(THIS_DIR, '.gn'), cwd)
28 root = os.path.relpath(ROOT_DIR, cwd)
29 extra_args = [ '--dotfile=' + dotfile, '--root=' + root ]
30
31 # Run GN command with --dotfile= and --root= added.
32 cmd = [gn] + extra_args + sys.argv[1:]
33 sys.exit(subprocess.call(cmd))
34
35
36 if __name__ == '__main__':
37 main()