Christoffer Quist Adamsen | fb2caf8 | 2021-06-01 13:50:30 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 2 | # 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 | |
| 9 | import optparse |
| 10 | import os |
| 11 | import shutil |
| 12 | import subprocess |
| 13 | import sys |
| 14 | import tarfile |
| 15 | import utils |
| 16 | |
Jeffrey van Gogh | 5dac448 | 2018-01-24 02:36:38 -0800 | [diff] [blame] | 17 | GMSCORE_DEPS = '/google/data/ro/teams/r8/deps' |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 18 | |
| 19 | def parse_options(): |
| 20 | return optparse.OptionParser().parse_args() |
| 21 | |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 22 | def download(src, dest): |
Christoffer Quist Adamsen | fb2caf8 | 2021-06-01 13:50:30 +0200 | [diff] [blame] | 23 | print('Downloading %s to %s' % (src, dest)) |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 24 | shutil.copyfile(src, dest) |
| 25 | utils.unpack_archive(dest) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 26 | |
| 27 | def Main(): |
| 28 | (options, args) = parse_options() |
| 29 | assert len(args) == 1 |
| 30 | sha1_file = args[0] |
| 31 | dest = sha1_file[:-5] |
Christoffer Quist Adamsen | fb2caf8 | 2021-06-01 13:50:30 +0200 | [diff] [blame] | 32 | print('Ensuring %s' % dest) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 33 | 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 Adamsen | fb2caf8 | 2021-06-01 13:50:30 +0200 | [diff] [blame] | 36 | print('sha1 matches, not downloading') |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 37 | dest_dir = utils.extract_dir(dest) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 38 | if os.path.exists(dest_dir): |
Christoffer Quist Adamsen | fb2caf8 | 2021-06-01 13:50:30 +0200 | [diff] [blame] | 39 | print('destination directory exists, no extraction') |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 40 | else: |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 41 | utils.unpack_archive(dest) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 42 | return |
| 43 | src = os.path.join(GMSCORE_DEPS, sha1) |
| 44 | if not os.path.exists(src): |
Christoffer Quist Adamsen | fb2caf8 | 2021-06-01 13:50:30 +0200 | [diff] [blame] | 45 | print('File (%s) does not exist on x20' % src) |
| 46 | print('Maybe pass -Pno_internal to your gradle invocation') |
Stephan Herhut | 79d66bd | 2017-09-20 09:18:57 +0200 | [diff] [blame] | 47 | return 42 |
Jean-Marie Henaff | 7a64eec | 2018-05-31 15:30:35 +0200 | [diff] [blame] | 48 | download(src, dest) |
Mads Ager | 418d1ca | 2017-05-22 09:35:49 +0200 | [diff] [blame] | 49 | |
| 50 | if __name__ == '__main__': |
| 51 | sys.exit(Main()) |