1#!/usr/bin/env python
2# Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3#
4# Use of this source code is governed by a BSD-style license
5# that can be found in the LICENSE file in the root of the source
6# tree. An additional intellectual property rights grant can be found
7# in the file PATENTS.  All contributing project authors may
8# be found in the AUTHORS file in the root of the source tree.
9
10"""Downloads precompiled tools.
11
12These are checked into the repository as SHA-1 hashes (see *.sha1 files in
13subdirectories). Note that chrome-webrtc-resources is a Google-internal bucket,
14so please download and compile these tools manually if this script fails.
15"""
16
17import os
18import sys
19
20
21SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
22SRC_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, os.pardir))
23sys.path.append(os.path.join(SRC_DIR, 'build'))
24
25
26import find_depot_tools
27find_depot_tools.add_depot_tools_to_path()
28import gclient_utils
29import subprocess2
30
31
32def main(directories):
33  if not directories:
34    directories = [SCRIPT_DIR]
35
36  for path in directories:
37    cmd = [
38      sys.executable,
39      os.path.join(find_depot_tools.DEPOT_TOOLS_PATH,
40                   'download_from_google_storage.py'),
41      '--directory',
42      '--num_threads=10',
43      '--bucket', 'chrome-webrtc-resources',
44      '--auto_platform',
45      '--recursive',
46      path,
47    ]
48    print 'Downloading precompiled tools...'
49
50    # Perform download similar to how gclient hooks execute.
51    try:
52      gclient_utils.CheckCallAndFilter(
53          cmd, cwd=SRC_DIR, always_show_header=True)
54    except (gclient_utils.Error, subprocess2.CalledProcessError) as e:
55      print 'Error: %s' % str(e)
56      return 2
57    return 0
58
59
60if __name__ == '__main__':
61  sys.exit(main(sys.argv[1:]))
62