Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: gn.py

Issue 66013002: Add a wrapper script for GN to depot_tools (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gn.bat ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright (c) 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
15 import os
16 import subprocess
17 import sys
18
19
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):
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
58 def 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
65 if __name__ == '__main__':
66 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « gn.bat ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698