blob: b9740c44490d680e10aa6b699d8a66c0da49c54f [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2019 The ChromiumOS Authors
Alex Kleineb77ffa2019-05-28 14:47:44 -06002# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Package related functionality."""
6
Chris McDonald1672ddb2021-07-21 11:48:23 -06007import logging
8
Alex Klein076841b2019-08-29 15:19:39 -06009from chromite.api import faux
David Burger1e0fe232019-07-01 14:52:07 -060010from chromite.api import validate
Alex Kleineb77ffa2019-05-28 14:47:44 -060011from chromite.api.controller import controller_util
12from chromite.api.gen.chromite.api import binhost_pb2
Alex Klein6becabc2020-09-11 14:03:05 -060013from chromite.api.gen.chromite.api import packages_pb2
David Burger1e0fe232019-07-01 14:52:07 -060014from chromite.api.gen.chromiumos import common_pb2
Alex Kleineb77ffa2019-05-28 14:47:44 -060015from chromite.lib import constants
16from chromite.lib import cros_build_lib
Michael Mortensenbbce7e42020-05-01 15:03:49 -060017from chromite.lib import portage_util
Alex Klein6becabc2020-09-11 14:03:05 -060018from chromite.lib.parser import package_info
Chris McDonald1672ddb2021-07-21 11:48:23 -060019from chromite.lib.uprev_lib import GitRef
Alex Kleineb77ffa2019-05-28 14:47:44 -060020from chromite.service import packages
21
22
23_OVERLAY_TYPE_TO_NAME = {
24 binhost_pb2.OVERLAYTYPE_PUBLIC: constants.PUBLIC_OVERLAYS,
25 binhost_pb2.OVERLAYTYPE_PRIVATE: constants.PRIVATE_OVERLAYS,
26 binhost_pb2.OVERLAYTYPE_BOTH: constants.BOTH_OVERLAYS,
27}
28
Alex Klein1699fab2022-09-08 08:46:06 -060029
Michael Mortensen2677bf62019-10-29 08:31:25 -060030def _UprevResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060031 """Add fake paths to a successful uprev response."""
32 output_proto.modified_ebuilds.add().path = "/fake/path1"
33 output_proto.modified_ebuilds.add().path = "/fake/path2"
34
Alex Kleineb77ffa2019-05-28 14:47:44 -060035
Michael Mortensen2677bf62019-10-29 08:31:25 -060036@faux.success(_UprevResponse)
37@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -060038@validate.require("overlay_type")
39@validate.is_in("overlay_type", _OVERLAY_TYPE_TO_NAME)
Alex Klein231d2da2019-07-22 16:44:45 -060040@validate.validation_complete
41def Uprev(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060042 """Uprev all cros workon ebuilds that have changes."""
43 build_targets = controller_util.ParseBuildTargets(input_proto.build_targets)
44 overlay_type = _OVERLAY_TYPE_TO_NAME[input_proto.overlay_type]
45 chroot = controller_util.ParseChroot(input_proto.chroot)
46 output_dir = input_proto.output_dir or None
Alex Kleineb77ffa2019-05-28 14:47:44 -060047
Alex Klein1699fab2022-09-08 08:46:06 -060048 try:
49 modified_ebuilds, revved_packages = packages.uprev_build_targets(
50 build_targets, overlay_type, chroot, output_dir
51 )
52 except packages.Error as e:
53 # Handle module errors nicely, let everything else bubble up.
54 cros_build_lib.Die(e)
David Burger1e0fe232019-07-01 14:52:07 -060055
Alex Klein1699fab2022-09-08 08:46:06 -060056 for path in modified_ebuilds:
Andrew Lamb701696f2023-09-15 17:22:45 +000057 output_proto.modified_ebuilds.add().path = path
Alex Klein5dd6b1e2019-07-31 15:45:24 -060058
Alex Klein1699fab2022-09-08 08:46:06 -060059 for package in revved_packages:
60 pkg_info = package_info.parse(package)
61 pkg_proto = output_proto.packages.add()
62 controller_util.serialize_package_info(pkg_info, pkg_proto)
63
Alex Klein231d2da2019-07-22 16:44:45 -060064
Michael Mortensen2677bf62019-10-29 08:31:25 -060065def _UprevVersionedPackageResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060066 """Add fake paths to a successful uprev versioned package response."""
67 uprev_response = output_proto.responses.add()
68 uprev_response.modified_ebuilds.add().path = "/uprev/response/path"
Michael Mortensen2677bf62019-10-29 08:31:25 -060069
70
71@faux.success(_UprevVersionedPackageResponse)
72@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -060073@validate.require("versions")
74@validate.require("package_info.package_name", "package_info.category")
Alex Klein231d2da2019-07-22 16:44:45 -060075@validate.validation_complete
Alex Klein87531182019-08-12 15:23:37 -060076def UprevVersionedPackage(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -060077 """Uprev a versioned package.
Evan Hernandez38555d42019-08-05 15:11:54 -060078
Alex Klein1699fab2022-09-08 08:46:06 -060079 See go/pupr-generator for details about this endpoint.
80 """
81 chroot = controller_util.ParseChroot(input_proto.chroot)
82 build_targets = controller_util.ParseBuildTargets(input_proto.build_targets)
Alex Kleind3b84042023-05-19 14:43:59 -060083 package = controller_util.deserialize_package_info(input_proto.package_info)
Alex Klein1699fab2022-09-08 08:46:06 -060084 refs = []
85 for ref in input_proto.versions:
86 refs.append(
87 GitRef(path=ref.repository, ref=ref.ref, revision=ref.revision)
88 )
Alex Klein87531182019-08-12 15:23:37 -060089
Alex Klein1699fab2022-09-08 08:46:06 -060090 try:
91 result = packages.uprev_versioned_package(
92 package, build_targets, refs, chroot
93 )
94 except packages.Error as e:
95 # Handle module errors nicely, let everything else bubble up.
96 cros_build_lib.Die(e)
Alex Klein87531182019-08-12 15:23:37 -060097
Alex Klein1699fab2022-09-08 08:46:06 -060098 for modified in result.modified:
99 uprev_response = output_proto.responses.add()
100 uprev_response.version = modified.new_version
101 for path in modified.files:
102 uprev_response.modified_ebuilds.add().path = path
Alex Klein16ea1b32021-10-01 15:48:50 -0600103
104
105@faux.success(_UprevVersionedPackageResponse)
106@faux.empty_error
107@validate.validation_complete
108def RevBumpChrome(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600109 result = packages.revbump_chrome()
Alex Klein34afcbc2019-08-22 16:14:31 -0600110
Alex Klein1699fab2022-09-08 08:46:06 -0600111 for modified in result.modified:
112 uprev_response = output_proto.responses.add()
113 uprev_response.version = modified.new_version
114 for path in modified.files:
115 uprev_response.modified_ebuilds.add().path = path
Yaakov Shaul730814a2019-09-10 13:58:25 -0600116
Alex Klein87531182019-08-12 15:23:37 -0600117
Michael Mortensen2677bf62019-10-29 08:31:25 -0600118def _GetBestVisibleResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600119 """Add fake paths to a successful GetBestVisible response."""
120 pkg_info_msg = common_pb2.PackageInfo(
121 category="category",
122 package_name="name",
123 version="1.01",
124 )
125 output_proto.package_info.CopyFrom(pkg_info_msg)
Michael Mortensen2677bf62019-10-29 08:31:25 -0600126
127
128@faux.success(_GetBestVisibleResponse)
129@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600130@validate.require("atom")
Alex Klein231d2da2019-07-22 16:44:45 -0600131@validate.validation_complete
132def GetBestVisible(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600133 """Returns the best visible PackageInfo for the indicated atom."""
134 build_target = None
135 if input_proto.build_target.name:
136 build_target = controller_util.ParseBuildTarget(
137 input_proto.build_target
138 )
Alex Kleinbbef2b32019-08-27 10:38:50 -0600139
Alex Klein1699fab2022-09-08 08:46:06 -0600140 best = packages.get_best_visible(
141 input_proto.atom, build_target=build_target
142 )
143 controller_util.serialize_package_info(best, output_proto.package_info)
Alex Klein551e8052019-08-29 11:23:48 -0600144
145
Michael Mortensen68abdb72019-10-28 09:43:52 -0600146def _ChromeVersionResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600147 """Add a fake chrome version to a successful response."""
148 output_proto.version = "78.0.3900.0"
Michael Mortensen68abdb72019-10-28 09:43:52 -0600149
150
151@faux.success(_ChromeVersionResponse)
152@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600153@validate.require("build_target.name")
Alex Klein551e8052019-08-29 11:23:48 -0600154@validate.validation_complete
155def GetChromeVersion(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600156 """Returns the chrome version."""
157 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
Gilberto Contreras4f2d1452023-01-30 23:22:58 +0000158 chrome_version = packages.determine_package_version(
159 constants.CHROME_CP, build_target
160 )
Alex Klein1699fab2022-09-08 08:46:06 -0600161 if chrome_version:
162 output_proto.version = chrome_version
Alex Kleinda39c6d2019-09-16 14:36:36 -0600163
164
Michael Mortensen2677bf62019-10-29 08:31:25 -0600165def _GetTargetVersionsResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600166 """Add fake target version fields to a successful response."""
167 output_proto.android_version = "5812377"
168 output_proto.android_branch_version = "git_nyc-mr1-arc"
169 output_proto.android_target_version = "cheets"
170 output_proto.chrome_version = "78.0.3900.0"
171 output_proto.platform_version = "12438.0.0"
172 output_proto.milestone_version = "78"
173 output_proto.full_version = "R78-12438.0.0"
Gilberto Contreras4f2d1452023-01-30 23:22:58 +0000174 output_proto.lacros_version = "111.0.5550.0"
Michael Mortensen2677bf62019-10-29 08:31:25 -0600175
176
177@faux.success(_GetTargetVersionsResponse)
178@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600179@validate.require("build_target.name")
180@validate.require_each("packages", ["category", "package_name"])
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600181@validate.validation_complete
182def GetTargetVersions(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600183 """Returns the target versions."""
184 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
185 package_list = [
Alex Kleind3b84042023-05-19 14:43:59 -0600186 controller_util.deserialize_package_info(x)
187 for x in input_proto.packages
Alex Klein1699fab2022-09-08 08:46:06 -0600188 ]
189 target_versions = packages.get_target_versions(build_target, package_list)
Alex Klein445ae3c2020-01-08 16:40:43 -0700190
Alex Klein1699fab2022-09-08 08:46:06 -0600191 output_proto.android_version = target_versions.android_version or ""
192 output_proto.android_branch_version = target_versions.android_branch or ""
193 output_proto.android_target_version = target_versions.android_target or ""
194 output_proto.chrome_version = target_versions.chrome_version or ""
195 output_proto.platform_version = target_versions.platform_version or ""
196 output_proto.milestone_version = target_versions.milestone_version or ""
197 output_proto.full_version = target_versions.full_version or ""
Gilberto Contreras4f2d1452023-01-30 23:22:58 +0000198 output_proto.lacros_version = target_versions.lacros_version or ""
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600199
200
Michael Mortensenbfc56392020-04-30 15:23:47 -0600201def _GetBuilderMetadataResponse(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600202 """Add fake metadata fields to a successful response."""
203 # Populate only a few fields to validate faux testing.
204 build_target_metadata = output_proto.build_target_metadata.add()
205 build_target_metadata.build_target = input_proto.build_target.name
206 build_target_metadata.android_container_branch = "git_pi-arc"
207 model_metadata = output_proto.model_metadata.add()
208 model_metadata.model_name = "astronaut"
209 model_metadata.ec_firmware_version = "coral_v1.1.1234-56789f"
Michael Mortensenbfc56392020-04-30 15:23:47 -0600210
211
212@faux.success(_GetBuilderMetadataResponse)
213@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600214@validate.require("build_target.name")
Michael Mortensenbfc56392020-04-30 15:23:47 -0600215@validate.validation_complete
216def GetBuilderMetadata(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600217 """Returns the target builder metadata."""
218 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
219 build_target_metadata = output_proto.build_target_metadata.add()
220 build_target_metadata.build_target = build_target.name
221 # Android version.
222 android_version = packages.determine_android_version(build_target.name)
223 logging.info("Found android version: %s", android_version)
224 if android_version:
225 build_target_metadata.android_container_version = android_version
226 # Android branch version.
227 android_branch_version = packages.determine_android_branch(
228 build_target.name
229 )
230 logging.info("Found android branch version: %s", android_branch_version)
231 if android_branch_version:
232 build_target_metadata.android_container_branch = android_branch_version
233 # Android target version.
234 android_target_version = packages.determine_android_target(
235 build_target.name
236 )
237 logging.info("Found android target version: %s", android_target_version)
238 if android_target_version:
239 build_target_metadata.android_container_target = android_target_version
Michael Mortensenbbce7e42020-05-01 15:03:49 -0600240
Alex Klein1699fab2022-09-08 08:46:06 -0600241 build_target_metadata.arc_use_set = "arc" in portage_util.GetBoardUseFlags(
242 build_target.name
243 )
Michael Mortensenbbce7e42020-05-01 15:03:49 -0600244
Alex Klein1699fab2022-09-08 08:46:06 -0600245 fw_versions = packages.determine_firmware_versions(build_target)
246 build_target_metadata.main_firmware_version = (
247 fw_versions.main_fw_version or ""
248 )
249 build_target_metadata.ec_firmware_version = fw_versions.ec_fw_version or ""
Benjamin Shai0858cd32022-01-10 20:23:49 +0000250
Alex Klein1699fab2022-09-08 08:46:06 -0600251 build_target_metadata.kernel_version = (
252 packages.determine_kernel_version(build_target) or ""
253 )
254 fingerprints = packages.find_fingerprints(build_target)
255 build_target_metadata.fingerprints.extend(fingerprints)
Michael Mortensenbfc56392020-04-30 15:23:47 -0600256
Alex Klein1699fab2022-09-08 08:46:06 -0600257 models = packages.get_models(build_target)
258 if models:
259 all_fw_versions = packages.get_all_firmware_versions(build_target)
260 for model in models:
261 if model in all_fw_versions:
262 fw_versions = all_fw_versions[model]
263 ec = fw_versions.ec_rw or fw_versions.ec
264 main_ro = fw_versions.main
265 main_rw = fw_versions.main_rw or main_ro
266 # Get the firmware key-id for the current board and model.
267 key_id = packages.get_key_id(build_target, model)
268 model_metadata = output_proto.model_metadata.add()
269 model_metadata.model_name = model
270 model_metadata.ec_firmware_version = ec or ""
271 model_metadata.firmware_key_id = key_id
272 model_metadata.main_readonly_firmware_version = main_ro or ""
273 model_metadata.main_readwrite_firmware_version = main_rw or ""
Michael Mortensen770bc122020-05-27 17:53:30 -0600274
275
Alex Klein7d66c092020-03-23 15:13:18 -0600276def _HasPrebuiltSuccess(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600277 """The mock success case for HasChromePrebuilt."""
278 output_proto.has_prebuilt = True
Michael Mortensen68abdb72019-10-28 09:43:52 -0600279
280
Alex Klein7d66c092020-03-23 15:13:18 -0600281@faux.success(_HasPrebuiltSuccess)
Alex Kleinda39c6d2019-09-16 14:36:36 -0600282@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600283@validate.require("build_target.name")
Alex Kleinda39c6d2019-09-16 14:36:36 -0600284@validate.validation_complete
285def HasChromePrebuilt(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600286 """Checks if the most recent version of Chrome has a prebuilt."""
287 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
288 useflags = "chrome_internal" if input_proto.chrome else None
289 exists = packages.has_prebuilt(
290 constants.CHROME_CP, build_target=build_target, useflags=useflags
291 )
Alex Kleinda39c6d2019-09-16 14:36:36 -0600292
Alex Klein1699fab2022-09-08 08:46:06 -0600293 output_proto.has_prebuilt = exists
Alex Klein73fb6572019-09-30 16:55:23 -0600294
295
Alex Klein7d66c092020-03-23 15:13:18 -0600296@faux.success(_HasPrebuiltSuccess)
297@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600298@validate.require(
299 "build_target.name", "package_info.category", "package_info.package_name"
300)
Alex Klein7d66c092020-03-23 15:13:18 -0600301@validate.validation_complete
302def HasPrebuilt(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600303 """Checks if the most recent version of Chrome has a prebuilt."""
304 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
Alex Kleind3b84042023-05-19 14:43:59 -0600305 package = controller_util.deserialize_package_info(input_proto.package_info)
Alex Klein1699fab2022-09-08 08:46:06 -0600306 useflags = "chrome_internal" if input_proto.chrome else None
307 exists = packages.has_prebuilt(
Alex Kleind3b84042023-05-19 14:43:59 -0600308 package.atom, build_target=build_target, useflags=useflags
Alex Klein1699fab2022-09-08 08:46:06 -0600309 )
Alex Klein7d66c092020-03-23 15:13:18 -0600310
Alex Klein1699fab2022-09-08 08:46:06 -0600311 output_proto.has_prebuilt = exists
Alex Klein7d66c092020-03-23 15:13:18 -0600312
313
Alex Klein73fb6572019-09-30 16:55:23 -0600314def _BuildsChromeSuccess(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600315 """Mock success case for BuildsChrome."""
316 output_proto.builds_chrome = True
Alex Klein73fb6572019-09-30 16:55:23 -0600317
318
319@faux.success(_BuildsChromeSuccess)
320@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600321@validate.require("build_target.name")
322@validate.require_each("packages", ["category", "package_name"])
Alex Klein73fb6572019-09-30 16:55:23 -0600323@validate.validation_complete
324def BuildsChrome(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600325 """Check if the board builds chrome."""
326 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
Alex Kleind3b84042023-05-19 14:43:59 -0600327 pkgs = [
328 controller_util.deserialize_package_info(x)
329 for x in input_proto.packages
330 ]
331 builds_chrome = packages.builds(constants.CHROME_CP, build_target, pkgs)
Alex Klein1699fab2022-09-08 08:46:06 -0600332 output_proto.builds_chrome = builds_chrome
Alex Klein6becabc2020-09-11 14:03:05 -0600333
334
335def _NeedsChromeSourceSuccess(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600336 """Mock success case for NeedsChromeSource."""
337 output_proto.needs_chrome_source = True
338 output_proto.builds_chrome = True
Alex Klein6becabc2020-09-11 14:03:05 -0600339
Alex Klein1699fab2022-09-08 08:46:06 -0600340 output_proto.reasons.append(
341 packages_pb2.NeedsChromeSourceResponse.NO_PREBUILT
342 )
Alex Klein6becabc2020-09-11 14:03:05 -0600343 pkg_info_msg = output_proto.packages.add()
Alex Klein1699fab2022-09-08 08:46:06 -0600344 pkg_info_msg.category = constants.CHROME_CN
345 pkg_info_msg.package_name = constants.CHROME_PN
346
347 output_proto.reasons.append(
348 packages_pb2.NeedsChromeSourceResponse.FOLLOWER_LACKS_PREBUILT
349 )
350 for pkg in constants.OTHER_CHROME_PACKAGES:
351 pkg_info_msg = output_proto.packages.add()
352 pkg_info = package_info.parse(pkg)
353 controller_util.serialize_package_info(pkg_info, pkg_info_msg)
Alex Klein6becabc2020-09-11 14:03:05 -0600354
355
356@faux.success(_NeedsChromeSourceSuccess)
357@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600358@validate.require("install_request.sysroot.build_target.name")
359@validate.exists("install_request.sysroot.path")
Alex Klein6becabc2020-09-11 14:03:05 -0600360@validate.validation_complete
361def NeedsChromeSource(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600362 """Check if the build will need the chrome source."""
363 # Input parsing.
364 build_target = controller_util.ParseBuildTarget(
365 input_proto.install_request.sysroot.build_target
366 )
367 compile_source = (
368 input_proto.install_request.flags.compile_source
369 or input_proto.install_request.flags.toolchain_changed
Ryo Hashimoto5272b032023-09-29 08:22:13 +0000370 or input_proto.install_request.flags.bazel
Alex Klein1699fab2022-09-08 08:46:06 -0600371 )
372 pkgs = [
373 controller_util.deserialize_package_info(pi)
374 for pi in input_proto.install_request.packages
375 ]
376 use_flags = [f.flag for f in input_proto.install_request.use_flags]
Alex Klein6becabc2020-09-11 14:03:05 -0600377
Alex Klein1699fab2022-09-08 08:46:06 -0600378 result = packages.needs_chrome_source(
379 build_target,
380 compile_source=compile_source,
381 packages=pkgs,
382 useflags=use_flags,
383 )
Alex Klein6becabc2020-09-11 14:03:05 -0600384
Alex Klein1699fab2022-09-08 08:46:06 -0600385 # Record everything in the response.
386 output_proto.needs_chrome_source = result.needs_chrome_source
387 output_proto.builds_chrome = result.builds_chrome
Alex Klein6becabc2020-09-11 14:03:05 -0600388
Alex Klein1699fab2022-09-08 08:46:06 -0600389 # Compile source reason.
390 if compile_source:
391 output_proto.reasons.append(
392 packages_pb2.NeedsChromeSourceResponse.COMPILE_SOURCE
393 )
Alex Klein6becabc2020-09-11 14:03:05 -0600394
Alex Klein1699fab2022-09-08 08:46:06 -0600395 # Local uprev reason.
396 if result.local_uprev:
397 output_proto.reasons.append(
398 packages_pb2.NeedsChromeSourceResponse.LOCAL_UPREV
399 )
Alex Klein9ce3f682021-06-23 15:06:44 -0600400
Alex Klein1699fab2022-09-08 08:46:06 -0600401 # No chrome prebuilt reason.
402 if result.missing_chrome_prebuilt:
403 output_proto.reasons.append(
404 packages_pb2.NeedsChromeSourceResponse.NO_PREBUILT
405 )
Alex Klein6becabc2020-09-11 14:03:05 -0600406
Alex Klein1699fab2022-09-08 08:46:06 -0600407 # Follower package(s) lack prebuilt reason.
408 if result.missing_follower_prebuilt:
409 output_proto.reasons.append(
410 packages_pb2.NeedsChromeSourceResponse.FOLLOWER_LACKS_PREBUILT
411 )
Alex Klein6becabc2020-09-11 14:03:05 -0600412
Alex Klein1699fab2022-09-08 08:46:06 -0600413 for pkg in result.packages:
414 pkg_info = output_proto.packages.add()
415 controller_util.serialize_package_info(pkg, pkg_info)
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900416
417
418def _GetAndroidMetadataResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600419 """Mock Android metadata on successful run."""
420 output_proto.android_package = "android-vm-rvc"
421 output_proto.android_branch = "git_rvc-arc"
422 output_proto.android_version = "7123456"
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900423
424
425@faux.success(_GetAndroidMetadataResponse)
426@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600427@validate.require("build_target.name")
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900428@validate.validation_complete
429def GetAndroidMetadata(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600430 """Returns Android-related metadata."""
431 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
432 # This returns a full CPVR string, e.g.
433 # 'chromeos-base/android-vm-rvc-7336577-r1'
434 android_full_package = packages.determine_android_package(build_target.name)
435 if android_full_package:
436 logging.info("Found Android package: %s", android_full_package)
437 info = package_info.parse(android_full_package)
438 output_proto.android_package = info.package
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900439
Alex Klein1699fab2022-09-08 08:46:06 -0600440 android_branch = packages.determine_android_branch(
441 build_target.name, package=android_full_package
442 )
443 logging.info("Found Android branch: %s", android_branch)
444 output_proto.android_branch = android_branch
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900445
Alex Klein1699fab2022-09-08 08:46:06 -0600446 android_version = packages.determine_android_version(
447 build_target.name, package=android_full_package
448 )
449 logging.info("Found Android version: %s", android_version)
450 output_proto.android_version = android_version