Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2019, 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 | # This script is designed to run on a buildbot to build from the source |
| 7 | # of https://github.com/google/desugar_jdk_libs and publish to the |
| 8 | # r8-release Cloud Storage Bucket. |
| 9 | # |
| 10 | # These files are uploaded: |
| 11 | # |
| 12 | # raw/desugar_jdk_libs/<VERSION>/desugar_jdk_libs.jar |
| 13 | # raw/desugar_jdk_libs/<VERSION>/desugar_jdk_libs.zip |
| 14 | # raw/com/android/tools/desugar_jdk_libs/<VERSION>/desugar_jdk_libs-<VERSION>.jar |
| 15 | # |
| 16 | # The first two are the raw jar file and the maven compatible zip file. The |
| 17 | # third is the raw jar file placed and named so that the URL |
Rico Wind | 70d614f | 2020-01-31 08:45:21 +0100 | [diff] [blame] | 18 | # https://storage.googleapis.com/r8-releases/raw can be treated as a maven |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 19 | # repository to fetch the artifact com.android.tools:desugar_jdk_libs:1.0.0 |
| 20 | |
| 21 | import archive |
| 22 | import git_utils |
| 23 | import optparse |
| 24 | import os |
| 25 | import re |
| 26 | import shutil |
| 27 | import subprocess |
| 28 | import sys |
| 29 | import utils |
| 30 | |
| 31 | VERSION_FILE = 'VERSION.txt' |
| 32 | LIBRARY_NAME = 'desugar_jdk_libs' |
| 33 | |
| 34 | def ParseOptions(argv): |
| 35 | result = optparse.OptionParser() |
| 36 | result.add_option('--dry-run', '--dry_run', |
| 37 | help='Running on bot, use third_party dependency.', |
| 38 | default=False, |
| 39 | action='store_true') |
| 40 | result.add_option('--dry-run-output', '--dry_run_output', |
| 41 | help='Output directory for dry run.', |
| 42 | type="string", action="store") |
| 43 | result.add_option('--github-account', '--github_account', |
| 44 | help='GitHub account to clone from.', |
| 45 | default="google", |
| 46 | type="string", action="store") |
| 47 | (options, args) = result.parse_args(argv) |
| 48 | return (options, args) |
| 49 | |
| 50 | |
Søren Gjesse | 07b6aea | 2019-12-12 11:11:58 +0100 | [diff] [blame] | 51 | def GetVersion(version_file_name): |
| 52 | with open(version_file_name, 'r') as version_file: |
Søren Gjesse | f298e7a | 2019-12-06 09:57:36 +0100 | [diff] [blame] | 53 | lines = [line.strip() for line in version_file.readlines()] |
| 54 | lines = [line for line in lines if not line.startswith('#')] |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 55 | if len(lines) != 1: |
| 56 | raise Exception('Version file ' |
Søren Gjesse | 07b6aea | 2019-12-12 11:11:58 +0100 | [diff] [blame] | 57 | + version_file + ' is expected to have exactly one line') |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 58 | version = lines[0].strip() |
Søren Gjesse | 1e17153 | 2019-09-03 09:44:22 +0200 | [diff] [blame] | 59 | utils.check_basic_semver_version( |
Søren Gjesse | 07b6aea | 2019-12-12 11:11:58 +0100 | [diff] [blame] | 60 | version, 'in version file ' + version_file_name) |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 61 | return version |
| 62 | |
| 63 | |
| 64 | def Upload(options, file_name, storage_path, destination, is_master): |
| 65 | print('Uploading %s to %s' % (file_name, destination)) |
| 66 | if options.dry_run: |
| 67 | if options.dry_run_output: |
| 68 | dry_run_destination = \ |
| 69 | os.path.join(options.dry_run_output, os.path.basename(file_name)) |
| 70 | print('Dry run, not actually uploading. Copying to ' |
| 71 | + dry_run_destination) |
| 72 | shutil.copyfile(file_name, dry_run_destination) |
| 73 | else: |
| 74 | print('Dry run, not actually uploading') |
| 75 | else: |
| 76 | utils.upload_file_to_cloud_storage(file_name, destination) |
| 77 | print('File available at: %s' % |
Rico Wind | 70d614f | 2020-01-31 08:45:21 +0100 | [diff] [blame] | 78 | destination.replace('gs://', 'https://storage.googleapis.com/', 1)) |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 79 | |
| 80 | |
| 81 | def Main(argv): |
| 82 | (options, args) = ParseOptions(argv) |
| 83 | if (len(args) > 0): |
| 84 | raise Exception('Unsupported arguments') |
| 85 | if not utils.is_bot() and not options.dry_run: |
| 86 | raise Exception('You are not a bot, don\'t archive builds. ' |
| 87 | + 'Use --dry-run to test locally') |
| 88 | if (options.dry_run_output and |
| 89 | (not os.path.exists(options.dry_run_output) or |
| 90 | not os.path.isdir(options.dry_run_output))): |
| 91 | raise Exception(options.dry_run_output |
| 92 | + ' does not exist or is not a directory') |
| 93 | |
| 94 | if utils.is_bot(): |
| 95 | archive.SetRLimitToMax() |
| 96 | |
| 97 | # Make sure bazel is extracted in third_party. |
| 98 | utils.DownloadFromGoogleCloudStorage(utils.BAZEL_SHA_FILE) |
Søren Gjesse | 699f636 | 2019-10-09 14:56:33 +0200 | [diff] [blame] | 99 | utils.DownloadFromGoogleCloudStorage(utils.JAVA8_SHA_FILE) |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 100 | |
| 101 | # Only handling versioned desugar_jdk_libs. |
| 102 | is_master = False |
| 103 | |
| 104 | with utils.TempDir() as checkout_dir: |
| 105 | git_utils.GitClone( |
| 106 | 'https://github.com/' |
| 107 | + options.github_account + '/' + LIBRARY_NAME, checkout_dir) |
| 108 | with utils.ChangedWorkingDirectory(checkout_dir): |
Søren Gjesse | 07b6aea | 2019-12-12 11:11:58 +0100 | [diff] [blame] | 109 | version = GetVersion(VERSION_FILE) |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 110 | |
| 111 | destination = archive.GetVersionDestination( |
| 112 | 'gs://', LIBRARY_NAME + '/' + version, is_master) |
| 113 | if utils.cloud_storage_exists(destination) and not options.dry_run: |
| 114 | raise Exception( |
| 115 | 'Target archive directory %s already exists' % destination) |
| 116 | |
| 117 | bazel = os.path.join(utils.BAZEL_TOOL, 'lib', 'bazel', 'bin', 'bazel') |
Søren Gjesse | 7f7343e | 2020-06-10 09:16:58 +0200 | [diff] [blame] | 118 | cmd = [bazel, 'build', 'maven_release'] |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 119 | utils.PrintCmd(cmd) |
| 120 | subprocess.check_call(cmd) |
| 121 | cmd = [bazel, 'shutdown'] |
| 122 | utils.PrintCmd(cmd) |
| 123 | subprocess.check_call(cmd) |
| 124 | |
| 125 | # Locate the library jar and the maven zip with the jar from the |
| 126 | # bazel build. |
| 127 | library_jar = os.path.join( |
| 128 | 'bazel-bin', 'src', 'share', 'classes', 'java', 'libjava.jar') |
| 129 | maven_zip = os.path.join('bazel-bin', LIBRARY_NAME +'.zip') |
| 130 | |
Søren Gjesse | 1c115b5 | 2019-08-14 12:43:57 +0200 | [diff] [blame] | 131 | storage_path = LIBRARY_NAME + '/' + version |
| 132 | # Upload the jar file with the library. |
| 133 | destination = archive.GetUploadDestination( |
| 134 | storage_path, LIBRARY_NAME + '.jar', is_master) |
| 135 | Upload(options, library_jar, storage_path, destination, is_master) |
| 136 | |
| 137 | # Upload the maven zip file with the library. |
| 138 | destination = archive.GetUploadDestination( |
| 139 | storage_path, LIBRARY_NAME + '.zip', is_master) |
| 140 | Upload(options, maven_zip, storage_path, destination, is_master) |
| 141 | |
| 142 | # Upload the jar file for accessing GCS as a maven repro. |
| 143 | maven_destination = archive.GetUploadDestination( |
| 144 | utils.get_maven_path('desugar_jdk_libs', version), |
| 145 | 'desugar_jdk_libs-%s.jar' % version, |
| 146 | is_master) |
| 147 | if options.dry_run: |
| 148 | print('Dry run, not actually creating maven repo') |
| 149 | else: |
| 150 | utils.upload_file_to_cloud_storage(library_jar, maven_destination) |
| 151 | print('Maven repo root available at: %s' % archive.GetMavenUrl(is_master)) |
| 152 | |
| 153 | |
| 154 | if __name__ == '__main__': |
| 155 | sys.exit(Main(sys.argv[1:])) |