| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """This script is a wrapper around the GN binary that is pulled from Google | 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 | 7 Cloud Storage when you sync Chrome. The binaries go into platform-specific |
| 8 subdirectories in the source tree. | 8 subdirectories in the source tree. |
| 9 | 9 |
| 10 This script makes there be one place for forwarding to the correct platform's | 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 | 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 | 12 the chrome source tree, so users can just type "gn" on the command line |
| 13 (normally depot_tools is on the path).""" | 13 (normally depot_tools is on the path).""" |
| 14 | 14 |
| 15 import gclient_utils |
| 15 import os | 16 import os |
| 16 import subprocess | 17 import subprocess |
| 17 import sys | 18 import sys |
| 18 | 19 |
| 19 | 20 |
| 20 class PlatformUnknownError(IOError): | |
| 21 pass | |
| 22 | |
| 23 | |
| 24 def HasDotfile(path): | |
| 25 """Returns True if the given path has a .gn file in it.""" | |
| 26 return os.path.exists(path + '/.gn') | |
| 27 | |
| 28 | |
| 29 def FindSourceRootOnPath(): | |
| 30 """Searches upward from the current directory for the root of the source | |
| 31 tree and returns the found path. Returns None if no source root could | |
| 32 be found.""" | |
| 33 cur = os.getcwd() | |
| 34 while True: | |
| 35 if HasDotfile(cur): | |
| 36 return cur | |
| 37 up_one = os.path.dirname(cur) | |
| 38 if up_one == cur: | |
| 39 return None # Reached the top of the directory tree | |
| 40 cur = up_one | |
| 41 | |
| 42 | |
| 43 def RunGN(sourceroot): | 21 def RunGN(sourceroot): |
| 44 # The binaries in platform-specific subdirectories in src/tools/gn/bin. | 22 # The binaries in platform-specific subdirectories in src/tools/gn/bin. |
| 45 gnpath = sourceroot + '/tools/gn/bin/' | 23 gnpath = os.path.join(sourceroot, |
| 46 if sys.platform in ('cygwin', 'win32'): | 24 'tools', 'gn', 'bin', gclient_utils.GetMacWinOrLinux(), |
| 47 gnpath += 'win/gn.exe' | 25 'gn' + gclient_utils.GetExeSuffix()) |
| 48 elif sys.platform.startswith('linux'): | |
| 49 gnpath += 'linux/gn' | |
| 50 elif sys.platform == 'darwin': | |
| 51 gnpath += 'mac/gn' | |
| 52 else: | |
| 53 raise PlatformUnknownError('Unknown platform for GN: ' + sys.platform) | |
| 54 | |
| 55 return subprocess.call([gnpath] + sys.argv[1:]) | 26 return subprocess.call([gnpath] + sys.argv[1:]) |
| 56 | 27 |
| 57 | 28 |
| 58 def main(args): | 29 def main(args): |
| 59 sourceroot = FindSourceRootOnPath() | 30 sourceroot = gclient_utils.FindFileUpwards('.gn') |
| 60 if not sourceroot: | 31 if not sourceroot: |
| 61 print >> sys.stderr, '.gn file not found in any parent of the current path.' | 32 print >> sys.stderr, '.gn file not found in any parent of the current path.' |
| 62 sys.exit(1) | 33 sys.exit(1) |
| 63 return RunGN(sourceroot) | 34 return RunGN(sourceroot) |
| 64 | 35 |
| 36 |
| 65 if __name__ == '__main__': | 37 if __name__ == '__main__': |
| 66 sys.exit(main(sys.argv)) | 38 sys.exit(main(sys.argv)) |
| OLD | NEW |