blob: 1e8abdaf8f9325656e02ca54f6b346713f5cb00b [file] [log] [blame]
David Rileyc0da9d92016-02-01 12:11:01 -08001# Copyright 2016 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""This module uprevs Android for cbuildbot.
6
Shao-Chuan Lee84bf9a22021-11-19 17:42:11 +09007After calling, it prints out a JSON representing the result, with the new
8Android version atom string included. A caller could then use this atom with
9emerge to build the newly uprevved version of Android e.g.
David Rileyc0da9d92016-02-01 12:11:01 -080010
Shuhei Takahashi6d02c192017-04-05 14:01:24 +090011./cros_mark_android_as_stable \
Shao-Chuan Lee9c39e0c2020-04-24 11:40:34 +090012 --android_build_branch=git_pi-arc \
13 --android_package=android-container-pi
Shuhei Takahashi6d02c192017-04-05 14:01:24 +090014
Shao-Chuan Lee84bf9a22021-11-19 17:42:11 +090015Returns {"android_atom": "chromeos-base/android-container-pi-6417892-r1"}
David Rileyc0da9d92016-02-01 12:11:01 -080016
Shao-Chuan Lee9c39e0c2020-04-24 11:40:34 +090017emerge-eve =chromeos-base/android-container-pi-6417892-r1
David Rileyc0da9d92016-02-01 12:11:01 -080018"""
19
David Rileyc0da9d92016-02-01 12:11:01 -080020import filecmp
21import glob
Junichi Uekawad21f94d2020-07-27 15:50:05 +090022import json
Chris McDonaldb55b7032021-06-17 16:41:32 -060023import logging
David Rileyc0da9d92016-02-01 12:11:01 -080024import os
25
Chris McDonaldb55b7032021-06-17 16:41:32 -060026from chromite.cbuildbot import cbuildbot_alerts
David Rileyc0da9d92016-02-01 12:11:01 -080027from chromite.lib import commandline
Chris McDonaldb55b7032021-06-17 16:41:32 -060028from chromite.lib import constants
David Rileyc0da9d92016-02-01 12:11:01 -080029from chromite.lib import cros_build_lib
David Rileyc0da9d92016-02-01 12:11:01 -080030from chromite.lib import git
31from chromite.lib import gs
Shao-Chuan Lee301a4192021-02-08 11:53:49 +090032from chromite.lib import osutils
David Rileyc0da9d92016-02-01 12:11:01 -080033from chromite.lib import portage_util
Shao-Chuan Lee007dbe82021-02-09 14:05:39 +090034from chromite.lib import repo_util
David Rileyc0da9d92016-02-01 12:11:01 -080035from chromite.scripts import cros_mark_as_stable
Shao-Chuan Lee7fd0ca12021-03-19 15:57:40 +090036from chromite.service import android
David Rileyc0da9d92016-02-01 12:11:01 -080037
38
39# Dir where all the action happens.
40_OVERLAY_DIR = '%(srcroot)s/private-overlays/project-cheets-private/'
41
Junichi Uekawa6d61ab02020-04-15 14:52:28 +090042_GIT_COMMIT_MESSAGE = """Marking latest for %(android_package)s ebuild with \
43version %(android_version)s as stable.
44
45BUG=None
46TEST=CQ
47"""
David Rileyc0da9d92016-02-01 12:11:01 -080048
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -070049_RUNTIME_ARTIFACTS_BUCKET_URL = 'gs://chromeos-arc-images/runtime_artifacts'
David Rileyc0da9d92016-02-01 12:11:01 -080050
David Rileyc0da9d92016-02-01 12:11:01 -080051
52def FindAndroidCandidates(package_dir):
53 """Return a tuple of Android's unstable ebuild and stable ebuilds.
54
55 Args:
56 package_dir: The path to where the package ebuild is stored.
57
58 Returns:
59 Tuple [unstable_ebuild, stable_ebuilds].
60
61 Raises:
62 Exception: if no unstable ebuild exists for Android.
63 """
64 stable_ebuilds = []
65 unstable_ebuilds = []
66 for path in glob.glob(os.path.join(package_dir, '*.ebuild')):
67 ebuild = portage_util.EBuild(path)
68 if ebuild.version == '9999':
69 unstable_ebuilds.append(ebuild)
70 else:
71 stable_ebuilds.append(ebuild)
72
73 # Apply some sanity checks.
74 if not unstable_ebuilds:
75 raise Exception('Missing 9999 ebuild for %s' % package_dir)
76 if not stable_ebuilds:
Lann Martinffb95162018-08-28 12:02:54 -060077 logging.warning('Missing stable ebuild for %s', package_dir)
David Rileyc0da9d92016-02-01 12:11:01 -080078
79 return portage_util.BestEBuild(unstable_ebuilds), stable_ebuilds
80
81
Shao-Chuan Lee085e3d72020-05-11 16:00:42 +090082def PrintUprevMetadata(build_branch, stable_candidate, new_ebuild):
83 """Shows metadata on buildbot page at UprevAndroid step.
David Rileyc0da9d92016-02-01 12:11:01 -080084
85 Args:
Shao-Chuan Lee085e3d72020-05-11 16:00:42 +090086 build_branch: The branch of Android builds.
87 stable_candidate: The existing stable ebuild.
88 new_ebuild: The newly written ebuild.
David Rileyc0da9d92016-02-01 12:11:01 -080089 """
Shao-Chuan Lee085e3d72020-05-11 16:00:42 +090090 # Examples:
91 # "android-container-pi revved 6461825-r1 -> 6468247-r1"
92 # "android-container-pi revved 6461825-r1 -> 6461825-r2 (ebuild update only)"
93 msg = '%s revved %s -> %s' % (stable_candidate.pkgname,
94 stable_candidate.version,
95 new_ebuild.version)
96
97 old_android = stable_candidate.version_no_rev
98 new_android = new_ebuild.version_no_rev
99
100 if old_android == new_android:
101 msg += ' (ebuild update only)'
102 else:
103 ab_link = ('https://android-build.googleplex.com'
104 '/builds/%s/branches/%s/cls?end=%s'
105 % (new_android, build_branch, old_android))
Chris McDonaldb55b7032021-06-17 16:41:32 -0600106 cbuildbot_alerts.PrintBuildbotLink('Android changelog', ab_link)
Shao-Chuan Lee085e3d72020-05-11 16:00:42 +0900107
Chris McDonaldb55b7032021-06-17 16:41:32 -0600108 cbuildbot_alerts.PrintBuildbotStepText(msg)
109 cbuildbot_alerts.PrintKitchenSetBuildProperty('android_uprev', json.dumps({
Junichi Uekawad21f94d2020-07-27 15:50:05 +0900110 'branch': build_branch,
111 'new': new_ebuild.version,
112 'old': stable_candidate.version,
113 'pkgname': stable_candidate.pkgname,
114 }))
David Rileyc0da9d92016-02-01 12:11:01 -0800115
116
Yury Khmelb009aeb2020-08-19 19:40:00 -0700117def FindDataCollectorArtifacts(gs_context,
118 android_version,
119 runtime_artifacts_bucket_url,
120 version_reference):
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700121 r"""Finds and includes into variables artifacts from arc.DataCollector.
122
Yury Khmelb009aeb2020-08-19 19:40:00 -0700123 This is used from UpdateDataCollectorArtifacts in order to check the
124 particular version.
125
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700126 Args:
Yury Khmelb009aeb2020-08-19 19:40:00 -0700127 gs_context: context to execute gsutil
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700128 android_version: The \d+ build id of Android.
129 runtime_artifacts_bucket_url: root of runtime artifacts
Yury Khmelb009aeb2020-08-19 19:40:00 -0700130 build_branch: build branch. Used to determine the pinned version if exists.
131 version_reference: which version to use as a reference. Could be '${PV}' in
132 case version of data collector artifacts matches the
133 Android version or direct version in case of override.
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700134
135 Returns:
Yury Khmelb009aeb2020-08-19 19:40:00 -0700136 dictionary with filled ebuild variables. This dictionary is empty in case
137 no artificats are found.
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700138 """
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700139 variables = {}
Yury Khmelb009aeb2020-08-19 19:40:00 -0700140
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700141 buckets = ['ureadahead_pack', 'gms_core_cache']
142 archs = ['arm', 'arm64', 'x86', 'x86_64']
143 build_types = ['user', 'userdebug']
144
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700145 for bucket in buckets:
146 for arch in archs:
147 for build_type in build_types:
148 path = (f'{runtime_artifacts_bucket_url}/{bucket}_{arch}_{build_type}_'
Yury Khmele1b74402020-05-18 08:41:35 -0700149 f'{android_version}.tar')
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700150 if gs_context.Exists(path):
151 variables[(f'{arch}_{build_type}_{bucket}').upper()] = (
152 f'{runtime_artifacts_bucket_url}/{bucket}_{arch}_{build_type}_'
153 f'{version_reference}.tar')
154
155 return variables
156
157
Yury Khmelb009aeb2020-08-19 19:40:00 -0700158def UpdateDataCollectorArtifacts(android_version,
159 runtime_artifacts_bucket_url,
160 build_branch):
161 r"""Finds and includes into variables artifacts from arc.DataCollector.
162
163 This verifies default android version. In case artificts are not found for
164 default Android version it tries to find artifacts for pinned version. If
165 pinned version is provided, it is required artifacts exist for the pinned
166 version.
167
168 Args:
169 android_version: The \d+ build id of Android.
170 runtime_artifacts_bucket_url: root of runtime artifacts
171 build_branch: build branch. Used to determine the pinned version if exists.
172
173 Returns:
174 dictionary with filled ebuild variables.
175 """
176
177 gs_context = gs.GSContext()
178 # Check the existing version. If we find any artifacts, use them.
179 variables = FindDataCollectorArtifacts(gs_context,
180 android_version,
181 runtime_artifacts_bucket_url,
182 '${PV}')
183 if variables:
184 # Data artificts were found.
185 return variables
186
187 # Check pinned version for the current branch.
188 pin_path = (f'{runtime_artifacts_bucket_url}/{build_branch}_pin_version')
189 if not gs_context.Exists(pin_path):
190 # No pinned version.
191 logging.warning(
192 'No data collector artifacts were found for %s',
193 android_version)
194 return variables
195
196 pin_version = gs_context.Cat(pin_path, encoding='utf-8').rstrip()
197 logging.info('Pinned version %s overrides %s',
198 pin_version, android_version)
199 variables = FindDataCollectorArtifacts(gs_context,
200 pin_version,
201 runtime_artifacts_bucket_url,
202 pin_version)
203 if not variables:
204 # If pin version set it must contain data.
205 raise Exception('Pinned version %s:%s does not contain artificats' % (
206 build_branch, pin_version))
207
208 return variables
209
210
Hidehiko Abe4fd94ae2017-01-24 18:59:55 +0900211def MarkAndroidEBuildAsStable(stable_candidate, unstable_ebuild,
212 android_package, android_version, package_dir,
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700213 build_branch, arc_bucket_url,
Shao-Chuan Lee7e9eacb2021-03-19 16:45:21 +0900214 runtime_artifacts_bucket_url):
David Rileyc0da9d92016-02-01 12:11:01 -0800215 r"""Uprevs the Android ebuild.
216
217 This is the main function that uprevs from a stable candidate
218 to its new version.
219
220 Args:
221 stable_candidate: ebuild that corresponds to the stable ebuild we are
222 revving from. If None, builds the a new ebuild given the version
223 with revision set to 1.
224 unstable_ebuild: ebuild corresponding to the unstable ebuild for Android.
Hidehiko Abe4fd94ae2017-01-24 18:59:55 +0900225 android_package: android package name.
David Rileyc0da9d92016-02-01 12:11:01 -0800226 android_version: The \d+ build id of Android.
David Rileyc0da9d92016-02-01 12:11:01 -0800227 package_dir: Path to the android-container package dir.
David Riley73f00d92016-02-16 18:54:20 -0800228 build_branch: branch of Android builds.
229 arc_bucket_url: URL of the target ARC build gs bucket.
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700230 runtime_artifacts_bucket_url: root of runtime artifacts
David Rileyc0da9d92016-02-01 12:11:01 -0800231
232 Returns:
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900233 Tuple[str, List[str], List[str]] if revved, or None
234 1. Full portage version atom (including rc's, etc) that was revved.
235 2. List of files to be `git add`ed.
236 3. List of files to be `git rm`ed.
David Rileyc0da9d92016-02-01 12:11:01 -0800237 """
238 def IsTheNewEBuildRedundant(new_ebuild, stable_ebuild):
239 """Returns True if the new ebuild is redundant.
240
241 This is True if there if the current stable ebuild is the exact same copy
242 of the new one.
243 """
244 if not stable_ebuild:
245 return False
246
David Riley676f5402016-02-12 17:24:23 -0800247 if stable_candidate.version_no_rev == new_ebuild.version_no_rev:
David Rileyc0da9d92016-02-01 12:11:01 -0800248 return filecmp.cmp(
249 new_ebuild.ebuild_path, stable_ebuild.ebuild_path, shallow=False)
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700250 return False
David Rileyc0da9d92016-02-01 12:11:01 -0800251
252 # Case where we have the last stable candidate with same version just rev.
David Riley676f5402016-02-12 17:24:23 -0800253 if stable_candidate and stable_candidate.version_no_rev == android_version:
David Rileyc0da9d92016-02-01 12:11:01 -0800254 new_ebuild_path = '%s-r%d.ebuild' % (
255 stable_candidate.ebuild_path_no_revision,
256 stable_candidate.current_revision + 1)
257 else:
Hidehiko Abe4fd94ae2017-01-24 18:59:55 +0900258 pf = '%s-%s-r1' % (android_package, android_version)
David Rileyc0da9d92016-02-01 12:11:01 -0800259 new_ebuild_path = os.path.join(package_dir, '%s.ebuild' % pf)
260
Shao-Chuan Lee7e9eacb2021-03-19 16:45:21 +0900261 build_targets = constants.ANDROID_BRANCH_TO_BUILD_TARGETS[build_branch]
David Riley73f00d92016-02-16 18:54:20 -0800262 variables = {'BASE_URL': arc_bucket_url}
Shao-Chuan Lee41fe3522021-03-22 15:50:31 +0900263 for var, target in build_targets.items():
264 variables[var] = f'{build_branch}-linux-{target}'
David Rileyc0da9d92016-02-01 12:11:01 -0800265
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700266 variables.update(UpdateDataCollectorArtifacts(
Yury Khmelb009aeb2020-08-19 19:40:00 -0700267 android_version, runtime_artifacts_bucket_url, build_branch))
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700268
David Rileyc0da9d92016-02-01 12:11:01 -0800269 portage_util.EBuild.MarkAsStable(
270 unstable_ebuild.ebuild_path, new_ebuild_path,
271 variables, make_stable=True)
272 new_ebuild = portage_util.EBuild(new_ebuild_path)
273
274 # Determine whether this is ebuild is redundant.
275 if IsTheNewEBuildRedundant(new_ebuild, stable_candidate):
276 msg = 'Previous ebuild with same version found and ebuild is redundant.'
277 logging.info(msg)
Chris McDonaldb55b7032021-06-17 16:41:32 -0600278 cbuildbot_alerts.PrintBuildbotStepText('%s %s not revved'
Shao-Chuan Lee84bf9a22021-11-19 17:42:11 +0900279 % (stable_candidate.pkgname,
280 stable_candidate.version))
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900281 osutils.SafeUnlink(new_ebuild_path)
David Rileyc0da9d92016-02-01 12:11:01 -0800282 return None
283
Shao-Chuan Lee085e3d72020-05-11 16:00:42 +0900284 # PFQ runs should always be able to find a stable candidate.
David Rileyc0da9d92016-02-01 12:11:01 -0800285 if stable_candidate:
Shao-Chuan Lee085e3d72020-05-11 16:00:42 +0900286 PrintUprevMetadata(build_branch, stable_candidate, new_ebuild)
David Rileyc0da9d92016-02-01 12:11:01 -0800287
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900288 files_to_add = [new_ebuild_path]
289 files_to_remove = []
David Rileyc0da9d92016-02-01 12:11:01 -0800290 if stable_candidate and not stable_candidate.IsSticky():
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900291 osutils.SafeUnlink(stable_candidate.ebuild_path)
292 files_to_remove.append(stable_candidate.ebuild_path)
David Rileyc0da9d92016-02-01 12:11:01 -0800293
294 # Update ebuild manifest and git add it.
295 gen_manifest_cmd = ['ebuild', new_ebuild_path, 'manifest', '--force']
Mike Frysinger45602c72019-09-22 02:15:11 -0400296 cros_build_lib.run(gen_manifest_cmd, extra_env=None, print_cmd=True)
Shao-Chuan Lee556015c2021-11-26 00:03:28 +0900297 files_to_add.append(os.path.join(package_dir, 'Manifest'))
David Rileyc0da9d92016-02-01 12:11:01 -0800298
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900299 return (
300 f'{new_ebuild.package}-{new_ebuild.version}',
301 files_to_add,
302 files_to_remove,
303 )
David Rileyc0da9d92016-02-01 12:11:01 -0800304
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900305
Shao-Chuan Lee007dbe82021-02-09 14:05:39 +0900306def _PrepareGitBranch(overlay_dir):
307 """Prepares a git branch for the uprev commit.
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900308
Shao-Chuan Lee007dbe82021-02-09 14:05:39 +0900309 If the overlay project is currently on a branch (e.g. patches are being
310 applied), rebase the new branch on top of it.
311
312 Args:
313 overlay_dir: The overlay directory.
314 """
315 existing_branch = git.GetCurrentBranch(overlay_dir)
316 repo_util.Repository.MustFind(overlay_dir).StartBranch(
317 constants.STABLE_EBUILD_BRANCH, projects=['.'], cwd=overlay_dir)
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900318 if existing_branch:
319 git.RunGit(overlay_dir, ['rebase', existing_branch])
320
321
322def _CommitChange(message, android_package_dir, files_to_add, files_to_remove):
323 """Commit changes to git with list of files to add/remove."""
324 git.RunGit(android_package_dir, ['add', '--'] + files_to_add)
325 git.RunGit(android_package_dir, ['rm', '--'] + files_to_remove)
326
327 portage_util.EBuild.CommitChange(message, android_package_dir)
David Rileyc0da9d92016-02-01 12:11:01 -0800328
329
330def GetParser():
331 """Creates the argument parser."""
332 parser = commandline.ArgumentParser()
333 parser.add_argument('-b', '--boards')
334 parser.add_argument('--android_bucket_url',
Shao-Chuan Leee3940152021-03-25 14:44:36 +0900335 default=android.ANDROID_BUCKET_URL,
David Riley73f00d92016-02-16 18:54:20 -0800336 type='gs_path')
David Rileyc0da9d92016-02-01 12:11:01 -0800337 parser.add_argument('--android_build_branch',
Shao-Chuan Lee7e9eacb2021-03-19 16:45:21 +0900338 choices=constants.ANDROID_BRANCH_TO_BUILD_TARGETS,
Shao-Chuan Leea4b4f302021-05-12 14:40:20 +0900339 help='Android branch to import from, overriding default')
Hidehiko Abe4fd94ae2017-01-24 18:59:55 +0900340 parser.add_argument('--android_package',
Shao-Chuan Leea4b4f302021-05-12 14:40:20 +0900341 required=True,
342 choices=constants.ANDROID_ALL_PACKAGES,
343 help='Android package to uprev')
David Riley73f00d92016-02-16 18:54:20 -0800344 parser.add_argument('--arc_bucket_url',
345 default=constants.ARC_BUCKET_URL,
346 type='gs_path')
David Rileyc0da9d92016-02-01 12:11:01 -0800347 parser.add_argument('-f', '--force_version',
348 help='Android build id to use')
349 parser.add_argument('-s', '--srcroot',
350 default=os.path.join(os.environ['HOME'], 'trunk', 'src'),
351 help='Path to the src directory')
khmel@chromium.orgd3ec3d72020-04-29 15:57:35 -0700352 parser.add_argument('--runtime_artifacts_bucket_url',
353 default=_RUNTIME_ARTIFACTS_BUCKET_URL,
354 type='gs_path')
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900355 parser.add_argument('--skip_commit',
356 action='store_true',
357 help='Skip commiting uprev changes to git')
David Rileyc0da9d92016-02-01 12:11:01 -0800358 return parser
359
360
361def main(argv):
Chris McDonaldb55b7032021-06-17 16:41:32 -0600362 cbuildbot_alerts.EnableBuildbotMarkers()
David Rileyc0da9d92016-02-01 12:11:01 -0800363 parser = GetParser()
364 options = parser.parse_args(argv)
365 options.Freeze()
366
367 overlay_dir = os.path.abspath(_OVERLAY_DIR % {'srcroot': options.srcroot})
Hidehiko Abe4fd94ae2017-01-24 18:59:55 +0900368 android_package_dir = os.path.join(
369 overlay_dir,
370 portage_util.GetFullAndroidPortagePackageName(options.android_package))
David Rileyc0da9d92016-02-01 12:11:01 -0800371
Shao-Chuan Leea4b4f302021-05-12 14:40:20 +0900372 # Use default Android branch if not overridden.
373 android_build_branch = (
374 options.android_build_branch or
375 android.GetAndroidBranchForPackage(options.android_package))
376
David Rileyc0da9d92016-02-01 12:11:01 -0800377 (unstable_ebuild, stable_ebuilds) = FindAndroidCandidates(android_package_dir)
Hidehiko Abe1ebc25d2016-07-28 02:24:37 +0900378 # Mirror artifacts, i.e., images and some sdk tools (e.g., adb, aapt).
Shao-Chuan Lee7fd0ca12021-03-19 15:57:40 +0900379 version_to_uprev = android.MirrorArtifacts(options.android_bucket_url,
Shao-Chuan Leea4b4f302021-05-12 14:40:20 +0900380 android_build_branch,
Shao-Chuan Lee6865ff52021-03-19 18:29:18 +0900381 options.arc_bucket_url,
382 android_package_dir,
Shao-Chuan Lee7fd0ca12021-03-19 15:57:40 +0900383 options.force_version)
Hidehiko Abe1ebc25d2016-07-28 02:24:37 +0900384
David Rileyc0da9d92016-02-01 12:11:01 -0800385 stable_candidate = portage_util.BestEBuild(stable_ebuilds)
386
387 if stable_candidate:
Lann Martinffb95162018-08-28 12:02:54 -0600388 logging.info('Stable candidate found %s', stable_candidate.version)
David Rileyc0da9d92016-02-01 12:11:01 -0800389 else:
390 logging.info('No stable candidate found.')
391
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900392 if not options.skip_commit:
Shao-Chuan Lee007dbe82021-02-09 14:05:39 +0900393 _PrepareGitBranch(overlay_dir)
David Rileyc0da9d92016-02-01 12:11:01 -0800394
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900395 revved = MarkAndroidEBuildAsStable(
Hidehiko Abe4fd94ae2017-01-24 18:59:55 +0900396 stable_candidate, unstable_ebuild, options.android_package,
Shao-Chuan Leea4b4f302021-05-12 14:40:20 +0900397 version_to_uprev, android_package_dir, android_build_branch,
398 options.arc_bucket_url, options.runtime_artifacts_bucket_url)
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900399
Shao-Chuan Leedea458f2021-11-25 23:46:53 +0900400 output = dict(revved=revved)
401
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900402 if revved:
Shao-Chuan Lee84bf9a22021-11-19 17:42:11 +0900403 android_atom, files_to_add, files_to_remove = revved
Shao-Chuan Lee301a4192021-02-08 11:53:49 +0900404 if not options.skip_commit:
405 _CommitChange(
406 _GIT_COMMIT_MESSAGE % {'android_package': options.android_package,
407 'android_version': version_to_uprev},
408 android_package_dir,
409 files_to_add,
410 files_to_remove,
411 )
David Rileyc0da9d92016-02-01 12:11:01 -0800412 if options.boards:
413 cros_mark_as_stable.CleanStalePackages(options.srcroot,
414 options.boards.split(':'),
Shao-Chuan Lee84bf9a22021-11-19 17:42:11 +0900415 [android_atom])
David Rileyc0da9d92016-02-01 12:11:01 -0800416
Shao-Chuan Leedea458f2021-11-25 23:46:53 +0900417 output['android_atom'] = android_atom
Shao-Chuan Lee62cfbc72021-11-30 14:15:07 +0900418 # This field is read by the PUpr uprev handler for creating CLs. We cannot
419 # return absolute paths because this script runs inside chroot but the uprev
420 # handler runs outside.
421 # Here we return paths relative to |overlay_dir|.
422 output['modified_files'] = [os.path.relpath(f, overlay_dir)
423 for f in files_to_add + files_to_remove]
Shao-Chuan Leedea458f2021-11-25 23:46:53 +0900424
425 # The output is being parsed by service.packages.uprev_android and has to be
426 # in its own single line. When invoked from chromite API endpoints, entering
427 # chroot can generate junk messages on stdout, so we prefix our output with a
428 # line break to further ensure that.
429 print('\n' + json.dumps(output))