blob: c8af3302e912c3d733ba459c3a5525205d3ef29d [file] [log] [blame]
brettw@chromium.org67bb8612013-11-08 20:51:40 +00001#!/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
7Cloud Storage when you sync Chrome. The binaries go into platform-specific
8subdirectories in the source tree.
9
10This script makes there be one place for forwarding to the correct platform's
11binary. It will also automatically try to find the gn binary when run inside
12the chrome source tree, so users can just type "gn" on the command line
13(normally depot_tools is on the path)."""
14
15import os
16import subprocess
17import sys
18
19
20class PlatformUnknownError(IOError):
21 pass
22
23
24def HasDotfile(path):
25 """Returns True if the given path has a .gn file in it."""
26 return os.path.exists(path + '/.gn')
27
28
29def 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
43def RunGN(sourceroot):
44 # The binaries in platform-specific subdirectories in src/tools/gn/bin.
45 gnpath = sourceroot + '/tools/gn/bin/'
46 if sys.platform == 'win32':
47 gnpath += 'win/gn.exe'
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:])
56
57
58def main(args):
59 sourceroot = FindSourceRootOnPath()
60 if not sourceroot:
61 print >> sys.stderr, '.gn file not found in any parent of the current path.'
62 sys.exit(1)
63 return RunGN(sourceroot)
64
65if __name__ == '__main__':
66 sys.exit(main(sys.argv))