Søren Gjesse | 3bbef10 | 2024-11-14 12:42:50 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright (c) 2024, 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 | import shutil |
| 9 | import sys |
| 10 | import utils |
| 11 | |
| 12 | |
| 13 | def parse_options(): |
| 14 | parser = argparse.ArgumentParser(description='Release r8') |
| 15 | parser.add_argument('--sdk-home', |
| 16 | '--sdk_home', |
| 17 | metavar=('<SDK_HOME>'), |
| 18 | help='SDK_HOME to use for finding SDK') |
| 19 | parser.add_argument('--sdk-name', |
| 20 | '--sdk_name', |
| 21 | required=True, |
| 22 | metavar=('<name>'), |
| 23 | help='Name of the SDK, either API level or code name') |
Søren Gjesse | 1ba4f01 | 2024-11-22 12:50:42 +0100 | [diff] [blame] | 24 | parser.add_argument('--api-level', |
| 25 | '--api_level', |
| 26 | metavar=('<level>'), |
| 27 | help='API level to add this as in third_party') |
Søren Gjesse | 3bbef10 | 2024-11-14 12:42:50 +0100 | [diff] [blame] | 28 | return parser.parse_args() |
| 29 | |
| 30 | |
| 31 | def remove(path): |
| 32 | try: |
| 33 | os.remove(path) |
| 34 | except FileNotFoundError: |
| 35 | pass |
| 36 | |
| 37 | |
| 38 | def generate_readme_google(destination, sdk_name): |
| 39 | with open(os.path.join(destination, 'README.google'), 'w') as f: |
| 40 | f.write('Name: Android SDK excerpts\n') |
| 41 | f.write('URL: https://developer.android.com/tools/sdkmanager\n') |
| 42 | f.write('Version: API version %s\n' % sdk_name) |
| 43 | f.write('Revision: N/A\n') |
| 44 | f.write('License: Apache License Version 2.0\n') |
| 45 | f.write('\n') |
| 46 | f.write('Description:\n') |
| 47 | f.write('This is excerpts from an Android SDK including android.jar.\n') |
| 48 | |
| 49 | |
| 50 | def main(): |
| 51 | args = parse_options() |
| 52 | |
| 53 | if not args.sdk_home: |
| 54 | args.sdk_home = os.environ.get('SDK_HOME') |
| 55 | if not args.sdk_home: |
| 56 | print('No SDK_HOME specified') |
| 57 | sys.exit(1) |
| 58 | else: |
| 59 | print('Using SDK_HOME: %s' % args.sdk_home) |
| 60 | |
| 61 | source = os.path.join(args.sdk_home, 'platforms', |
| 62 | 'android-%s' % args.sdk_name) |
| 63 | if not os.path.exists(source): |
| 64 | print('Path %s does not exist' % source) |
| 65 | sys.exit(1) |
| 66 | |
Søren Gjesse | 1ba4f01 | 2024-11-22 12:50:42 +0100 | [diff] [blame] | 67 | api_level = -1 |
| 68 | try: |
| 69 | api_level = int(args.api_level if args.api_level else args.sdk_name) |
| 70 | except: |
| 71 | print('API level "%s" must be an integer' |
| 72 | % (args.api_level if args.api_level else args.sdk_name)) |
| 73 | sys.exit(1) |
| 74 | |
| 75 | destination = utils.get_android_jar_dir(api_level) |
Søren Gjesse | 3bbef10 | 2024-11-14 12:42:50 +0100 | [diff] [blame] | 76 | |
| 77 | # Remove existing if present. |
| 78 | shutil.rmtree(destination, ignore_errors=True) |
| 79 | remove(destination + 'tar.gz') |
| 80 | remove(destination + 'tar.gz.sha1') |
| 81 | |
| 82 | # Copy the files of interest. |
| 83 | destination_optional_path = os.path.join(destination, 'optional') |
| 84 | os.makedirs(os.path.join(destination_optional_path)) |
| 85 | shutil.copyfile(os.path.join(source, 'android.jar'), |
| 86 | os.path.join(destination, 'android.jar')) |
| 87 | shutil.copyfile(os.path.join(source, 'data', 'api-versions.xml'), |
| 88 | os.path.join(destination, 'api-versions.xml')) |
| 89 | source_optional_path = os.path.join(source, 'optional') |
| 90 | for root, dirnames, filenames in os.walk(source_optional_path): |
| 91 | for filename in filenames: |
| 92 | if filename.endswith('.jar') or filename == 'optional.json': |
| 93 | shutil.copyfile( |
| 94 | os.path.join(source_optional_path, filename), |
| 95 | os.path.join(destination_optional_path, filename)) |
| 96 | generate_readme_google(destination, args.sdk_name) |
| 97 | |
| 98 | print('If you want to upload this run:') |
| 99 | print(' (cd %s; upload_to_google_storage.py -a --bucket r8-deps %s)' % |
| 100 | (os.path.dirname(destination), os.path.basename(destination))) |
| 101 | print('Update d8_r8/commonBuildSrc/src/main/kotlin/DependenciesPlugin.kt' |
| 102 | ' if this is a new dependency.') |
Søren Gjesse | e73cf8e | 2025-03-07 15:59:25 +0100 | [diff] [blame] | 103 | print('Run main method in AndroidApiHashingDatabaseBuilderGeneratorTest' |
| 104 | ' to generate the API database.') |
Søren Gjesse | 3bbef10 | 2024-11-14 12:42:50 +0100 | [diff] [blame] | 105 | |
| 106 | if __name__ == '__main__': |
| 107 | sys.exit(main()) |