blob: 343a7f2e2307d63ab9a87430e69df2a28500dbef [file] [log] [blame]
Søren Gjesse1c115b52019-08-14 12:43:57 +02001#!/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 Wind70d614f2020-01-31 08:45:21 +010018# https://storage.googleapis.com/r8-releases/raw can be treated as a maven
Søren Gjesse1c115b52019-08-14 12:43:57 +020019# repository to fetch the artifact com.android.tools:desugar_jdk_libs:1.0.0
20
21import archive
22import git_utils
23import optparse
24import os
25import re
26import shutil
27import subprocess
28import sys
29import utils
30
31VERSION_FILE = 'VERSION.txt'
32LIBRARY_NAME = 'desugar_jdk_libs'
33
34def 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 Gjesse07b6aea2019-12-12 11:11:58 +010051def GetVersion(version_file_name):
52 with open(version_file_name, 'r') as version_file:
Søren Gjessef298e7a2019-12-06 09:57:36 +010053 lines = [line.strip() for line in version_file.readlines()]
54 lines = [line for line in lines if not line.startswith('#')]
Søren Gjesse1c115b52019-08-14 12:43:57 +020055 if len(lines) != 1:
56 raise Exception('Version file '
Søren Gjesse07b6aea2019-12-12 11:11:58 +010057 + version_file + ' is expected to have exactly one line')
Søren Gjesse1c115b52019-08-14 12:43:57 +020058 version = lines[0].strip()
Søren Gjesse1e171532019-09-03 09:44:22 +020059 utils.check_basic_semver_version(
Søren Gjesse07b6aea2019-12-12 11:11:58 +010060 version, 'in version file ' + version_file_name)
Søren Gjesse1c115b52019-08-14 12:43:57 +020061 return version
62
63
64def 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 Wind70d614f2020-01-31 08:45:21 +010078 destination.replace('gs://', 'https://storage.googleapis.com/', 1))
Søren Gjesse1c115b52019-08-14 12:43:57 +020079
80
81def 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 Gjesse699f6362019-10-09 14:56:33 +020099 utils.DownloadFromGoogleCloudStorage(utils.JAVA8_SHA_FILE)
Søren Gjesse1c115b52019-08-14 12:43:57 +0200100
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 Gjesse07b6aea2019-12-12 11:11:58 +0100109 version = GetVersion(VERSION_FILE)
Søren Gjesse1c115b52019-08-14 12:43:57 +0200110
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 Gjesse7f7343e2020-06-10 09:16:58 +0200118 cmd = [bazel, 'build', 'maven_release']
Søren Gjesse1c115b52019-08-14 12:43:57 +0200119 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 Gjesse1c115b52019-08-14 12:43:57 +0200131 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
154if __name__ == '__main__':
155 sys.exit(Main(sys.argv[1:]))