Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
Avi Drissman | 3f1ea44 | 2022-09-08 15:42:01 | [diff] [blame] | 3 | # Copyright 2020 The Chromium Authors |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """A script to generate build.gradle from template and run fetch_all.py |
| 7 | |
| 8 | More specifically, to generate build.gradle: |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 9 | - It downloads the index page for the latest androidx snapshot from |
| 10 | https://androidx.dev/snapshots/latest/artifacts |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 11 | - It replaces {{androidx_repository_url}} with the URL for the latest snapshot |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 12 | - For each dependency, it looks up the version in the index page's HTML and |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 13 | substitutes the version into {{androidx_dependency_version}}. |
Peter Wen | 2e5944d | 2025-02-04 17:02:32 | [diff] [blame] | 14 | |
| 15 | Extra args after -- are passed directly to fetch_all.py. |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 16 | """ |
| 17 | |
Haiyang Pan | ace50093 | 2022-01-26 19:49:03 | [diff] [blame] | 18 | import argparse |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 19 | import contextlib |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 20 | import json |
Haiyang Pan | ace50093 | 2022-01-26 19:49:03 | [diff] [blame] | 21 | import logging |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 22 | import os |
Andrew Grieve | b5255af | 2024-06-06 17:03:18 | [diff] [blame] | 23 | import pathlib |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 24 | import re |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 25 | import shutil |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 26 | import sys |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 27 | import subprocess |
| 28 | import tempfile |
Peter Kotwicz | 4676d06 | 2020-10-22 06:04:13 | [diff] [blame] | 29 | from urllib import request |
Peter Wen | c90bbb7 | 2025-02-25 20:41:44 | [diff] [blame] | 30 | import zipfile |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 31 | |
| 32 | _ANDROIDX_PATH = os.path.normpath(os.path.join(__file__, '..')) |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 33 | _CIPD_PATH = os.path.join(_ANDROIDX_PATH, 'cipd') |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 34 | _SRC_PATH = os.path.normpath(os.path.join(_ANDROIDX_PATH, '..', '..')) |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 35 | _BOM_PATH = os.path.join(_CIPD_PATH, 'bill_of_materials.json') |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 36 | |
| 37 | sys.path.insert(1, os.path.join(_SRC_PATH, 'third_party', 'depot_tools')) |
| 38 | import gclient_eval |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 39 | |
| 40 | _FETCH_ALL_PATH = os.path.normpath( |
| 41 | os.path.join(_ANDROIDX_PATH, '..', 'android_deps', 'fetch_all.py')) |
| 42 | |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 43 | # URL to artifacts in latest androidx snapshot. |
| 44 | _ANDROIDX_LATEST_SNAPSHOT_ARTIFACTS_URL = 'https://androidx.dev/snapshots/latest/artifacts' |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 45 | |
| 46 | # Path to package listed in //DEPS |
| 47 | _DEPS_PACKAGE = 'src/third_party/androidx/cipd' |
| 48 | # CIPD package name |
| 49 | _CIPD_PACKAGE = 'chromium/third_party/androidx' |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 50 | |
Peter Kotwicz | 3fb0070e | 2021-02-11 07:37:35 | [diff] [blame] | 51 | # Snapshot repository URL with {{version}} placeholder. |
| 52 | _SNAPSHOT_REPOSITORY_URL = 'https://androidx.dev/snapshots/builds/{{version}}/artifacts/repository' |
| 53 | |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 54 | # When androidx roller is breaking, and a fix is not imminent, use this to pin a |
Andrew Grieve | 2515bcbd | 2022-05-06 03:14:07 | [diff] [blame] | 55 | # broken library to an old known-working version. |
Andrew Grieve | a03217f | 2022-05-12 16:05:27 | [diff] [blame] | 56 | # * The first element of each tuple is the path to the artifact of the latest |
| 57 | # version of the library. It could change if the version is rev'ed in a new |
| 58 | # snapshot. |
| 59 | # * The second element is a URL to replace the file with. Find the URL for older |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 60 | # versions of libraries by looking through the artifacts for the older version |
| 61 | # (e.g.: https://androidx.dev/snapshots/builds/8545498/artifacts) |
Andrew Grieve | 2515bcbd | 2022-05-06 03:14:07 | [diff] [blame] | 62 | _OVERRIDES = [ |
Andrew Grieve | a03217f | 2022-05-12 16:05:27 | [diff] [blame] | 63 | # Example: |
Andrew Grieve | 2515bcbd | 2022-05-06 03:14:07 | [diff] [blame] | 64 | #('androidx_core_core/core-1.9.0-SNAPSHOT.aar', |
| 65 | # 'https://androidx.dev/snapshots/builds/8545498/artifacts/repository/' |
| 66 | # 'androidx/core/core/1.8.0-SNAPSHOT/core-1.8.0-20220505.122105-1.aar'), |
| 67 | ] |
| 68 | |
Peter Wen | ba01695b | 2025-03-03 18:29:46 | [diff] [blame] | 69 | _FILES_TO_COMMIT = [ |
| 70 | 'additional_readme_paths.json', |
| 71 | 'bill_of_materials.json', |
| 72 | 'BUILD.gn', |
| 73 | 'build.gradle', |
| 74 | ] |
| 75 | _CIPD_DATA_FILES = _FILES_TO_COMMIT + [ |
| 76 | 'VERSION.txt', |
| 77 | 'to_commit.zip', |
| 78 | ] |
| 79 | |
Peter Wen | 19a6870 | 2025-03-03 20:41:31 | [diff] [blame^] | 80 | _GENERATED_DISCLAIMER = '''\ |
| 81 | // **IMPORTANT**: build.gradle is generated and any changes would be overridden |
| 82 | // by the autoroller. Please update build.gradle.template |
| 83 | // instead. |
| 84 | ''' |
| 85 | |
Peter Kotwicz | 3fb0070e | 2021-02-11 07:37:35 | [diff] [blame] | 86 | |
| 87 | def _build_snapshot_repository_url(version): |
| 88 | return _SNAPSHOT_REPOSITORY_URL.replace('{{version}}', version) |
| 89 | |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 90 | |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 91 | def _get_latest_androidx_version(): |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 92 | androidx_artifacts_response = request.urlopen( |
| 93 | _ANDROIDX_LATEST_SNAPSHOT_ARTIFACTS_URL) |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 94 | # Get the versioned url from the redirect destination. |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 95 | androidx_artifacts_url = androidx_artifacts_response.url |
| 96 | androidx_artifacts_response.close() |
| 97 | logging.info('URL for the latest build info: %s', androidx_artifacts_url) |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 98 | # Strip '/repository' from pattern. |
| 99 | resolved_snapshot_repository_url_pattern = ( |
| 100 | _build_snapshot_repository_url('([0-9]*)').rsplit('/', 1)[0]) |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 101 | match = re.match(resolved_snapshot_repository_url_pattern, |
| 102 | androidx_artifacts_url) |
| 103 | assert match is not None |
| 104 | version = match.group(1) |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 105 | return version |
| 106 | |
| 107 | |
| 108 | def _query_cipd_tags(version): |
| 109 | cipd_output = subprocess.check_output( |
| 110 | ['cipd', 'describe', _CIPD_PACKAGE, '-version', version], |
| 111 | encoding='utf-8') |
| 112 | # Output looks like: |
| 113 | # Package: chromium/third_party/androidx |
| 114 | # Instance ID: gUjEawxv5mQO8yfbuC8W-rx4V3zYE-4LTWggXpZHI4sC |
| 115 | # Registered by: user:chromium-cipd-builder@chops-service-accounts.iam.gserviceaccount.com |
| 116 | # Registered at: 2025-01-06 17:54:48.034135 +0000 UTC |
| 117 | # Refs: |
| 118 | # latest |
| 119 | # Tags: |
| 120 | # details0:version-cr-012873390 |
| 121 | # version:cr-012873390 |
| 122 | lines = cipd_output.split('\n') |
| 123 | tags = {} |
| 124 | parsing_tags = False |
| 125 | for line in lines: |
| 126 | if not line.strip(): |
| 127 | continue |
| 128 | if line.startswith('Tags:'): |
| 129 | parsing_tags = True |
| 130 | continue |
| 131 | if parsing_tags: |
| 132 | tag, value = line.strip().split(':', 1) |
| 133 | tags[tag] = value |
| 134 | return tags |
| 135 | |
| 136 | |
| 137 | def _get_current_cipd_instance(): |
| 138 | with open(os.path.join(_SRC_PATH, 'DEPS'), 'rt') as f: |
| 139 | gclient_dict = gclient_eval.Exec(f.read()) |
| 140 | return gclient_eval.GetCIPD(gclient_dict, _DEPS_PACKAGE, _CIPD_PACKAGE) |
| 141 | |
| 142 | |
| 143 | def _get_current_androidx_version(): |
| 144 | cipd_instance = _get_current_cipd_instance() |
| 145 | cipd_tags = _query_cipd_tags(cipd_instance) |
| 146 | version_string = cipd_tags['version'] |
| 147 | version = version_string[len('cr-0'):] |
| 148 | return version |
| 149 | |
| 150 | |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 151 | def _generate_version_map_str(bom_path): |
| 152 | bom = [] |
| 153 | version_lines = [] |
| 154 | with open(bom_path) as f: |
| 155 | bom = json.load(f) |
| 156 | for dep in bom: |
Mohamed Heikal | be6cc50 | 2025-02-26 16:50:00 | [diff] [blame] | 157 | line = f"versionCache['{dep['group']}:{dep['name']}'] = '{dep['version']}'" |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 158 | version_lines.append(line) |
| 159 | return '\n'.join(sorted(version_lines)) |
| 160 | |
| 161 | |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame] | 162 | def _process_build_gradle(template_path, output_path, androidx_repository_url, |
| 163 | version_overrides_str): |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 164 | """Generates build.gradle from template. |
| 165 | |
| 166 | Args: |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 167 | template_path: Path to build.gradle.template. |
| 168 | output_path: Path to build.gradle. |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 169 | androidx_repository_url: URL of the maven repository. |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame] | 170 | version_override_str: An optional list of pinned versions. |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 171 | """ |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 172 | content = pathlib.Path(template_path).read_text() |
| 173 | content = content.replace('{{androidx_repository_url}}', |
| 174 | androidx_repository_url) |
| 175 | content = content.replace('{{version_overrides}}', version_overrides_str) |
Peter Wen | 19a6870 | 2025-03-03 20:41:31 | [diff] [blame^] | 176 | content = content.replace('{{generated_disclaimer}}', |
| 177 | _GENERATED_DISCLAIMER) |
Andrew Grieve | b5255af | 2024-06-06 17:03:18 | [diff] [blame] | 178 | # build.gradle is not deleted after script has finished running. The file is in |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 179 | # .gitignore and thus will be excluded from uploaded CLs. |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 180 | pathlib.Path(output_path).write_text(content) |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 181 | |
| 182 | |
Peter Wen | 801b2fe | 2025-02-25 23:02:46 | [diff] [blame] | 183 | def _write_cipd_yaml(libs_dir, |
| 184 | version, |
| 185 | cipd_yaml_path, |
Peter Wen | 801b2fe | 2025-02-25 23:02:46 | [diff] [blame] | 186 | experimental=False): |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 187 | """Writes cipd.yaml file at the passed-in path.""" |
| 188 | |
| 189 | lib_dirs = os.listdir(libs_dir) |
| 190 | if not lib_dirs: |
| 191 | raise Exception('No generated libraries in {}'.format(libs_dir)) |
| 192 | |
Peter Wen | ba01695b | 2025-03-03 18:29:46 | [diff] [blame] | 193 | cipd_lib_files = [] |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 194 | for lib_dir in lib_dirs: |
| 195 | abs_lib_dir = os.path.join(libs_dir, lib_dir) |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 196 | androidx_rel_lib_dir = os.path.relpath(abs_lib_dir, _CIPD_PATH) |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 197 | if not os.path.isdir(abs_lib_dir): |
| 198 | continue |
| 199 | lib_files = os.listdir(abs_lib_dir) |
| 200 | if not 'cipd.yaml' in lib_files: |
| 201 | continue |
| 202 | |
Peter Kotwicz | a6b3b9a | 2021-01-28 21:40:12 | [diff] [blame] | 203 | for lib_file in lib_files: |
Peter Wen | 3477b8b | 2025-02-27 17:40:22 | [diff] [blame] | 204 | if lib_file == 'cipd.yaml': |
Peter Kotwicz | a6b3b9a | 2021-01-28 21:40:12 | [diff] [blame] | 205 | continue |
Peter Wen | ba01695b | 2025-03-03 18:29:46 | [diff] [blame] | 206 | cipd_lib_files.append(os.path.join(androidx_rel_lib_dir, lib_file)) |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 207 | |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 208 | if experimental: |
| 209 | package = 'experimental/google.com/' + os.getlogin() + '/androidx' |
| 210 | else: |
| 211 | package = 'chromium/third_party/androidx' |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 212 | contents = [ |
mark a. foltz | f87dfea | 2023-09-06 23:49:03 | [diff] [blame] | 213 | '# Copyright 2021 The Chromium Authors', |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 214 | '# Use of this source code is governed by a BSD-style license that can be', |
| 215 | '# found in the LICENSE file.', |
Peter Kotwicz | 92548aa | 2021-02-18 15:12:58 | [diff] [blame] | 216 | '# version: ' + version, |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 217 | 'package: ' + package, |
Peter Kotwicz | 3fb0070e | 2021-02-11 07:37:35 | [diff] [blame] | 218 | 'description: androidx', |
| 219 | 'data:', |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 220 | ] |
Peter Wen | ba01695b | 2025-03-03 18:29:46 | [diff] [blame] | 221 | contents.extend('- file: ' + f for f in cipd_lib_files + _CIPD_DATA_FILES) |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 222 | |
| 223 | with open(cipd_yaml_path, 'w') as out: |
| 224 | out.write('\n'.join(contents)) |
| 225 | |
| 226 | |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 227 | def main(): |
Haiyang Pan | ace50093 | 2022-01-26 19:49:03 | [diff] [blame] | 228 | parser = argparse.ArgumentParser(description=__doc__) |
| 229 | parser.add_argument('-v', |
| 230 | '--verbose', |
| 231 | dest='verbose_count', |
| 232 | default=0, |
| 233 | action='count', |
| 234 | help='Verbose level (multiple times for more)') |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 235 | parser.add_argument('--local-repo', |
| 236 | help='Path to a locally androidx maven repo to use ' |
| 237 | 'instead of fetching the latest.') |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 238 | parser.add_argument( |
| 239 | '--no-roll', |
| 240 | action='store_true', |
| 241 | help='If passed then we will not try rolling the ' |
| 242 | 'latest androidx but use the currently rolled version.') |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame] | 243 | parser.add_argument( |
| 244 | '--use-bom', |
| 245 | action='store_true', |
| 246 | help='If passed then we will use the existing bill_of_materials.json ' |
| 247 | 'instead of resolving the latest androidx.') |
Peter Wen | 2e5944d | 2025-02-04 17:02:32 | [diff] [blame] | 248 | args, extra_args = parser.parse_known_args() |
Haiyang Pan | ace50093 | 2022-01-26 19:49:03 | [diff] [blame] | 249 | |
| 250 | logging.basicConfig( |
| 251 | level=logging.WARNING - 10 * args.verbose_count, |
| 252 | format='%(levelname).1s %(relativeCreated)6d %(message)s') |
| 253 | |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 254 | if args.local_repo: |
| 255 | version = 'local' |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 256 | androidx_snapshot_repository_url = ('file://' + |
| 257 | os.path.abspath(args.local_repo)) |
| 258 | else: |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 259 | if args.no_roll: |
| 260 | version = _get_current_androidx_version() |
| 261 | logging.info('Resolved current androidx version to %s', version) |
| 262 | else: |
| 263 | version = _get_latest_androidx_version() |
| 264 | logging.info('Resolved latest androidx version to %s', version) |
| 265 | |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 266 | androidx_snapshot_repository_url = _build_snapshot_repository_url( |
| 267 | version) |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 268 | # Prepend '0' to version to avoid conflicts with previous version format. |
| 269 | version = 'cr-0' + version |
| 270 | |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame] | 271 | if args.use_bom: |
| 272 | version_map_str = _generate_version_map_str(_BOM_PATH) |
| 273 | else: |
| 274 | version_map_str = '' |
| 275 | |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 276 | if os.path.exists(_CIPD_PATH): |
| 277 | shutil.rmtree(_CIPD_PATH) |
| 278 | os.mkdir(_CIPD_PATH) |
| 279 | |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 280 | _process_build_gradle( |
| 281 | os.path.join(_ANDROIDX_PATH, 'build.gradle.template'), |
Peter Wen | 6fcf2d7 | 2025-02-12 15:34:26 | [diff] [blame] | 282 | os.path.join(_CIPD_PATH, 'build.gradle'), |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame] | 283 | androidx_snapshot_repository_url, version_map_str) |
Peter Wen | ba01695b | 2025-03-03 18:29:46 | [diff] [blame] | 284 | shutil.copyfile(os.path.join(_ANDROIDX_PATH, 'BUILD.gn'), |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 285 | os.path.join(_CIPD_PATH, 'BUILD.gn')) |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 286 | |
| 287 | fetch_all_cmd = [ |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 288 | _FETCH_ALL_PATH, '--android-deps-dir', _CIPD_PATH, |
Peter Kotwicz | dabb89d07 | 2020-10-22 16:30:03 | [diff] [blame] | 289 | '--ignore-vulnerabilities' |
Andrew Grieve | e9bccea4 | 2023-02-10 19:56:25 | [diff] [blame] | 290 | ] + ['-v'] * args.verbose_count |
Peter Wen | 2e5944d | 2025-02-04 17:02:32 | [diff] [blame] | 291 | |
| 292 | # Filter out -- from the args to pass to fetch_all.py. |
| 293 | fetch_all_cmd += [a for a in extra_args if a != '--'] |
| 294 | |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 295 | # Overrides do not work with local snapshots since the repository_url is |
| 296 | # different. |
| 297 | if not args.local_repo: |
| 298 | for subpath, url in _OVERRIDES: |
| 299 | fetch_all_cmd += ['--override-artifact', f'{subpath}:{url}'] |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 300 | env = os.environ.copy() |
| 301 | # Silence the --local warning in fetch_all.py that is not applicable here. |
| 302 | env['SWARMING_TASK_ID'] = '1' |
| 303 | subprocess.run(fetch_all_cmd, check=True, env=env) |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 304 | |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 305 | version_map_str = _generate_version_map_str(_BOM_PATH) |
| 306 | |
| 307 | # Regenerate the build.gradle file filling in the the version map so that |
| 308 | # runs of the main project do not have to revalutate androidx versions. |
| 309 | _process_build_gradle( |
| 310 | os.path.join(_ANDROIDX_PATH, 'build.gradle.template'), |
| 311 | os.path.join(_CIPD_PATH, 'build.gradle'), |
| 312 | androidx_snapshot_repository_url, version_map_str) |
| 313 | |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 314 | version_txt_path = os.path.join(_CIPD_PATH, 'VERSION.txt') |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 315 | with open(version_txt_path, 'w') as f: |
| 316 | f.write(version) |
Peter Kotwicz | 92548aa | 2021-02-18 15:12:58 | [diff] [blame] | 317 | |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 318 | libs_dir = os.path.join(_CIPD_PATH, 'libs') |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 319 | |
Peter Wen | c90bbb7 | 2025-02-25 20:41:44 | [diff] [blame] | 320 | to_commit_paths = [] |
| 321 | for root, _, files in os.walk(libs_dir): |
| 322 | for file in files: |
| 323 | # Avoid committing actual artifacts. |
Peter Wen | 3477b8b | 2025-02-27 17:40:22 | [diff] [blame] | 324 | if file.endswith(('.aar', '.jar', 'cipd.yaml')): |
Peter Wen | c90bbb7 | 2025-02-25 20:41:44 | [diff] [blame] | 325 | continue |
| 326 | file_path = os.path.join(root, file) |
| 327 | file_path_in_committed = os.path.relpath(file_path, _CIPD_PATH) |
| 328 | to_commit_paths.append((file_path, file_path_in_committed)) |
| 329 | |
Peter Wen | ba01695b | 2025-03-03 18:29:46 | [diff] [blame] | 330 | for file in _FILES_TO_COMMIT: |
Peter Wen | c90bbb7 | 2025-02-25 20:41:44 | [diff] [blame] | 331 | file_path = os.path.join(_CIPD_PATH, file) |
| 332 | to_commit_paths.append( |
| 333 | (file_path, f'CHROMIUM_SRC/third_party/androidx/{file}')) |
| 334 | |
| 335 | to_commit_zip_path = os.path.join(_CIPD_PATH, 'to_commit.zip') |
| 336 | with zipfile.ZipFile(to_commit_zip_path, 'w') as zip_file: |
| 337 | for filename, arcname in to_commit_paths: |
| 338 | zip_file.write(filename, arcname=arcname) |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 339 | |
Peter Wen | 801b2fe | 2025-02-25 23:02:46 | [diff] [blame] | 340 | yaml_path = os.path.join(_CIPD_PATH, 'cipd.yaml') |
| 341 | _write_cipd_yaml(libs_dir, |
| 342 | version, |
| 343 | yaml_path, |
Peter Wen | 801b2fe | 2025-02-25 23:02:46 | [diff] [blame] | 344 | experimental=bool(args.local_repo)) |
| 345 | |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 346 | if __name__ == '__main__': |
| 347 | main() |