blob: feafe40d7e46200d2184107f58d97a4913a9e1e4 [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:
57 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)
83 package = controller_util.PackageInfoToCPV(input_proto.package_info)
84 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 = [
186 controller_util.PackageInfoToCPV(x) for x in input_proto.packages or []
187 ]
188 target_versions = packages.get_target_versions(build_target, package_list)
Alex Klein445ae3c2020-01-08 16:40:43 -0700189
Alex Klein1699fab2022-09-08 08:46:06 -0600190 output_proto.android_version = target_versions.android_version or ""
191 output_proto.android_branch_version = target_versions.android_branch or ""
192 output_proto.android_target_version = target_versions.android_target or ""
193 output_proto.chrome_version = target_versions.chrome_version or ""
194 output_proto.platform_version = target_versions.platform_version or ""
195 output_proto.milestone_version = target_versions.milestone_version or ""
196 output_proto.full_version = target_versions.full_version or ""
Gilberto Contreras4f2d1452023-01-30 23:22:58 +0000197 output_proto.lacros_version = target_versions.lacros_version or ""
Michael Mortensenb70e8a82019-10-10 18:43:41 -0600198
199
Michael Mortensenbfc56392020-04-30 15:23:47 -0600200def _GetBuilderMetadataResponse(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600201 """Add fake metadata fields to a successful response."""
202 # Populate only a few fields to validate faux testing.
203 build_target_metadata = output_proto.build_target_metadata.add()
204 build_target_metadata.build_target = input_proto.build_target.name
205 build_target_metadata.android_container_branch = "git_pi-arc"
206 model_metadata = output_proto.model_metadata.add()
207 model_metadata.model_name = "astronaut"
208 model_metadata.ec_firmware_version = "coral_v1.1.1234-56789f"
Michael Mortensenbfc56392020-04-30 15:23:47 -0600209
210
211@faux.success(_GetBuilderMetadataResponse)
212@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600213@validate.require("build_target.name")
Michael Mortensenbfc56392020-04-30 15:23:47 -0600214@validate.validation_complete
215def GetBuilderMetadata(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600216 """Returns the target builder metadata."""
217 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
218 build_target_metadata = output_proto.build_target_metadata.add()
219 build_target_metadata.build_target = build_target.name
220 # Android version.
221 android_version = packages.determine_android_version(build_target.name)
222 logging.info("Found android version: %s", android_version)
223 if android_version:
224 build_target_metadata.android_container_version = android_version
225 # Android branch version.
226 android_branch_version = packages.determine_android_branch(
227 build_target.name
228 )
229 logging.info("Found android branch version: %s", android_branch_version)
230 if android_branch_version:
231 build_target_metadata.android_container_branch = android_branch_version
232 # Android target version.
233 android_target_version = packages.determine_android_target(
234 build_target.name
235 )
236 logging.info("Found android target version: %s", android_target_version)
237 if android_target_version:
238 build_target_metadata.android_container_target = android_target_version
Michael Mortensenbbce7e42020-05-01 15:03:49 -0600239
Alex Klein1699fab2022-09-08 08:46:06 -0600240 build_target_metadata.arc_use_set = "arc" in portage_util.GetBoardUseFlags(
241 build_target.name
242 )
Michael Mortensenbbce7e42020-05-01 15:03:49 -0600243
Alex Klein1699fab2022-09-08 08:46:06 -0600244 fw_versions = packages.determine_firmware_versions(build_target)
245 build_target_metadata.main_firmware_version = (
246 fw_versions.main_fw_version or ""
247 )
248 build_target_metadata.ec_firmware_version = fw_versions.ec_fw_version or ""
Benjamin Shai0858cd32022-01-10 20:23:49 +0000249
Alex Klein1699fab2022-09-08 08:46:06 -0600250 build_target_metadata.kernel_version = (
251 packages.determine_kernel_version(build_target) or ""
252 )
253 fingerprints = packages.find_fingerprints(build_target)
254 build_target_metadata.fingerprints.extend(fingerprints)
Michael Mortensenbfc56392020-04-30 15:23:47 -0600255
Alex Klein1699fab2022-09-08 08:46:06 -0600256 models = packages.get_models(build_target)
257 if models:
258 all_fw_versions = packages.get_all_firmware_versions(build_target)
259 for model in models:
260 if model in all_fw_versions:
261 fw_versions = all_fw_versions[model]
262 ec = fw_versions.ec_rw or fw_versions.ec
263 main_ro = fw_versions.main
264 main_rw = fw_versions.main_rw or main_ro
265 # Get the firmware key-id for the current board and model.
266 key_id = packages.get_key_id(build_target, model)
267 model_metadata = output_proto.model_metadata.add()
268 model_metadata.model_name = model
269 model_metadata.ec_firmware_version = ec or ""
270 model_metadata.firmware_key_id = key_id
271 model_metadata.main_readonly_firmware_version = main_ro or ""
272 model_metadata.main_readwrite_firmware_version = main_rw or ""
Michael Mortensen770bc122020-05-27 17:53:30 -0600273
274
Alex Klein7d66c092020-03-23 15:13:18 -0600275def _HasPrebuiltSuccess(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600276 """The mock success case for HasChromePrebuilt."""
277 output_proto.has_prebuilt = True
Michael Mortensen68abdb72019-10-28 09:43:52 -0600278
279
Alex Klein7d66c092020-03-23 15:13:18 -0600280@faux.success(_HasPrebuiltSuccess)
Alex Kleinda39c6d2019-09-16 14:36:36 -0600281@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600282@validate.require("build_target.name")
Alex Kleinda39c6d2019-09-16 14:36:36 -0600283@validate.validation_complete
284def HasChromePrebuilt(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600285 """Checks if the most recent version of Chrome has a prebuilt."""
286 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
287 useflags = "chrome_internal" if input_proto.chrome else None
288 exists = packages.has_prebuilt(
289 constants.CHROME_CP, build_target=build_target, useflags=useflags
290 )
Alex Kleinda39c6d2019-09-16 14:36:36 -0600291
Alex Klein1699fab2022-09-08 08:46:06 -0600292 output_proto.has_prebuilt = exists
Alex Klein73fb6572019-09-30 16:55:23 -0600293
294
Alex Klein7d66c092020-03-23 15:13:18 -0600295@faux.success(_HasPrebuiltSuccess)
296@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600297@validate.require(
298 "build_target.name", "package_info.category", "package_info.package_name"
299)
Alex Klein7d66c092020-03-23 15:13:18 -0600300@validate.validation_complete
301def HasPrebuilt(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600302 """Checks if the most recent version of Chrome has a prebuilt."""
303 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
304 package = controller_util.PackageInfoToCPV(input_proto.package_info).cp
305 useflags = "chrome_internal" if input_proto.chrome else None
306 exists = packages.has_prebuilt(
307 package, build_target=build_target, useflags=useflags
308 )
Alex Klein7d66c092020-03-23 15:13:18 -0600309
Alex Klein1699fab2022-09-08 08:46:06 -0600310 output_proto.has_prebuilt = exists
Alex Klein7d66c092020-03-23 15:13:18 -0600311
312
Alex Klein73fb6572019-09-30 16:55:23 -0600313def _BuildsChromeSuccess(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600314 """Mock success case for BuildsChrome."""
315 output_proto.builds_chrome = True
Alex Klein73fb6572019-09-30 16:55:23 -0600316
317
318@faux.success(_BuildsChromeSuccess)
319@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600320@validate.require("build_target.name")
321@validate.require_each("packages", ["category", "package_name"])
Alex Klein73fb6572019-09-30 16:55:23 -0600322@validate.validation_complete
323def BuildsChrome(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600324 """Check if the board builds chrome."""
325 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
326 cpvs = [controller_util.PackageInfoToCPV(pi) for pi in input_proto.packages]
327 builds_chrome = packages.builds(constants.CHROME_CP, build_target, cpvs)
328 output_proto.builds_chrome = builds_chrome
Alex Klein6becabc2020-09-11 14:03:05 -0600329
330
331def _NeedsChromeSourceSuccess(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600332 """Mock success case for NeedsChromeSource."""
333 output_proto.needs_chrome_source = True
334 output_proto.builds_chrome = True
Alex Klein6becabc2020-09-11 14:03:05 -0600335
Alex Klein1699fab2022-09-08 08:46:06 -0600336 output_proto.reasons.append(
337 packages_pb2.NeedsChromeSourceResponse.NO_PREBUILT
338 )
Alex Klein6becabc2020-09-11 14:03:05 -0600339 pkg_info_msg = output_proto.packages.add()
Alex Klein1699fab2022-09-08 08:46:06 -0600340 pkg_info_msg.category = constants.CHROME_CN
341 pkg_info_msg.package_name = constants.CHROME_PN
342
343 output_proto.reasons.append(
344 packages_pb2.NeedsChromeSourceResponse.FOLLOWER_LACKS_PREBUILT
345 )
346 for pkg in constants.OTHER_CHROME_PACKAGES:
347 pkg_info_msg = output_proto.packages.add()
348 pkg_info = package_info.parse(pkg)
349 controller_util.serialize_package_info(pkg_info, pkg_info_msg)
Alex Klein6becabc2020-09-11 14:03:05 -0600350
351
352@faux.success(_NeedsChromeSourceSuccess)
353@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600354@validate.require("install_request.sysroot.build_target.name")
355@validate.exists("install_request.sysroot.path")
Alex Klein6becabc2020-09-11 14:03:05 -0600356@validate.validation_complete
357def NeedsChromeSource(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600358 """Check if the build will need the chrome source."""
359 # Input parsing.
360 build_target = controller_util.ParseBuildTarget(
361 input_proto.install_request.sysroot.build_target
362 )
363 compile_source = (
364 input_proto.install_request.flags.compile_source
365 or input_proto.install_request.flags.toolchain_changed
366 )
367 pkgs = [
368 controller_util.deserialize_package_info(pi)
369 for pi in input_proto.install_request.packages
370 ]
371 use_flags = [f.flag for f in input_proto.install_request.use_flags]
Alex Klein6becabc2020-09-11 14:03:05 -0600372
Alex Klein1699fab2022-09-08 08:46:06 -0600373 result = packages.needs_chrome_source(
374 build_target,
375 compile_source=compile_source,
376 packages=pkgs,
377 useflags=use_flags,
378 )
Alex Klein6becabc2020-09-11 14:03:05 -0600379
Alex Klein1699fab2022-09-08 08:46:06 -0600380 # Record everything in the response.
381 output_proto.needs_chrome_source = result.needs_chrome_source
382 output_proto.builds_chrome = result.builds_chrome
Alex Klein6becabc2020-09-11 14:03:05 -0600383
Alex Klein1699fab2022-09-08 08:46:06 -0600384 # Compile source reason.
385 if compile_source:
386 output_proto.reasons.append(
387 packages_pb2.NeedsChromeSourceResponse.COMPILE_SOURCE
388 )
Alex Klein6becabc2020-09-11 14:03:05 -0600389
Alex Klein1699fab2022-09-08 08:46:06 -0600390 # Local uprev reason.
391 if result.local_uprev:
392 output_proto.reasons.append(
393 packages_pb2.NeedsChromeSourceResponse.LOCAL_UPREV
394 )
Alex Klein9ce3f682021-06-23 15:06:44 -0600395
Alex Klein1699fab2022-09-08 08:46:06 -0600396 # No chrome prebuilt reason.
397 if result.missing_chrome_prebuilt:
398 output_proto.reasons.append(
399 packages_pb2.NeedsChromeSourceResponse.NO_PREBUILT
400 )
Alex Klein6becabc2020-09-11 14:03:05 -0600401
Alex Klein1699fab2022-09-08 08:46:06 -0600402 # Follower package(s) lack prebuilt reason.
403 if result.missing_follower_prebuilt:
404 output_proto.reasons.append(
405 packages_pb2.NeedsChromeSourceResponse.FOLLOWER_LACKS_PREBUILT
406 )
Alex Klein6becabc2020-09-11 14:03:05 -0600407
Alex Klein1699fab2022-09-08 08:46:06 -0600408 for pkg in result.packages:
409 pkg_info = output_proto.packages.add()
410 controller_util.serialize_package_info(pkg, pkg_info)
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900411
412
413def _GetAndroidMetadataResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600414 """Mock Android metadata on successful run."""
415 output_proto.android_package = "android-vm-rvc"
416 output_proto.android_branch = "git_rvc-arc"
417 output_proto.android_version = "7123456"
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900418
419
420@faux.success(_GetAndroidMetadataResponse)
421@faux.empty_error
Alex Klein1699fab2022-09-08 08:46:06 -0600422@validate.require("build_target.name")
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900423@validate.validation_complete
424def GetAndroidMetadata(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600425 """Returns Android-related metadata."""
426 build_target = controller_util.ParseBuildTarget(input_proto.build_target)
427 # This returns a full CPVR string, e.g.
428 # 'chromeos-base/android-vm-rvc-7336577-r1'
429 android_full_package = packages.determine_android_package(build_target.name)
430 if android_full_package:
431 logging.info("Found Android package: %s", android_full_package)
432 info = package_info.parse(android_full_package)
433 output_proto.android_package = info.package
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900434
Alex Klein1699fab2022-09-08 08:46:06 -0600435 android_branch = packages.determine_android_branch(
436 build_target.name, package=android_full_package
437 )
438 logging.info("Found Android branch: %s", android_branch)
439 output_proto.android_branch = android_branch
Shao-Chuan Leeeb834a32021-05-12 17:10:55 +0900440
Alex Klein1699fab2022-09-08 08:46:06 -0600441 android_version = packages.determine_android_version(
442 build_target.name, package=android_full_package
443 )
444 logging.info("Found Android version: %s", android_version)
445 output_proto.android_version = android_version