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): |
Søren Gjesse | d10fec9 | 2024-08-19 11:27:07 +0200 | [diff] [blame] | 55 | subprocess.check_call([ |
| 56 | bazel, '--bazelrc=/dev/null', 'build', |
| 57 | '--spawn_strategy=local', '--verbose_failures', ':desugar_jdk_libs_jdk11' |
| 58 | ]) |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 59 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 60 | openjdk_dir = join('third_party', 'openjdk') |
| 61 | openjdk_subdir = 'desugar_jdk_libs_11' |
| 62 | dest_dir = join(openjdk_dir, openjdk_subdir) |
| 63 | src_dir = join(checkout_dir, 'bazel-bin', 'jdk11', 'src') |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 64 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 65 | metadata_files = ('LICENSE', 'README.google') |
| 66 | for f in metadata_files: |
| 67 | shutil.copyfile(join(dest_dir, f), join(tmp_dir, f)) |
| 68 | shutil.rmtree(dest_dir) |
| 69 | os.remove(join(openjdk_dir, openjdk_subdir + '.tar.gz')) |
| 70 | os.remove(join(openjdk_dir, openjdk_subdir + '.tar.gz.sha1')) |
| 71 | os.mkdir(dest_dir) |
Søren Gjesse | d10fec9 | 2024-08-19 11:27:07 +0200 | [diff] [blame] | 72 | shutil.copyfile( |
| 73 | join(src_dir, 'd8_java_base_selected_with_addon.jar'), |
| 74 | join(dest_dir, 'desugar_jdk_libs.jar')) |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 75 | for f in metadata_files: |
| 76 | shutil.copyfile(join(tmp_dir, f), join(dest_dir, f)) |
| 77 | desugar_jdk_libs_hash = os.path.join(dest_dir, 'desugar_jdk_libs_hash') |
| 78 | with open(desugar_jdk_libs_hash, 'w') as desugar_jdk_libs_hash_writer: |
| 79 | desugar_jdk_libs_hash_writer.write(GetGitHash(checkout_dir)) |
| 80 | sed('^Version: [0-9a-f]{40}$', 'Version: %s' % GetGitHash(checkout_dir), |
| 81 | join(dest_dir, 'README.google')) |
| 82 | sed('^Date: .*$', 'Date: %s' % datetime.today().strftime('%Y-%m-%d'), |
| 83 | join(dest_dir, 'README.google')) |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 84 | |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 85 | print('Now run') |
| 86 | print(' (cd %s; upload_to_google_storage.py -a --bucket r8-deps %s)' % |
| 87 | (openjdk_dir, openjdk_subdir)) |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 88 | |
| 89 | |
| 90 | def main(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 91 | args = parse_options() |
| 92 | run(args) |
| 93 | |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 94 | |
| 95 | def parse_options(): |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 96 | parser = argparse.ArgumentParser( |
| 97 | description='Script for updating third_party/openjdk/desugar_jdk_libs*') |
| 98 | parser.add_argument( |
| 99 | '--desugar-jdk-libs-checkout', |
| 100 | '--desugar_jdk_libs_checkout', |
| 101 | default=None, |
| 102 | metavar=('<path>'), |
| 103 | help='Use existing checkout of github.com/google/desugar_jdk_libs.') |
| 104 | parser.add_argument( |
| 105 | '--desugar-jdk-libs-revision', |
| 106 | '--desugar_jdk_libs_revision', |
| 107 | default=None, |
| 108 | metavar=('<revision>'), |
| 109 | help='Revision of github.com/google/desugar_jdk_libs to use.') |
| 110 | args = parser.parse_args() |
| 111 | return args |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 112 | |
| 113 | |
| 114 | if __name__ == '__main__': |
Christoffer Quist Adamsen | 2434a4d | 2023-10-16 11:29:03 +0200 | [diff] [blame] | 115 | sys.exit(main()) |