blob: cca57f95bbfa4a59bf7b1ec2e803d6d9d38c7f2e [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
nick@chromium.org3ac1c4e2014-01-16 02:44:42 +000015import gclient_utils
brettw@chromium.org67bb8612013-11-08 20:51:40 +000016import os
17import subprocess
18import sys
19
20
brettw@chromium.org67bb8612013-11-08 20:51:40 +000021def main(args):
Scott Grahama991ac62018-06-26 23:19:51 +000022 # Try in primary solution location first, with the gn binary having been
23 # downloaded by cipd in the projects DEPS.
24 gn_path = os.path.join(gclient_utils.GetPrimarySolutionPath(), 'third_party',
25 'gn', 'gn' + gclient_utils.GetExeSuffix())
26 if os.path.exists(gn_path):
27 return subprocess.call([gn_path] + args[1:])
28
29 # Otherwise try the old .sha1 and download_from_google_storage locations
30 # inside of buildtools.
brettw@chromium.orgcc968fe2014-06-23 17:30:32 +000031 bin_path = gclient_utils.GetBuildtoolsPlatformBinaryPath()
32 if not bin_path:
33 print >> sys.stderr, ('gn.py: Could not find checkout in any parent of '
34 'the current path.\nThis must be run inside a '
35 'checkout.')
kjellander@chromium.orgf7facfa2014-09-05 12:40:28 +000036 return 1
brettw@chromium.orgcc968fe2014-06-23 17:30:32 +000037 gn_path = os.path.join(bin_path, 'gn' + gclient_utils.GetExeSuffix())
kjellander@chromium.orgf7facfa2014-09-05 12:40:28 +000038 if not os.path.exists(gn_path):
39 print >> sys.stderr, 'gn.py: Could not find gn executable at: %s' % gn_path
40 return 2
41 else:
scottmg@chromium.orgd05ab352014-12-05 17:24:26 +000042 return subprocess.call([gn_path] + args[1:])
brettw@chromium.org67bb8612013-11-08 20:51:40 +000043
nick@chromium.org3ac1c4e2014-01-16 02:44:42 +000044
brettw@chromium.org67bb8612013-11-08 20:51:40 +000045if __name__ == '__main__':
sbc@chromium.org013731e2015-02-26 18:28:43 +000046 try:
47 sys.exit(main(sys.argv))
48 except KeyboardInterrupt:
49 sys.stderr.write('interrupted\n')
50 sys.exit(1)