Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2017, 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 | import d8 |
| 7 | import os |
| 8 | import r8 |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 9 | import subprocess |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 10 | import sys |
| 11 | import utils |
| 12 | |
Rico Wind | 792e8c7 | 2017-08-30 09:43:46 +0200 | [diff] [blame] | 13 | ARCHIVE_BUCKET = 'r8-releases' |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 14 | |
| 15 | def GetVersion(): |
| 16 | r8_version = r8.run(['--version'], build = False).strip() |
| 17 | d8_version = d8.run(['--version'], build = False).strip() |
| 18 | # The version printed is "D8 vVERSION_NUMBER" and "R8 vVERSION_NUMBER" |
| 19 | # Sanity check that versions match. |
| 20 | if d8_version.split()[1] != r8_version.split()[1]: |
| 21 | raise Exception( |
| 22 | 'Version mismatch: \n%s\n%s' % (d8_version, r8_version)) |
| 23 | return d8_version.split()[1] |
| 24 | |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 25 | def GetGitBranches(): |
| 26 | return subprocess.check_output(['git', 'show', '-s', '--pretty=%d', 'HEAD']) |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 27 | |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 28 | def GetGitHash(): |
| 29 | return subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 30 | |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 31 | def IsMaster(version): |
Rico Wind | 2f72029 | 2017-10-06 14:32:12 +0200 | [diff] [blame^] | 32 | branches = subprocess.check_output(['git', 'branch', '-r', '--contains', |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 33 | 'HEAD']) |
| 34 | if not version.endswith('-dev'): |
| 35 | # Sanity check, we don't want to archive on top of release builds EVER |
| 36 | # Note that even though we branch, we never push the bots to build the same |
| 37 | # commit as master on a branch since we always change the version to |
| 38 | # not have dev (or we crash here :-)). |
| 39 | if 'origin/master' in branches: |
| 40 | raise Exception('We are seeing origin/master in a commit that ' |
| 41 | 'don\'t have -dev in version') |
| 42 | return False; |
| 43 | if not 'origin/master' in branches: |
| 44 | raise Exception('We are not seeing origin/master ' |
| 45 | 'in a commit that have -dev in version') |
| 46 | return True; |
| 47 | |
| 48 | def GetStorageDestination(storage_prefix, version, file_name, is_master): |
| 49 | # We archive master commits under raw/master instead of directly under raw |
| 50 | archive_dir = 'raw/master' if is_master else 'raw' |
| 51 | return '%s%s/%s/%s/%s' % (storage_prefix, ARCHIVE_BUCKET, archive_dir, |
| 52 | version, file_name) |
| 53 | |
| 54 | def GetUploadDestination(version, file_name, is_master): |
| 55 | return GetStorageDestination('gs://', version, file_name, is_master) |
| 56 | |
| 57 | def GetUrl(version, file_name, is_master): |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 58 | return GetStorageDestination('http://storage.googleapis.com/', |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 59 | version, file_name, is_master) |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 60 | |
| 61 | def Main(): |
| 62 | if not 'BUILDBOT_BUILDERNAME' in os.environ: |
| 63 | raise Exception('You are not a bot, don\'t archive builds') |
| 64 | version = GetVersion() |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 65 | is_master = IsMaster(version) |
| 66 | if is_master: |
| 67 | # On master we use the git hash to archive with |
| 68 | print 'On master, using git hash for archiving' |
| 69 | version = GetGitHash() |
| 70 | |
Rico Wind | 74fab30 | 2017-10-02 07:25:33 +0200 | [diff] [blame] | 71 | for jar in [utils.D8_JAR, utils.R8_JAR, utils.COMPATDX_JAR]: |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 72 | file_name = os.path.basename(jar) |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 73 | destination = GetUploadDestination(version, file_name, is_master) |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 74 | print('Uploading %s to %s' % (jar, destination)) |
| 75 | utils.upload_file_to_cloud_storage(jar, destination) |
Rico Wind | 0c24ae7 | 2017-09-08 11:33:56 +0200 | [diff] [blame] | 76 | print('File available at: %s' % GetUrl(version, file_name, is_master)) |
Rico Wind | b4621c1 | 2017-08-28 12:48:53 +0200 | [diff] [blame] | 77 | |
| 78 | if __name__ == '__main__': |
| 79 | sys.exit(Main()) |