brettw@chromium.org | 67bb861 | 2013-11-08 20:51:40 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """This script is a wrapper around the GN binary that is pulled from Google |
| 7 | Cloud Storage when you sync Chrome. The binaries go into platform-specific |
| 8 | subdirectories in the source tree. |
| 9 | |
| 10 | This script makes there be one place for forwarding to the correct platform's |
| 11 | binary. It will also automatically try to find the gn binary when run inside |
| 12 | the chrome source tree, so users can just type "gn" on the command line |
| 13 | (normally depot_tools is on the path).""" |
| 14 | |
nick@chromium.org | 3ac1c4e | 2014-01-16 02:44:42 +0000 | [diff] [blame] | 15 | import gclient_utils |
brettw@chromium.org | 67bb861 | 2013-11-08 20:51:40 +0000 | [diff] [blame] | 16 | import os |
| 17 | import subprocess |
| 18 | import sys |
| 19 | |
| 20 | |
brettw@chromium.org | 67bb861 | 2013-11-08 20:51:40 +0000 | [diff] [blame] | 21 | def RunGN(sourceroot): |
| 22 | # The binaries in platform-specific subdirectories in src/tools/gn/bin. |
nick@chromium.org | 3ac1c4e | 2014-01-16 02:44:42 +0000 | [diff] [blame] | 23 | gnpath = os.path.join(sourceroot, |
| 24 | 'tools', 'gn', 'bin', gclient_utils.GetMacWinOrLinux(), |
| 25 | 'gn' + gclient_utils.GetExeSuffix()) |
brettw@chromium.org | 67bb861 | 2013-11-08 20:51:40 +0000 | [diff] [blame] | 26 | return subprocess.call([gnpath] + sys.argv[1:]) |
| 27 | |
| 28 | |
| 29 | def main(args): |
dpranke@chromium.org | a2a0c57 | 2014-03-27 21:44:36 +0000 | [diff] [blame] | 30 | for arg in sys.argv: |
| 31 | if arg.startswith('--root='): |
| 32 | sourceroot = arg.replace('--root=', '') |
| 33 | dotfile_path = os.path.join(sourceroot, '.gn') |
| 34 | if not os.path.exists(dotfile_path): |
| 35 | print >> sys.stderr, 'gn.py: "%s" not found, exiting.' % dotfile_path |
| 36 | sys.exit(1) |
| 37 | return RunGN(sourceroot) |
| 38 | |
nick@chromium.org | 3ac1c4e | 2014-01-16 02:44:42 +0000 | [diff] [blame] | 39 | sourceroot = gclient_utils.FindFileUpwards('.gn') |
brettw@chromium.org | 67bb861 | 2013-11-08 20:51:40 +0000 | [diff] [blame] | 40 | if not sourceroot: |
dpranke@chromium.org | a2a0c57 | 2014-03-27 21:44:36 +0000 | [diff] [blame] | 41 | print >> sys.stderr, ('gn.py: No .gn file found in any parent of ' |
| 42 | 'the current path.') |
| 43 | print >> sys.stderr, ('\nYou need to either be inside a checkout, ' |
| 44 | 'or use --root to specify the checkout root.') |
brettw@chromium.org | 67bb861 | 2013-11-08 20:51:40 +0000 | [diff] [blame] | 45 | sys.exit(1) |
| 46 | return RunGN(sourceroot) |
| 47 | |
nick@chromium.org | 3ac1c4e | 2014-01-16 02:44:42 +0000 | [diff] [blame] | 48 | |
brettw@chromium.org | 67bb861 | 2013-11-08 20:51:40 +0000 | [diff] [blame] | 49 | if __name__ == '__main__': |
| 50 | sys.exit(main(sys.argv)) |