blob: 3514cf8c1cda7df0e4619e3a87bad927fdbc4479 [file] [log] [blame]
Søren Gjesse85c37922022-09-01 16:58:07 +02001#!/usr/bin/env python3
2# Copyright (c) 2022, 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
Søren Gjesse0ea3f292023-02-02 14:43:48 +01006from datetime import datetime
Søren Gjesse85c37922022-09-01 16:58:07 +02007import argparse
8import os
9from os.path import join
Søren Gjesse0ea3f292023-02-02 14:43:48 +010010import re
Søren Gjesse85c37922022-09-01 16:58:07 +020011import shutil
12import subprocess
13import sys
14
15import utils
16
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020017
Søren Gjesse0ea3f292023-02-02 14:43:48 +010018def sed(pattern, replace, path):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020019 with open(path, "r") as sources:
20 lines = sources.readlines()
21 with open(path, "w") as sources:
22 for line in lines:
23 sources.write(re.sub(pattern, replace, line))
24
Søren Gjesse0ea3f292023-02-02 14:43:48 +010025
Søren Gjesse85c37922022-09-01 16:58:07 +020026def GetGitHash(checkout_dir):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020027 return subprocess.check_output(
28 ['git', '-C', checkout_dir, 'rev-parse',
29 'HEAD']).decode('utf-8').strip()
30
Søren Gjesse85c37922022-09-01 16:58:07 +020031
32def run(args):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020033 with utils.TempDir() as tmp_dir:
34 use_existing_checkout = args.desugar_jdk_libs_checkout != None
35 checkout_dir = (args.desugar_jdk_libs_checkout if use_existing_checkout
36 else join(tmp_dir, 'desugar_jdk_libs'))
37 if (not use_existing_checkout):
38 subprocess.check_call([
39 'git', 'clone',
40 'https://github.com/google/desugar_jdk_libs.git', checkout_dir
41 ])
42 if (args.desugar_jdk_libs_revision):
43 subprocess.check_call([
44 'git', '-C', checkout_dir, 'checkout',
45 args.desugar_jdk_libs_revision
46 ])
47 print("Hack to workaround b/256723819")
48 os.remove(
49 join(checkout_dir, "jdk11", "src", "java.base", "share", "classes",
50 "java", "time", "format",
51 "DesugarDateTimeFormatterBuilder.java"))
52 print("Building desugared library")
53 bazel = os.path.join(utils.BAZEL_TOOL, 'lib', 'bazel', 'bin', 'bazel')
54 with utils.ChangedWorkingDirectory(checkout_dir):
55 for target in [
56 ':desugar_jdk_libs_jdk11', '//jdk11/src:java_base_chm_only'
57 ]:
58 subprocess.check_call([
59 bazel, '--bazelrc=/dev/null', 'build',
60 '--spawn_strategy=local', '--verbose_failures', target
61 ])
Søren Gjesse85c37922022-09-01 16:58:07 +020062
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020063 openjdk_dir = join('third_party', 'openjdk')
64 openjdk_subdir = 'desugar_jdk_libs_11'
65 dest_dir = join(openjdk_dir, openjdk_subdir)
66 src_dir = join(checkout_dir, 'bazel-bin', 'jdk11', 'src')
Søren Gjesse85c37922022-09-01 16:58:07 +020067
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020068 metadata_files = ('LICENSE', 'README.google')
69 for f in metadata_files:
70 shutil.copyfile(join(dest_dir, f), join(tmp_dir, f))
71 shutil.rmtree(dest_dir)
72 os.remove(join(openjdk_dir, openjdk_subdir + '.tar.gz'))
73 os.remove(join(openjdk_dir, openjdk_subdir + '.tar.gz.sha1'))
74 os.mkdir(dest_dir)
75 for s in [(join(src_dir, 'd8_java_base_selected_with_addon.jar'),
76 join(dest_dir, 'desugar_jdk_libs.jar')),
77 (join(src_dir, 'java_base_chm_only.jar'),
78 join(dest_dir, 'desugar_jdk_libs_chm_only.jar'))]:
79 shutil.copyfile(s[0], s[1])
80 for f in metadata_files:
81 shutil.copyfile(join(tmp_dir, f), join(dest_dir, f))
82 desugar_jdk_libs_hash = os.path.join(dest_dir, 'desugar_jdk_libs_hash')
83 with open(desugar_jdk_libs_hash, 'w') as desugar_jdk_libs_hash_writer:
84 desugar_jdk_libs_hash_writer.write(GetGitHash(checkout_dir))
85 sed('^Version: [0-9a-f]{40}$', 'Version: %s' % GetGitHash(checkout_dir),
86 join(dest_dir, 'README.google'))
87 sed('^Date: .*$', 'Date: %s' % datetime.today().strftime('%Y-%m-%d'),
88 join(dest_dir, 'README.google'))
Søren Gjesse85c37922022-09-01 16:58:07 +020089
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020090 print('Now run')
91 print(' (cd %s; upload_to_google_storage.py -a --bucket r8-deps %s)' %
92 (openjdk_dir, openjdk_subdir))
Søren Gjesse85c37922022-09-01 16:58:07 +020093
94
95def main():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020096 args = parse_options()
97 run(args)
98
Søren Gjesse85c37922022-09-01 16:58:07 +020099
100def parse_options():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200101 parser = argparse.ArgumentParser(
102 description='Script for updating third_party/openjdk/desugar_jdk_libs*')
103 parser.add_argument(
104 '--desugar-jdk-libs-checkout',
105 '--desugar_jdk_libs_checkout',
106 default=None,
107 metavar=('<path>'),
108 help='Use existing checkout of github.com/google/desugar_jdk_libs.')
109 parser.add_argument(
110 '--desugar-jdk-libs-revision',
111 '--desugar_jdk_libs_revision',
112 default=None,
113 metavar=('<revision>'),
114 help='Revision of github.com/google/desugar_jdk_libs to use.')
115 args = parser.parse_args()
116 return args
Søren Gjesse85c37922022-09-01 16:58:07 +0200117
118
119if __name__ == '__main__':
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200120 sys.exit(main())