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 | |
Søren Gjesse | 0ea3f29 | 2023-02-02 14:43:48 +0100 | [diff] [blame] | 17 | def sed(pattern, replace, path): |
| 18 | with open(path, "r") as sources: |
| 19 | lines = sources.readlines() |
| 20 | with open(path, "w") as sources: |
| 21 | for line in lines: |
| 22 | sources.write(re.sub(pattern, replace, line)) |
| 23 | |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 24 | def GetGitHash(checkout_dir): |
| 25 | return subprocess.check_output( |
| 26 | ['git', '-C', checkout_dir, 'rev-parse', 'HEAD']).decode('utf-8').strip() |
| 27 | |
| 28 | def run(args): |
| 29 | with utils.TempDir() as tmp_dir: |
| 30 | use_existing_checkout = args.desugar_jdk_libs_checkout != None |
| 31 | checkout_dir = (args.desugar_jdk_libs_checkout |
| 32 | if use_existing_checkout |
| 33 | else join(tmp_dir, 'desugar_jdk_libs')) |
| 34 | if (not use_existing_checkout): |
| 35 | subprocess.check_call( |
| 36 | ['git', 'clone', 'https://github.com/google/desugar_jdk_libs.git', checkout_dir]) |
| 37 | if (args.desugar_jdk_libs_revision): |
| 38 | subprocess.check_call( |
| 39 | ['git', '-C', checkout_dir, 'checkout', args.desugar_jdk_libs_revision]) |
Søren Gjesse | 4b16c1b | 2023-01-30 15:04:30 +0100 | [diff] [blame] | 40 | print("Hack to workaround b/256723819") |
| 41 | os.remove( |
| 42 | join( |
| 43 | checkout_dir, |
| 44 | "jdk11", |
| 45 | "src", |
| 46 | "java.base", |
| 47 | "share", |
| 48 | "classes", |
| 49 | "java", |
| 50 | "time", |
| 51 | "format", |
| 52 | "DesugarDateTimeFormatterBuilder.java")) |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 53 | print("Building desugared library") |
| 54 | bazel = os.path.join(utils.BAZEL_TOOL, 'lib', 'bazel', 'bin', 'bazel') |
| 55 | with utils.ChangedWorkingDirectory(checkout_dir): |
| 56 | for target in [':desugar_jdk_libs_jdk11', '//jdk11/src:java_base_chm_only']: |
| 57 | subprocess.check_call([ |
| 58 | bazel, |
| 59 | '--bazelrc=/dev/null', |
| 60 | 'build', |
| 61 | '--spawn_strategy=local', |
| 62 | '--verbose_failures', |
| 63 | target]) |
| 64 | |
| 65 | openjdk_dir = join('third_party', 'openjdk') |
| 66 | openjdk_subdir = 'desugar_jdk_libs_11' |
| 67 | dest_dir = join(openjdk_dir, openjdk_subdir) |
| 68 | src_dir = join(checkout_dir, 'bazel-bin', 'jdk11', 'src') |
| 69 | |
| 70 | metadata_files = ('LICENSE', 'README.google') |
| 71 | for f in metadata_files: |
| 72 | shutil.copyfile(join(dest_dir, f), join(tmp_dir, f)) |
| 73 | shutil.rmtree(dest_dir) |
| 74 | os.remove(join(openjdk_dir, openjdk_subdir + '.tar.gz')) |
| 75 | os.remove(join(openjdk_dir, openjdk_subdir + '.tar.gz.sha1')) |
| 76 | os.mkdir(dest_dir) |
| 77 | for s in [ |
| 78 | (join(src_dir, 'd8_java_base_selected_with_addon.jar'), |
| 79 | join(dest_dir, 'desugar_jdk_libs.jar')), |
| 80 | (join(src_dir, 'java_base_chm_only.jar'), |
| 81 | join(dest_dir, 'desugar_jdk_libs_chm_only.jar'))]: |
| 82 | shutil.copyfile(s[0], s[1]) |
| 83 | for f in metadata_files: |
| 84 | shutil.copyfile(join(tmp_dir, f), join(dest_dir, f)) |
| 85 | desugar_jdk_libs_hash = os.path.join(dest_dir, 'desugar_jdk_libs_hash') |
| 86 | with open(desugar_jdk_libs_hash, 'w') as desugar_jdk_libs_hash_writer: |
| 87 | desugar_jdk_libs_hash_writer.write(GetGitHash(checkout_dir)) |
Søren Gjesse | 0ea3f29 | 2023-02-02 14:43:48 +0100 | [diff] [blame] | 88 | sed('^Version: [0-9a-f]{40}$', |
| 89 | 'Version: %s' % GetGitHash(checkout_dir), |
| 90 | join(dest_dir, 'README.google')) |
| 91 | sed('^Date: .*$', |
| 92 | 'Date: %s' % datetime.today().strftime('%Y-%m-%d'), |
| 93 | join(dest_dir, 'README.google')) |
Søren Gjesse | 85c3792 | 2022-09-01 16:58:07 +0200 | [diff] [blame] | 94 | |
| 95 | print('Now run') |
| 96 | print(' (cd %s; upload_to_google_storage.py -a --bucket r8-deps %s)' |
| 97 | % (openjdk_dir, openjdk_subdir)) |
| 98 | |
| 99 | |
| 100 | |
| 101 | def main(): |
| 102 | args = parse_options() |
| 103 | run(args) |
| 104 | |
| 105 | def parse_options(): |
| 106 | parser = argparse.ArgumentParser( |
| 107 | description='Script for updating third_party/openjdk/desugar_jdk_libs*') |
| 108 | parser.add_argument('--desugar-jdk-libs-checkout', '--desugar_jdk_libs_checkout', |
| 109 | default=None, |
| 110 | metavar=('<path>'), |
| 111 | help='Use existing checkout of github.com/google/desugar_jdk_libs.') |
| 112 | parser.add_argument('--desugar-jdk-libs-revision', '--desugar_jdk_libs_revision', |
| 113 | default=None, |
| 114 | metavar=('<revision>'), |
| 115 | help='Revision of github.com/google/desugar_jdk_libs to use.') |
| 116 | args = parser.parse_args() |
| 117 | return args |
| 118 | |
| 119 | |
| 120 | if __name__ == '__main__': |
| 121 | sys.exit(main()) |