Mike Frysinger | e58c0e2 | 2017-10-04 15:43:30 -0400 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 2 | # Copyright 2016 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """This module uprevs Android for cbuildbot. |
| 7 | |
| 8 | After calling, it prints outs ANDROID_VERSION_ATOM=(version atom string). A |
| 9 | caller could then use this atom with emerge to build the newly uprevved version |
| 10 | of Android e.g. |
| 11 | |
Shuhei Takahashi | 6d02c19 | 2017-04-05 14:01:24 +0900 | [diff] [blame] | 12 | ./cros_mark_android_as_stable \ |
Shao-Chuan Lee | 9c39e0c | 2020-04-24 11:40:34 +0900 | [diff] [blame] | 13 | --android_build_branch=git_pi-arc \ |
| 14 | --android_package=android-container-pi |
Shuhei Takahashi | 6d02c19 | 2017-04-05 14:01:24 +0900 | [diff] [blame] | 15 | |
Shao-Chuan Lee | 9c39e0c | 2020-04-24 11:40:34 +0900 | [diff] [blame] | 16 | Returns chromeos-base/android-container-pi-6417892-r1 |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 17 | |
Shao-Chuan Lee | 9c39e0c | 2020-04-24 11:40:34 +0900 | [diff] [blame] | 18 | emerge-eve =chromeos-base/android-container-pi-6417892-r1 |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 19 | """ |
| 20 | |
| 21 | from __future__ import print_function |
| 22 | |
| 23 | import filecmp |
| 24 | import glob |
Junichi Uekawa | d21f94d | 2020-07-27 15:50:05 +0900 | [diff] [blame] | 25 | import json |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 26 | import os |
Mike Frysinger | 00a0229 | 2020-04-19 06:28:03 -0400 | [diff] [blame] | 27 | import sys |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 28 | |
Aviv Keshet | b7519e1 | 2016-10-04 00:50:00 -0700 | [diff] [blame] | 29 | from chromite.lib import constants |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 30 | from chromite.lib import commandline |
| 31 | from chromite.lib import cros_build_lib |
| 32 | from chromite.lib import cros_logging as logging |
| 33 | from chromite.lib import git |
| 34 | from chromite.lib import gs |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 35 | from chromite.lib import osutils |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 36 | from chromite.lib import portage_util |
Shao-Chuan Lee | 007dbe8 | 2021-02-09 14:05:39 +0900 | [diff] [blame] | 37 | from chromite.lib import repo_util |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 38 | from chromite.scripts import cros_mark_as_stable |
Shao-Chuan Lee | 7fd0ca1 | 2021-03-19 15:57:40 +0900 | [diff] [blame] | 39 | from chromite.service import android |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 40 | |
| 41 | |
Mike Frysinger | 00a0229 | 2020-04-19 06:28:03 -0400 | [diff] [blame] | 42 | assert sys.version_info >= (3, 6), 'This module requires Python 3.6+' |
| 43 | |
| 44 | |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 45 | # Dir where all the action happens. |
| 46 | _OVERLAY_DIR = '%(srcroot)s/private-overlays/project-cheets-private/' |
| 47 | |
Junichi Uekawa | 6d61ab0 | 2020-04-15 14:52:28 +0900 | [diff] [blame] | 48 | _GIT_COMMIT_MESSAGE = """Marking latest for %(android_package)s ebuild with \ |
| 49 | version %(android_version)s as stable. |
| 50 | |
| 51 | BUG=None |
| 52 | TEST=CQ |
| 53 | """ |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 54 | |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 55 | _RUNTIME_ARTIFACTS_BUCKET_URL = 'gs://chromeos-arc-images/runtime_artifacts' |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 56 | |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 57 | |
| 58 | def FindAndroidCandidates(package_dir): |
| 59 | """Return a tuple of Android's unstable ebuild and stable ebuilds. |
| 60 | |
| 61 | Args: |
| 62 | package_dir: The path to where the package ebuild is stored. |
| 63 | |
| 64 | Returns: |
| 65 | Tuple [unstable_ebuild, stable_ebuilds]. |
| 66 | |
| 67 | Raises: |
| 68 | Exception: if no unstable ebuild exists for Android. |
| 69 | """ |
| 70 | stable_ebuilds = [] |
| 71 | unstable_ebuilds = [] |
| 72 | for path in glob.glob(os.path.join(package_dir, '*.ebuild')): |
| 73 | ebuild = portage_util.EBuild(path) |
| 74 | if ebuild.version == '9999': |
| 75 | unstable_ebuilds.append(ebuild) |
| 76 | else: |
| 77 | stable_ebuilds.append(ebuild) |
| 78 | |
| 79 | # Apply some sanity checks. |
| 80 | if not unstable_ebuilds: |
| 81 | raise Exception('Missing 9999 ebuild for %s' % package_dir) |
| 82 | if not stable_ebuilds: |
Lann Martin | ffb9516 | 2018-08-28 12:02:54 -0600 | [diff] [blame] | 83 | logging.warning('Missing stable ebuild for %s', package_dir) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 84 | |
| 85 | return portage_util.BestEBuild(unstable_ebuilds), stable_ebuilds |
| 86 | |
| 87 | |
Shao-Chuan Lee | 085e3d7 | 2020-05-11 16:00:42 +0900 | [diff] [blame] | 88 | def PrintUprevMetadata(build_branch, stable_candidate, new_ebuild): |
| 89 | """Shows metadata on buildbot page at UprevAndroid step. |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 90 | |
| 91 | Args: |
Shao-Chuan Lee | 085e3d7 | 2020-05-11 16:00:42 +0900 | [diff] [blame] | 92 | build_branch: The branch of Android builds. |
| 93 | stable_candidate: The existing stable ebuild. |
| 94 | new_ebuild: The newly written ebuild. |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 95 | """ |
Shao-Chuan Lee | 085e3d7 | 2020-05-11 16:00:42 +0900 | [diff] [blame] | 96 | # Examples: |
| 97 | # "android-container-pi revved 6461825-r1 -> 6468247-r1" |
| 98 | # "android-container-pi revved 6461825-r1 -> 6461825-r2 (ebuild update only)" |
| 99 | msg = '%s revved %s -> %s' % (stable_candidate.pkgname, |
| 100 | stable_candidate.version, |
| 101 | new_ebuild.version) |
| 102 | |
| 103 | old_android = stable_candidate.version_no_rev |
| 104 | new_android = new_ebuild.version_no_rev |
| 105 | |
| 106 | if old_android == new_android: |
| 107 | msg += ' (ebuild update only)' |
| 108 | else: |
| 109 | ab_link = ('https://android-build.googleplex.com' |
| 110 | '/builds/%s/branches/%s/cls?end=%s' |
| 111 | % (new_android, build_branch, old_android)) |
| 112 | logging.PrintBuildbotLink('Android changelog', ab_link) |
| 113 | |
| 114 | logging.PrintBuildbotStepText(msg) |
Junichi Uekawa | d21f94d | 2020-07-27 15:50:05 +0900 | [diff] [blame] | 115 | logging.PrintKitchenSetBuildProperty('android_uprev', json.dumps({ |
| 116 | 'branch': build_branch, |
| 117 | 'new': new_ebuild.version, |
| 118 | 'old': stable_candidate.version, |
| 119 | 'pkgname': stable_candidate.pkgname, |
| 120 | })) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 121 | |
| 122 | |
Yury Khmel | b009aeb | 2020-08-19 19:40:00 -0700 | [diff] [blame] | 123 | def FindDataCollectorArtifacts(gs_context, |
| 124 | android_version, |
| 125 | runtime_artifacts_bucket_url, |
| 126 | version_reference): |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 127 | r"""Finds and includes into variables artifacts from arc.DataCollector. |
| 128 | |
Yury Khmel | b009aeb | 2020-08-19 19:40:00 -0700 | [diff] [blame] | 129 | This is used from UpdateDataCollectorArtifacts in order to check the |
| 130 | particular version. |
| 131 | |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 132 | Args: |
Yury Khmel | b009aeb | 2020-08-19 19:40:00 -0700 | [diff] [blame] | 133 | gs_context: context to execute gsutil |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 134 | android_version: The \d+ build id of Android. |
| 135 | runtime_artifacts_bucket_url: root of runtime artifacts |
Yury Khmel | b009aeb | 2020-08-19 19:40:00 -0700 | [diff] [blame] | 136 | build_branch: build branch. Used to determine the pinned version if exists. |
| 137 | version_reference: which version to use as a reference. Could be '${PV}' in |
| 138 | case version of data collector artifacts matches the |
| 139 | Android version or direct version in case of override. |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 140 | |
| 141 | Returns: |
Yury Khmel | b009aeb | 2020-08-19 19:40:00 -0700 | [diff] [blame] | 142 | dictionary with filled ebuild variables. This dictionary is empty in case |
| 143 | no artificats are found. |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 144 | """ |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 145 | variables = {} |
Yury Khmel | b009aeb | 2020-08-19 19:40:00 -0700 | [diff] [blame] | 146 | |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 147 | buckets = ['ureadahead_pack', 'gms_core_cache'] |
| 148 | archs = ['arm', 'arm64', 'x86', 'x86_64'] |
| 149 | build_types = ['user', 'userdebug'] |
| 150 | |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 151 | for bucket in buckets: |
| 152 | for arch in archs: |
| 153 | for build_type in build_types: |
| 154 | path = (f'{runtime_artifacts_bucket_url}/{bucket}_{arch}_{build_type}_' |
Yury Khmel | e1b7440 | 2020-05-18 08:41:35 -0700 | [diff] [blame] | 155 | f'{android_version}.tar') |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 156 | if gs_context.Exists(path): |
| 157 | variables[(f'{arch}_{build_type}_{bucket}').upper()] = ( |
| 158 | f'{runtime_artifacts_bucket_url}/{bucket}_{arch}_{build_type}_' |
| 159 | f'{version_reference}.tar') |
| 160 | |
| 161 | return variables |
| 162 | |
| 163 | |
Yury Khmel | b009aeb | 2020-08-19 19:40:00 -0700 | [diff] [blame] | 164 | def UpdateDataCollectorArtifacts(android_version, |
| 165 | runtime_artifacts_bucket_url, |
| 166 | build_branch): |
| 167 | r"""Finds and includes into variables artifacts from arc.DataCollector. |
| 168 | |
| 169 | This verifies default android version. In case artificts are not found for |
| 170 | default Android version it tries to find artifacts for pinned version. If |
| 171 | pinned version is provided, it is required artifacts exist for the pinned |
| 172 | version. |
| 173 | |
| 174 | Args: |
| 175 | android_version: The \d+ build id of Android. |
| 176 | runtime_artifacts_bucket_url: root of runtime artifacts |
| 177 | build_branch: build branch. Used to determine the pinned version if exists. |
| 178 | |
| 179 | Returns: |
| 180 | dictionary with filled ebuild variables. |
| 181 | """ |
| 182 | |
| 183 | gs_context = gs.GSContext() |
| 184 | # Check the existing version. If we find any artifacts, use them. |
| 185 | variables = FindDataCollectorArtifacts(gs_context, |
| 186 | android_version, |
| 187 | runtime_artifacts_bucket_url, |
| 188 | '${PV}') |
| 189 | if variables: |
| 190 | # Data artificts were found. |
| 191 | return variables |
| 192 | |
| 193 | # Check pinned version for the current branch. |
| 194 | pin_path = (f'{runtime_artifacts_bucket_url}/{build_branch}_pin_version') |
| 195 | if not gs_context.Exists(pin_path): |
| 196 | # No pinned version. |
| 197 | logging.warning( |
| 198 | 'No data collector artifacts were found for %s', |
| 199 | android_version) |
| 200 | return variables |
| 201 | |
| 202 | pin_version = gs_context.Cat(pin_path, encoding='utf-8').rstrip() |
| 203 | logging.info('Pinned version %s overrides %s', |
| 204 | pin_version, android_version) |
| 205 | variables = FindDataCollectorArtifacts(gs_context, |
| 206 | pin_version, |
| 207 | runtime_artifacts_bucket_url, |
| 208 | pin_version) |
| 209 | if not variables: |
| 210 | # If pin version set it must contain data. |
| 211 | raise Exception('Pinned version %s:%s does not contain artificats' % ( |
| 212 | build_branch, pin_version)) |
| 213 | |
| 214 | return variables |
| 215 | |
| 216 | |
Hidehiko Abe | 4fd94ae | 2017-01-24 18:59:55 +0900 | [diff] [blame] | 217 | def MarkAndroidEBuildAsStable(stable_candidate, unstable_ebuild, |
| 218 | android_package, android_version, package_dir, |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 219 | build_branch, arc_bucket_url, |
| 220 | runtime_artifacts_bucket_url, |
| 221 | build_targets): |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 222 | r"""Uprevs the Android ebuild. |
| 223 | |
| 224 | This is the main function that uprevs from a stable candidate |
| 225 | to its new version. |
| 226 | |
| 227 | Args: |
| 228 | stable_candidate: ebuild that corresponds to the stable ebuild we are |
| 229 | revving from. If None, builds the a new ebuild given the version |
| 230 | with revision set to 1. |
| 231 | unstable_ebuild: ebuild corresponding to the unstable ebuild for Android. |
Hidehiko Abe | 4fd94ae | 2017-01-24 18:59:55 +0900 | [diff] [blame] | 232 | android_package: android package name. |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 233 | android_version: The \d+ build id of Android. |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 234 | package_dir: Path to the android-container package dir. |
David Riley | 73f00d9 | 2016-02-16 18:54:20 -0800 | [diff] [blame] | 235 | build_branch: branch of Android builds. |
| 236 | arc_bucket_url: URL of the target ARC build gs bucket. |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 237 | runtime_artifacts_bucket_url: root of runtime artifacts |
Nicolas Norvez | 4bd854f | 2017-05-23 10:04:45 -0700 | [diff] [blame] | 238 | build_targets: build targets for this particular Android branch. |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 239 | |
| 240 | Returns: |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 241 | Tuple[str, List[str], List[str]] if revved, or None |
| 242 | 1. Full portage version atom (including rc's, etc) that was revved. |
| 243 | 2. List of files to be `git add`ed. |
| 244 | 3. List of files to be `git rm`ed. |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 245 | """ |
| 246 | def IsTheNewEBuildRedundant(new_ebuild, stable_ebuild): |
| 247 | """Returns True if the new ebuild is redundant. |
| 248 | |
| 249 | This is True if there if the current stable ebuild is the exact same copy |
| 250 | of the new one. |
| 251 | """ |
| 252 | if not stable_ebuild: |
| 253 | return False |
| 254 | |
David Riley | 676f540 | 2016-02-12 17:24:23 -0800 | [diff] [blame] | 255 | if stable_candidate.version_no_rev == new_ebuild.version_no_rev: |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 256 | return filecmp.cmp( |
| 257 | new_ebuild.ebuild_path, stable_ebuild.ebuild_path, shallow=False) |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 258 | return False |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 259 | |
| 260 | # Case where we have the last stable candidate with same version just rev. |
David Riley | 676f540 | 2016-02-12 17:24:23 -0800 | [diff] [blame] | 261 | if stable_candidate and stable_candidate.version_no_rev == android_version: |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 262 | new_ebuild_path = '%s-r%d.ebuild' % ( |
| 263 | stable_candidate.ebuild_path_no_revision, |
| 264 | stable_candidate.current_revision + 1) |
| 265 | else: |
Hidehiko Abe | 4fd94ae | 2017-01-24 18:59:55 +0900 | [diff] [blame] | 266 | pf = '%s-%s-r1' % (android_package, android_version) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 267 | new_ebuild_path = os.path.join(package_dir, '%s.ebuild' % pf) |
| 268 | |
David Riley | 73f00d9 | 2016-02-16 18:54:20 -0800 | [diff] [blame] | 269 | variables = {'BASE_URL': arc_bucket_url} |
Mike Frysinger | 0bdbc10 | 2019-06-13 15:27:29 -0400 | [diff] [blame] | 270 | for build, (target, _) in build_targets.items(): |
David Riley | 73f00d9 | 2016-02-16 18:54:20 -0800 | [diff] [blame] | 271 | variables[build + '_TARGET'] = '%s-%s' % (build_branch, target) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 272 | |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 273 | variables.update(UpdateDataCollectorArtifacts( |
Yury Khmel | b009aeb | 2020-08-19 19:40:00 -0700 | [diff] [blame] | 274 | android_version, runtime_artifacts_bucket_url, build_branch)) |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 275 | |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 276 | portage_util.EBuild.MarkAsStable( |
| 277 | unstable_ebuild.ebuild_path, new_ebuild_path, |
| 278 | variables, make_stable=True) |
| 279 | new_ebuild = portage_util.EBuild(new_ebuild_path) |
| 280 | |
| 281 | # Determine whether this is ebuild is redundant. |
| 282 | if IsTheNewEBuildRedundant(new_ebuild, stable_candidate): |
| 283 | msg = 'Previous ebuild with same version found and ebuild is redundant.' |
| 284 | logging.info(msg) |
Shao-Chuan Lee | 085e3d7 | 2020-05-11 16:00:42 +0900 | [diff] [blame] | 285 | logging.PrintBuildbotStepText('%s %s not revved' |
| 286 | % (stable_candidate.pkgname, |
| 287 | stable_candidate.version)) |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 288 | osutils.SafeUnlink(new_ebuild_path) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 289 | return None |
| 290 | |
Shao-Chuan Lee | 085e3d7 | 2020-05-11 16:00:42 +0900 | [diff] [blame] | 291 | # PFQ runs should always be able to find a stable candidate. |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 292 | if stable_candidate: |
Shao-Chuan Lee | 085e3d7 | 2020-05-11 16:00:42 +0900 | [diff] [blame] | 293 | PrintUprevMetadata(build_branch, stable_candidate, new_ebuild) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 294 | |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 295 | files_to_add = [new_ebuild_path] |
| 296 | files_to_remove = [] |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 297 | if stable_candidate and not stable_candidate.IsSticky(): |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 298 | osutils.SafeUnlink(stable_candidate.ebuild_path) |
| 299 | files_to_remove.append(stable_candidate.ebuild_path) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 300 | |
| 301 | # Update ebuild manifest and git add it. |
| 302 | gen_manifest_cmd = ['ebuild', new_ebuild_path, 'manifest', '--force'] |
Mike Frysinger | 45602c7 | 2019-09-22 02:15:11 -0400 | [diff] [blame] | 303 | cros_build_lib.run(gen_manifest_cmd, extra_env=None, print_cmd=True) |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 304 | files_to_add.append('Manifest') |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 305 | |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 306 | return ( |
| 307 | f'{new_ebuild.package}-{new_ebuild.version}', |
| 308 | files_to_add, |
| 309 | files_to_remove, |
| 310 | ) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 311 | |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 312 | |
Shao-Chuan Lee | 007dbe8 | 2021-02-09 14:05:39 +0900 | [diff] [blame] | 313 | def _PrepareGitBranch(overlay_dir): |
| 314 | """Prepares a git branch for the uprev commit. |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 315 | |
Shao-Chuan Lee | 007dbe8 | 2021-02-09 14:05:39 +0900 | [diff] [blame] | 316 | If the overlay project is currently on a branch (e.g. patches are being |
| 317 | applied), rebase the new branch on top of it. |
| 318 | |
| 319 | Args: |
| 320 | overlay_dir: The overlay directory. |
| 321 | """ |
| 322 | existing_branch = git.GetCurrentBranch(overlay_dir) |
| 323 | repo_util.Repository.MustFind(overlay_dir).StartBranch( |
| 324 | constants.STABLE_EBUILD_BRANCH, projects=['.'], cwd=overlay_dir) |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 325 | if existing_branch: |
| 326 | git.RunGit(overlay_dir, ['rebase', existing_branch]) |
| 327 | |
| 328 | |
| 329 | def _CommitChange(message, android_package_dir, files_to_add, files_to_remove): |
| 330 | """Commit changes to git with list of files to add/remove.""" |
| 331 | git.RunGit(android_package_dir, ['add', '--'] + files_to_add) |
| 332 | git.RunGit(android_package_dir, ['rm', '--'] + files_to_remove) |
| 333 | |
| 334 | portage_util.EBuild.CommitChange(message, android_package_dir) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 335 | |
| 336 | |
| 337 | def GetParser(): |
| 338 | """Creates the argument parser.""" |
| 339 | parser = commandline.ArgumentParser() |
| 340 | parser.add_argument('-b', '--boards') |
| 341 | parser.add_argument('--android_bucket_url', |
David Riley | 73f00d9 | 2016-02-16 18:54:20 -0800 | [diff] [blame] | 342 | default=constants.ANDROID_BUCKET_URL, |
| 343 | type='gs_path') |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 344 | parser.add_argument('--android_build_branch', |
Shuhei Takahashi | 6d02c19 | 2017-04-05 14:01:24 +0900 | [diff] [blame] | 345 | required=True, |
| 346 | help='Android branch to import from. ' |
| 347 | 'Ex: git_mnc-dr-arc-dev') |
Hidehiko Abe | 4fd94ae | 2017-01-24 18:59:55 +0900 | [diff] [blame] | 348 | parser.add_argument('--android_package', |
| 349 | default=constants.ANDROID_PACKAGE_NAME) |
David Riley | 73f00d9 | 2016-02-16 18:54:20 -0800 | [diff] [blame] | 350 | parser.add_argument('--arc_bucket_url', |
| 351 | default=constants.ARC_BUCKET_URL, |
| 352 | type='gs_path') |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 353 | parser.add_argument('-f', '--force_version', |
| 354 | help='Android build id to use') |
| 355 | parser.add_argument('-s', '--srcroot', |
| 356 | default=os.path.join(os.environ['HOME'], 'trunk', 'src'), |
| 357 | help='Path to the src directory') |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 358 | parser.add_argument('--runtime_artifacts_bucket_url', |
| 359 | default=_RUNTIME_ARTIFACTS_BUCKET_URL, |
| 360 | type='gs_path') |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 361 | parser.add_argument('--skip_commit', |
| 362 | action='store_true', |
| 363 | help='Skip commiting uprev changes to git') |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 364 | return parser |
| 365 | |
| 366 | |
| 367 | def main(argv): |
Hidehiko Abe | c9ecf26 | 2017-07-05 15:17:41 +0900 | [diff] [blame] | 368 | logging.EnableBuildbotMarkers() |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 369 | parser = GetParser() |
| 370 | options = parser.parse_args(argv) |
| 371 | options.Freeze() |
| 372 | |
| 373 | overlay_dir = os.path.abspath(_OVERLAY_DIR % {'srcroot': options.srcroot}) |
Hidehiko Abe | 4fd94ae | 2017-01-24 18:59:55 +0900 | [diff] [blame] | 374 | android_package_dir = os.path.join( |
| 375 | overlay_dir, |
| 376 | portage_util.GetFullAndroidPortagePackageName(options.android_package)) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 377 | version_to_uprev = None |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 378 | |
| 379 | (unstable_ebuild, stable_ebuilds) = FindAndroidCandidates(android_package_dir) |
Shao-Chuan Lee | 7fd0ca1 | 2021-03-19 15:57:40 +0900 | [diff] [blame] | 380 | acls = android.MakeAclDict(android_package_dir) |
| 381 | build_targets = android.MakeBuildTargetDict(options.android_package, |
| 382 | options.android_build_branch) |
Hidehiko Abe | 1ebc25d | 2016-07-28 02:24:37 +0900 | [diff] [blame] | 383 | # Mirror artifacts, i.e., images and some sdk tools (e.g., adb, aapt). |
Shao-Chuan Lee | 7fd0ca1 | 2021-03-19 15:57:40 +0900 | [diff] [blame] | 384 | version_to_uprev = android.MirrorArtifacts(options.android_bucket_url, |
| 385 | options.android_build_branch, |
| 386 | options.arc_bucket_url, acls, |
| 387 | build_targets, |
| 388 | options.force_version) |
Hidehiko Abe | 1ebc25d | 2016-07-28 02:24:37 +0900 | [diff] [blame] | 389 | |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 390 | stable_candidate = portage_util.BestEBuild(stable_ebuilds) |
| 391 | |
| 392 | if stable_candidate: |
Lann Martin | ffb9516 | 2018-08-28 12:02:54 -0600 | [diff] [blame] | 393 | logging.info('Stable candidate found %s', stable_candidate.version) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 394 | else: |
| 395 | logging.info('No stable candidate found.') |
| 396 | |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 397 | if not options.skip_commit: |
Shao-Chuan Lee | 007dbe8 | 2021-02-09 14:05:39 +0900 | [diff] [blame] | 398 | _PrepareGitBranch(overlay_dir) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 399 | |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 400 | revved = MarkAndroidEBuildAsStable( |
Hidehiko Abe | 4fd94ae | 2017-01-24 18:59:55 +0900 | [diff] [blame] | 401 | stable_candidate, unstable_ebuild, options.android_package, |
David Riley | 73f00d9 | 2016-02-16 18:54:20 -0800 | [diff] [blame] | 402 | version_to_uprev, android_package_dir, |
khmel@chromium.org | d3ec3d7 | 2020-04-29 15:57:35 -0700 | [diff] [blame] | 403 | options.android_build_branch, options.arc_bucket_url, |
| 404 | options.runtime_artifacts_bucket_url, build_targets) |
Shao-Chuan Lee | 301a419 | 2021-02-08 11:53:49 +0900 | [diff] [blame] | 405 | |
| 406 | if revved: |
| 407 | android_version_atom, files_to_add, files_to_remove = revved |
| 408 | if not options.skip_commit: |
| 409 | _CommitChange( |
| 410 | _GIT_COMMIT_MESSAGE % {'android_package': options.android_package, |
| 411 | 'android_version': version_to_uprev}, |
| 412 | android_package_dir, |
| 413 | files_to_add, |
| 414 | files_to_remove, |
| 415 | ) |
David Riley | c0da9d9 | 2016-02-01 12:11:01 -0800 | [diff] [blame] | 416 | if options.boards: |
| 417 | cros_mark_as_stable.CleanStalePackages(options.srcroot, |
| 418 | options.boards.split(':'), |
| 419 | [android_version_atom]) |
| 420 | |
| 421 | # Explicit print to communicate to caller. |
| 422 | print('ANDROID_VERSION_ATOM=%s' % android_version_atom) |