Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 1 | #!/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 Gjesse | 0ea3f29 | 2023-02-02 14:43:48 +0100 | [diff] [blame] | 6 | from datetime import datetime |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 7 | import argparse |
| 8 | import os |
| 9 | from os.path import join |
Søren Gjesse | 0ea3f29 | 2023-02-02 14:43:48 +0100 | [diff] [blame] | 10 | import re |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 11 | import shutil |
| 12 | import subprocess |
| 13 | import sys |
| 14 | |
| 15 | import utils |
| 16 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 17 | |
Søren Gjesse | 0ea3f29 | 2023-02-02 14:43:48 +0100 | [diff] [blame] | 18 | def sed(pattern, replace, path): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 19 | 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 Gjesse | 0ea3f29 | 2023-02-02 14:43:48 +0100 | [diff] [blame] | 25 | |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 26 | def GetGitHash(checkout_dir): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 27 | return subprocess.check_output( |
| 28 | ['git', '-C', checkout_dir, 'rev-parse', |
| 29 | 'HEAD']).decode('utf-8').strip() |
| 30 | |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 31 | |
| 32 | def run(args): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 33 | 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 Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 62 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 63 | 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 Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 67 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 68 | 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 Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 89 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 90 | print('Now run') |
| 91 | print(' (cd %s; upload_to_google_storage.py -a --bucket r8-deps %s)' % |
| 92 | (openjdk_dir, openjdk_subdir)) |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 93 | |
| 94 | |
| 95 | def main(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 96 | args = parse_options() |
| 97 | run(args) |
| 98 | |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 99 | |
| 100 | def parse_options(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 101 | 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 Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 117 | |
| 118 | |
| 119 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 120 | sys.exit(main()) |