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 | |
| 6 | import argparse |
| 7 | import os |
| 8 | from os.path import join |
| 9 | import shutil |
| 10 | import subprocess |
| 11 | import sys |
| 12 | |
| 13 | import utils |
| 14 | |
| 15 | def GetGitHash(checkout_dir): |
| 16 | return subprocess.check_output( |
| 17 | ['git', '-C', checkout_dir, 'rev-parse', 'HEAD']).decode('utf-8').strip() |
| 18 | |
| 19 | def run(args): |
| 20 | with utils.TempDir() as tmp_dir: |
| 21 | use_existing_checkout = args.desugar_jdk_libs_checkout != None |
| 22 | checkout_dir = (args.desugar_jdk_libs_checkout |
| 23 | if use_existing_checkout |
| 24 | else join(tmp_dir, 'desugar_jdk_libs')) |
| 25 | if (not use_existing_checkout): |
| 26 | subprocess.check_call( |
| 27 | ['git', 'clone', 'https://github.com/google/desugar_jdk_libs.git', checkout_dir]) |
| 28 | if (args.desugar_jdk_libs_revision): |
| 29 | subprocess.check_call( |
| 30 | ['git', '-C', checkout_dir, 'checkout', args.desugar_jdk_libs_revision]) |
| 31 | print("Building desugared library") |
| 32 | bazel = os.path.join(utils.BAZEL_TOOL, 'lib', 'bazel', 'bin', 'bazel') |
| 33 | with utils.ChangedWorkingDirectory(checkout_dir): |
| 34 | for target in [':desugar_jdk_libs_jdk11', '//jdk11/src:java_base_chm_only']: |
| 35 | subprocess.check_call([ |
| 36 | bazel, |
| 37 | '--bazelrc=/dev/null', |
| 38 | 'build', |
| 39 | '--spawn_strategy=local', |
| 40 | '--verbose_failures', |
| 41 | target]) |
| 42 | |
| 43 | openjdk_dir = join('third_party', 'openjdk') |
| 44 | openjdk_subdir = 'desugar_jdk_libs_11' |
| 45 | dest_dir = join(openjdk_dir, openjdk_subdir) |
| 46 | src_dir = join(checkout_dir, 'bazel-bin', 'jdk11', 'src') |
| 47 | |
| 48 | metadata_files = ('LICENSE', 'README.google') |
| 49 | for f in metadata_files: |
| 50 | shutil.copyfile(join(dest_dir, f), join(tmp_dir, f)) |
| 51 | shutil.rmtree(dest_dir) |
| 52 | os.remove(join(openjdk_dir, openjdk_subdir + '.tar.gz')) |
| 53 | os.remove(join(openjdk_dir, openjdk_subdir + '.tar.gz.sha1')) |
| 54 | os.mkdir(dest_dir) |
| 55 | for s in [ |
| 56 | (join(src_dir, 'd8_java_base_selected_with_addon.jar'), |
| 57 | join(dest_dir, 'desugar_jdk_libs.jar')), |
| 58 | (join(src_dir, 'java_base_chm_only.jar'), |
| 59 | join(dest_dir, 'desugar_jdk_libs_chm_only.jar'))]: |
| 60 | shutil.copyfile(s[0], s[1]) |
| 61 | for f in metadata_files: |
| 62 | shutil.copyfile(join(tmp_dir, f), join(dest_dir, f)) |
| 63 | desugar_jdk_libs_hash = os.path.join(dest_dir, 'desugar_jdk_libs_hash') |
| 64 | with open(desugar_jdk_libs_hash, 'w') as desugar_jdk_libs_hash_writer: |
| 65 | desugar_jdk_libs_hash_writer.write(GetGitHash(checkout_dir)) |
| 66 | |
| 67 | print('Now run') |
| 68 | print(' (cd %s; upload_to_google_storage.py -a --bucket r8-deps %s)' |
| 69 | % (openjdk_dir, openjdk_subdir)) |
| 70 | |
| 71 | |
| 72 | |
| 73 | def main(): |
| 74 | args = parse_options() |
| 75 | run(args) |
| 76 | |
| 77 | def parse_options(): |
| 78 | parser = argparse.ArgumentParser( |
| 79 | description='Script for updating third_party/openjdk/desugar_jdk_libs*') |
| 80 | parser.add_argument('--desugar-jdk-libs-checkout', '--desugar_jdk_libs_checkout', |
| 81 | default=None, |
| 82 | metavar=('<path>'), |
| 83 | help='Use existing checkout of github.com/google/desugar_jdk_libs.') |
| 84 | parser.add_argument('--desugar-jdk-libs-revision', '--desugar_jdk_libs_revision', |
| 85 | default=None, |
| 86 | metavar=('<revision>'), |
| 87 | help='Revision of github.com/google/desugar_jdk_libs to use.') |
| 88 | args = parser.parse_args() |
| 89 | return args |
| 90 | |
| 91 | |
| 92 | if __name__ == '__main__': |
| 93 | sys.exit(main()) |