xref: /aosp_15_r20/external/webrtc/rtc_tools/testing/download_apprtc.py (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1#!/usr/bin/env python
2# Copyright (c) 2017 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"""Downloads prebuilt AppRTC and Go from WebRTC storage and unpacks it.
10
11Requires that depot_tools is installed and in the PATH.
12
13It downloads compressed files in the directory where the script lives.
14This is because the precondition is that the script lives in the same
15directory of the .sha1 files.
16"""
17
18import os
19import sys
20
21import utils
22
23SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
24
25
26def _GetGoArchivePathForPlatform():
27    archive_extension = 'zip' if utils.GetPlatform() == 'win' else 'tar.gz'
28    return os.path.join(utils.GetPlatform(), 'go.%s' % archive_extension)
29
30
31def main(argv):
32    if len(argv) > 2:
33        return 'Usage: %s [output_dir]' % argv[0]
34
35    output_dir = os.path.abspath(argv[1]) if len(argv) > 1 else None
36
37    apprtc_zip_path = os.path.join(SCRIPT_DIR, 'prebuilt_apprtc.zip')
38    if os.path.isfile(apprtc_zip_path + '.sha1'):
39        utils.DownloadFilesFromGoogleStorage(SCRIPT_DIR, auto_platform=False)
40
41    if output_dir is not None:
42        utils.RemoveDirectory(os.path.join(output_dir, 'apprtc'))
43        utils.UnpackArchiveTo(apprtc_zip_path, output_dir)
44
45    golang_path = os.path.join(SCRIPT_DIR, 'golang')
46    golang_zip_path = os.path.join(golang_path, _GetGoArchivePathForPlatform())
47    if os.path.isfile(golang_zip_path + '.sha1'):
48        utils.DownloadFilesFromGoogleStorage(golang_path)
49
50    if output_dir is not None:
51        utils.RemoveDirectory(os.path.join(output_dir, 'go'))
52        utils.UnpackArchiveTo(golang_zip_path, output_dir)
53
54
55if __name__ == '__main__':
56    sys.exit(main(sys.argv))
57