blob: b8eba4e12e795cad628f1813264fbabca48331f0 [file] [log] [blame]
Christoffer Quist Adamsenfb2caf82021-06-01 13:50:30 +02001#!/usr/bin/env python3
Mads Ager418d1ca2017-05-22 09:35:49 +02002# Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6# Script for downloading from x20 a dependency in the same way we use cloud
7# storage.
8
9import optparse
10import os
11import shutil
12import subprocess
13import sys
14import tarfile
15import utils
16
Jeffrey van Gogh5dac4482018-01-24 02:36:38 -080017GMSCORE_DEPS = '/google/data/ro/teams/r8/deps'
Mads Ager418d1ca2017-05-22 09:35:49 +020018
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020019
Mads Ager418d1ca2017-05-22 09:35:49 +020020def parse_options():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020021 return optparse.OptionParser().parse_args()
22
Mads Ager418d1ca2017-05-22 09:35:49 +020023
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020024def download(src, dest):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020025 print('Downloading %s to %s' % (src, dest))
26 shutil.copyfile(src, dest)
27 utils.unpack_archive(dest)
28
Mads Ager418d1ca2017-05-22 09:35:49 +020029
30def Main():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020031 (options, args) = parse_options()
32 assert len(args) == 1
33 sha1_file = args[0]
34 dest = sha1_file[:-5]
35 print('Ensuring %s' % dest)
36 with open(sha1_file, 'r') as input_sha:
37 sha1 = input_sha.readline()
38 if os.path.exists(dest) and utils.get_sha1(dest) == sha1:
39 print('sha1 matches, not downloading')
40 dest_dir = utils.extract_dir(dest)
41 if os.path.exists(dest_dir):
42 print('destination directory exists, no extraction')
43 else:
44 utils.unpack_archive(dest)
45 return
46 src = os.path.join(GMSCORE_DEPS, sha1)
47 if not os.path.exists(src):
48 print('File (%s) does not exist on x20' % src)
49 print('Maybe pass -Pno_internal to your gradle invocation')
50 return 42
51 download(src, dest)
52
Mads Ager418d1ca2017-05-22 09:35:49 +020053
54if __name__ == '__main__':
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020055 sys.exit(Main())