blob: 579682360b6fb3da869153c63c546960a0da54df [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
19def parse_options():
20 return optparse.OptionParser().parse_args()
21
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020022def download(src, dest):
Christoffer Quist Adamsenfb2caf82021-06-01 13:50:30 +020023 print('Downloading %s to %s' % (src, dest))
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020024 shutil.copyfile(src, dest)
25 utils.unpack_archive(dest)
Mads Ager418d1ca2017-05-22 09:35:49 +020026
27def Main():
28 (options, args) = parse_options()
29 assert len(args) == 1
30 sha1_file = args[0]
31 dest = sha1_file[:-5]
Christoffer Quist Adamsenfb2caf82021-06-01 13:50:30 +020032 print('Ensuring %s' % dest)
Mads Ager418d1ca2017-05-22 09:35:49 +020033 with open(sha1_file, 'r') as input_sha:
34 sha1 = input_sha.readline()
35 if os.path.exists(dest) and utils.get_sha1(dest) == sha1:
Christoffer Quist Adamsenfb2caf82021-06-01 13:50:30 +020036 print('sha1 matches, not downloading')
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020037 dest_dir = utils.extract_dir(dest)
Mads Ager418d1ca2017-05-22 09:35:49 +020038 if os.path.exists(dest_dir):
Christoffer Quist Adamsenfb2caf82021-06-01 13:50:30 +020039 print('destination directory exists, no extraction')
Mads Ager418d1ca2017-05-22 09:35:49 +020040 else:
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020041 utils.unpack_archive(dest)
Mads Ager418d1ca2017-05-22 09:35:49 +020042 return
43 src = os.path.join(GMSCORE_DEPS, sha1)
44 if not os.path.exists(src):
Christoffer Quist Adamsenfb2caf82021-06-01 13:50:30 +020045 print('File (%s) does not exist on x20' % src)
46 print('Maybe pass -Pno_internal to your gradle invocation')
Stephan Herhut79d66bd2017-09-20 09:18:57 +020047 return 42
Jean-Marie Henaff7a64eec2018-05-31 15:30:35 +020048 download(src, dest)
Mads Ager418d1ca2017-05-22 09:35:49 +020049
50if __name__ == '__main__':
51 sys.exit(Main())