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 Kotwicz | 3fb0070e | 2021-02-11 07:37:35 | [diff] [blame] | 69 | |
| 70 | def _build_snapshot_repository_url(version): |
| 71 | return _SNAPSHOT_REPOSITORY_URL.replace('{{version}}', version) |
| 72 | |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 73 | |
| 74 | def _parse_dir_list(dir_list): |
| 75 | """Computes 'library_group:library_name'->library_version mapping. |
| 76 | |
| 77 | Args: |
| 78 | dir_list: List of androidx library directories. |
| 79 | """ |
| 80 | dependency_version_map = dict() |
| 81 | for dir_entry in dir_list: |
| 82 | stripped_dir = dir_entry.strip() |
| 83 | if not stripped_dir.startswith('repository/androidx/'): |
| 84 | continue |
| 85 | dir_components = stripped_dir.split('/') |
| 86 | # Expected format: |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 87 | # "repository/androidx/library_group/library_name/library_version" |
| 88 | if len(dir_components) < 5: |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 89 | continue |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 90 | dependency_package = 'androidx.' + '.'.join(dir_components[2:-2]) |
Peter Kotwicz | 4d3c3970 | 2021-03-25 21:48:25 | [diff] [blame] | 91 | dependency_module = '{}:{}'.format(dependency_package, |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 92 | dir_components[-2]) |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 93 | if dependency_module not in dependency_version_map: |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 94 | dependency_version_map[dependency_module] = dir_components[-1] |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 95 | return dependency_version_map |
| 96 | |
| 97 | |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 98 | @contextlib.contextmanager |
| 99 | def _build_dir(): |
| 100 | dirname = tempfile.mkdtemp() |
| 101 | try: |
| 102 | yield dirname |
| 103 | finally: |
| 104 | shutil.rmtree(dirname) |
| 105 | |
| 106 | |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 107 | def _get_latest_androidx_version(): |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 108 | androidx_artifacts_response = request.urlopen( |
| 109 | _ANDROIDX_LATEST_SNAPSHOT_ARTIFACTS_URL) |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 110 | # Get the versioned url from the redirect destination. |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 111 | androidx_artifacts_url = androidx_artifacts_response.url |
| 112 | androidx_artifacts_response.close() |
| 113 | logging.info('URL for the latest build info: %s', androidx_artifacts_url) |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 114 | # Strip '/repository' from pattern. |
| 115 | resolved_snapshot_repository_url_pattern = ( |
| 116 | _build_snapshot_repository_url('([0-9]*)').rsplit('/', 1)[0]) |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 117 | match = re.match(resolved_snapshot_repository_url_pattern, |
| 118 | androidx_artifacts_url) |
| 119 | assert match is not None |
| 120 | version = match.group(1) |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 121 | return version |
| 122 | |
| 123 | |
| 124 | def _query_cipd_tags(version): |
| 125 | cipd_output = subprocess.check_output( |
| 126 | ['cipd', 'describe', _CIPD_PACKAGE, '-version', version], |
| 127 | encoding='utf-8') |
| 128 | # Output looks like: |
| 129 | # Package: chromium/third_party/androidx |
| 130 | # Instance ID: gUjEawxv5mQO8yfbuC8W-rx4V3zYE-4LTWggXpZHI4sC |
| 131 | # Registered by: user:chromium-cipd-builder@chops-service-accounts.iam.gserviceaccount.com |
| 132 | # Registered at: 2025-01-06 17:54:48.034135 +0000 UTC |
| 133 | # Refs: |
| 134 | # latest |
| 135 | # Tags: |
| 136 | # details0:version-cr-012873390 |
| 137 | # version:cr-012873390 |
| 138 | lines = cipd_output.split('\n') |
| 139 | tags = {} |
| 140 | parsing_tags = False |
| 141 | for line in lines: |
| 142 | if not line.strip(): |
| 143 | continue |
| 144 | if line.startswith('Tags:'): |
| 145 | parsing_tags = True |
| 146 | continue |
| 147 | if parsing_tags: |
| 148 | tag, value = line.strip().split(':', 1) |
| 149 | tags[tag] = value |
| 150 | return tags |
| 151 | |
| 152 | |
| 153 | def _get_current_cipd_instance(): |
| 154 | with open(os.path.join(_SRC_PATH, 'DEPS'), 'rt') as f: |
| 155 | gclient_dict = gclient_eval.Exec(f.read()) |
| 156 | return gclient_eval.GetCIPD(gclient_dict, _DEPS_PACKAGE, _CIPD_PACKAGE) |
| 157 | |
| 158 | |
| 159 | def _get_current_androidx_version(): |
| 160 | cipd_instance = _get_current_cipd_instance() |
| 161 | cipd_tags = _query_cipd_tags(cipd_instance) |
| 162 | version_string = cipd_tags['version'] |
| 163 | version = version_string[len('cr-0'):] |
| 164 | return version |
| 165 | |
| 166 | |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 167 | def _create_local_dir_list(repo_path): |
| 168 | repo_path = repo_path.rstrip('/') |
| 169 | prefix_len = len(repo_path) + 1 |
| 170 | ret = [] |
Peter Wen | 1a004a0 | 2025-01-28 23:04:46 | [diff] [blame] | 171 | for dirpath, _, _ in os.walk(repo_path): |
| 172 | ret.append(os.path.join('repository', dirpath[prefix_len:])) |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 173 | return ret |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 174 | |
| 175 | |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 176 | def _generate_version_map_str(bom_path): |
| 177 | bom = [] |
| 178 | version_lines = [] |
| 179 | with open(bom_path) as f: |
| 180 | bom = json.load(f) |
| 181 | for dep in bom: |
| 182 | line = f" versionCache['{dep['group']}:{dep['name']}'] = '{dep['version']}'" |
| 183 | version_lines.append(line) |
| 184 | return '\n'.join(sorted(version_lines)) |
| 185 | |
| 186 | |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame^] | 187 | def _process_build_gradle(template_path, output_path, androidx_repository_url, |
| 188 | version_overrides_str): |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 189 | """Generates build.gradle from template. |
| 190 | |
| 191 | Args: |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 192 | template_path: Path to build.gradle.template. |
| 193 | output_path: Path to build.gradle. |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 194 | androidx_repository_url: URL of the maven repository. |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame^] | 195 | version_override_str: An optional list of pinned versions. |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 196 | """ |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 197 | content = pathlib.Path(template_path).read_text() |
| 198 | content = content.replace('{{androidx_repository_url}}', |
| 199 | androidx_repository_url) |
| 200 | content = content.replace('{{version_overrides}}', version_overrides_str) |
Andrew Grieve | b5255af | 2024-06-06 17:03:18 | [diff] [blame] | 201 | # 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] | 202 | # .gitignore and thus will be excluded from uploaded CLs. |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 203 | pathlib.Path(output_path).write_text(content) |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 204 | |
| 205 | |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 206 | def _write_cipd_yaml(libs_dir, version, cipd_yaml_path, experimental=False): |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 207 | """Writes cipd.yaml file at the passed-in path.""" |
| 208 | |
| 209 | lib_dirs = os.listdir(libs_dir) |
| 210 | if not lib_dirs: |
| 211 | raise Exception('No generated libraries in {}'.format(libs_dir)) |
| 212 | |
Peter Kotwicz | 1ea22e1 | 2021-02-22 19:01:59 | [diff] [blame] | 213 | data_files = [ |
| 214 | 'BUILD.gn', 'VERSION.txt', 'additional_readme_paths.json', |
| 215 | 'build.gradle' |
| 216 | ] |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 217 | for lib_dir in lib_dirs: |
| 218 | abs_lib_dir = os.path.join(libs_dir, lib_dir) |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 219 | androidx_rel_lib_dir = os.path.relpath(abs_lib_dir, _CIPD_PATH) |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 220 | if not os.path.isdir(abs_lib_dir): |
| 221 | continue |
| 222 | lib_files = os.listdir(abs_lib_dir) |
| 223 | if not 'cipd.yaml' in lib_files: |
| 224 | continue |
| 225 | |
Peter Kotwicz | a6b3b9a | 2021-01-28 21:40:12 | [diff] [blame] | 226 | for lib_file in lib_files: |
| 227 | if lib_file == 'cipd.yaml' or lib_file == 'OWNERS': |
| 228 | continue |
| 229 | data_files.append(os.path.join(androidx_rel_lib_dir, lib_file)) |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 230 | |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 231 | if experimental: |
| 232 | package = 'experimental/google.com/' + os.getlogin() + '/androidx' |
| 233 | else: |
| 234 | package = 'chromium/third_party/androidx' |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 235 | contents = [ |
mark a. foltz | f87dfea | 2023-09-06 23:49:03 | [diff] [blame] | 236 | '# Copyright 2021 The Chromium Authors', |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 237 | '# Use of this source code is governed by a BSD-style license that can be', |
| 238 | '# found in the LICENSE file.', |
Peter Kotwicz | 92548aa | 2021-02-18 15:12:58 | [diff] [blame] | 239 | '# version: ' + version, |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 240 | 'package: ' + package, |
Peter Kotwicz | 3fb0070e | 2021-02-11 07:37:35 | [diff] [blame] | 241 | 'description: androidx', |
| 242 | 'data:', |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 243 | ] |
| 244 | contents.extend('- file: ' + f for f in data_files) |
| 245 | |
| 246 | with open(cipd_yaml_path, 'w') as out: |
| 247 | out.write('\n'.join(contents)) |
| 248 | |
| 249 | |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 250 | def main(): |
Haiyang Pan | ace50093 | 2022-01-26 19:49:03 | [diff] [blame] | 251 | parser = argparse.ArgumentParser(description=__doc__) |
| 252 | parser.add_argument('-v', |
| 253 | '--verbose', |
| 254 | dest='verbose_count', |
| 255 | default=0, |
| 256 | action='count', |
| 257 | help='Verbose level (multiple times for more)') |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 258 | parser.add_argument('--local-repo', |
| 259 | help='Path to a locally androidx maven repo to use ' |
| 260 | 'instead of fetching the latest.') |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 261 | parser.add_argument( |
| 262 | '--no-roll', |
| 263 | action='store_true', |
| 264 | help='If passed then we will not try rolling the ' |
| 265 | 'latest androidx but use the currently rolled version.') |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame^] | 266 | parser.add_argument( |
| 267 | '--use-bom', |
| 268 | action='store_true', |
| 269 | help='If passed then we will use the existing bill_of_materials.json ' |
| 270 | 'instead of resolving the latest androidx.') |
Peter Wen | 2e5944d | 2025-02-04 17:02:32 | [diff] [blame] | 271 | args, extra_args = parser.parse_known_args() |
Haiyang Pan | ace50093 | 2022-01-26 19:49:03 | [diff] [blame] | 272 | |
| 273 | logging.basicConfig( |
| 274 | level=logging.WARNING - 10 * args.verbose_count, |
| 275 | format='%(levelname).1s %(relativeCreated)6d %(message)s') |
| 276 | |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 277 | if args.local_repo: |
| 278 | version = 'local' |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 279 | androidx_snapshot_repository_url = ('file://' + |
| 280 | os.path.abspath(args.local_repo)) |
| 281 | else: |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 282 | if args.no_roll: |
| 283 | version = _get_current_androidx_version() |
| 284 | logging.info('Resolved current androidx version to %s', version) |
| 285 | else: |
| 286 | version = _get_latest_androidx_version() |
| 287 | logging.info('Resolved latest androidx version to %s', version) |
| 288 | |
Andrew Grieve | 10bbd55 | 2022-05-05 18:10:26 | [diff] [blame] | 289 | androidx_snapshot_repository_url = _build_snapshot_repository_url( |
| 290 | version) |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 291 | # Prepend '0' to version to avoid conflicts with previous version format. |
| 292 | version = 'cr-0' + version |
| 293 | |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame^] | 294 | if args.use_bom: |
| 295 | version_map_str = _generate_version_map_str(_BOM_PATH) |
| 296 | else: |
| 297 | version_map_str = '' |
| 298 | |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 299 | if os.path.exists(_CIPD_PATH): |
| 300 | shutil.rmtree(_CIPD_PATH) |
| 301 | os.mkdir(_CIPD_PATH) |
| 302 | |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 303 | _process_build_gradle( |
| 304 | os.path.join(_ANDROIDX_PATH, 'build.gradle.template'), |
Peter Wen | 6fcf2d7 | 2025-02-12 15:34:26 | [diff] [blame] | 305 | os.path.join(_CIPD_PATH, 'build.gradle'), |
Peter Wen | 1ba3d4d | 2025-02-25 21:46:37 | [diff] [blame^] | 306 | androidx_snapshot_repository_url, version_map_str) |
Andrew Grieve | 15c476e | 2023-02-10 19:57:31 | [diff] [blame] | 307 | shutil.copyfile(os.path.join(_ANDROIDX_PATH, 'BUILD.gn.template'), |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 308 | os.path.join(_CIPD_PATH, 'BUILD.gn')) |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 309 | |
| 310 | fetch_all_cmd = [ |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 311 | _FETCH_ALL_PATH, '--android-deps-dir', _CIPD_PATH, |
Peter Kotwicz | dabb89d07 | 2020-10-22 16:30:03 | [diff] [blame] | 312 | '--ignore-vulnerabilities' |
Andrew Grieve | e9bccea4 | 2023-02-10 19:56:25 | [diff] [blame] | 313 | ] + ['-v'] * args.verbose_count |
Peter Wen | 2e5944d | 2025-02-04 17:02:32 | [diff] [blame] | 314 | |
| 315 | # Filter out -- from the args to pass to fetch_all.py. |
| 316 | fetch_all_cmd += [a for a in extra_args if a != '--'] |
| 317 | |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 318 | # Overrides do not work with local snapshots since the repository_url is |
| 319 | # different. |
| 320 | if not args.local_repo: |
| 321 | for subpath, url in _OVERRIDES: |
| 322 | fetch_all_cmd += ['--override-artifact', f'{subpath}:{url}'] |
Mohamed Heikal | 864fa34 | 2025-01-08 19:15:45 | [diff] [blame] | 323 | env = os.environ.copy() |
| 324 | # Silence the --local warning in fetch_all.py that is not applicable here. |
| 325 | env['SWARMING_TASK_ID'] = '1' |
| 326 | subprocess.run(fetch_all_cmd, check=True, env=env) |
Peter Kotwicz | a31339a | 2020-10-20 16:36:23 | [diff] [blame] | 327 | |
Mohamed Heikal | 811bb64 | 2025-02-25 20:03:53 | [diff] [blame] | 328 | version_map_str = _generate_version_map_str(_BOM_PATH) |
| 329 | |
| 330 | # Regenerate the build.gradle file filling in the the version map so that |
| 331 | # runs of the main project do not have to revalutate androidx versions. |
| 332 | _process_build_gradle( |
| 333 | os.path.join(_ANDROIDX_PATH, 'build.gradle.template'), |
| 334 | os.path.join(_CIPD_PATH, 'build.gradle'), |
| 335 | androidx_snapshot_repository_url, version_map_str) |
| 336 | |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 337 | version_txt_path = os.path.join(_CIPD_PATH, 'VERSION.txt') |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 338 | with open(version_txt_path, 'w') as f: |
| 339 | f.write(version) |
Peter Kotwicz | 92548aa | 2021-02-18 15:12:58 | [diff] [blame] | 340 | |
Andrew Grieve | d8c9718 | 2024-06-28 18:37:33 | [diff] [blame] | 341 | libs_dir = os.path.join(_CIPD_PATH, 'libs') |
| 342 | yaml_path = os.path.join(_CIPD_PATH, 'cipd.yaml') |
| 343 | _write_cipd_yaml(libs_dir, |
| 344 | version, |
| 345 | yaml_path, |
Andrew Grieve | 9c7d4ac2f | 2022-08-24 17:38:59 | [diff] [blame] | 346 | experimental=bool(args.local_repo)) |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 347 | |
Peter Wen | c90bbb7 | 2025-02-25 20:41:44 | [diff] [blame] | 348 | to_commit_paths = [] |
| 349 | for root, _, files in os.walk(libs_dir): |
| 350 | for file in files: |
| 351 | # Avoid committing actual artifacts. |
| 352 | if file.endswith(('.aar', '.jar')): |
| 353 | continue |
| 354 | file_path = os.path.join(root, file) |
| 355 | file_path_in_committed = os.path.relpath(file_path, _CIPD_PATH) |
| 356 | to_commit_paths.append((file_path, file_path_in_committed)) |
| 357 | |
| 358 | files_in_tree = [ |
| 359 | 'additional_readme_paths.json', 'BUILD.gn', 'build.gradle' |
| 360 | ] |
| 361 | for file in files_in_tree: |
| 362 | file_path = os.path.join(_CIPD_PATH, file) |
| 363 | to_commit_paths.append( |
| 364 | (file_path, f'CHROMIUM_SRC/third_party/androidx/{file}')) |
| 365 | |
| 366 | to_commit_zip_path = os.path.join(_CIPD_PATH, 'to_commit.zip') |
| 367 | with zipfile.ZipFile(to_commit_zip_path, 'w') as zip_file: |
| 368 | for filename, arcname in to_commit_paths: |
| 369 | zip_file.write(filename, arcname=arcname) |
Peter Kotwicz | 2b85bd3d | 2020-10-01 22:29:49 | [diff] [blame] | 370 | |
| 371 | if __name__ == '__main__': |
| 372 | main() |