Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2019 The ChromiumOS Authors |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 2 | # 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 McDonald | 1672ddb | 2021-07-21 11:48:23 -0600 | [diff] [blame] | 7 | import logging |
| 8 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 9 | from chromite.api import faux |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 10 | from chromite.api import validate |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 11 | from chromite.api.controller import controller_util |
| 12 | from chromite.api.gen.chromite.api import binhost_pb2 |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 13 | from chromite.api.gen.chromite.api import packages_pb2 |
David Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 14 | from chromite.api.gen.chromiumos import common_pb2 |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 15 | from chromite.lib import constants |
| 16 | from chromite.lib import cros_build_lib |
Michael Mortensen | bbce7e4 | 2020-05-01 15:03:49 -0600 | [diff] [blame] | 17 | from chromite.lib import portage_util |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 18 | from chromite.lib.parser import package_info |
Chris McDonald | 1672ddb | 2021-07-21 11:48:23 -0600 | [diff] [blame] | 19 | from chromite.lib.uprev_lib import GitRef |
Alex Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 20 | from 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 Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 29 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 30 | def _UprevResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 31 | """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 Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 35 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 36 | @faux.success(_UprevResponse) |
| 37 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 38 | @validate.require("overlay_type") |
| 39 | @validate.is_in("overlay_type", _OVERLAY_TYPE_TO_NAME) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 40 | @validate.validation_complete |
| 41 | def Uprev(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 42 | """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 Klein | eb77ffa | 2019-05-28 14:47:44 -0600 | [diff] [blame] | 47 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 48 | 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 Burger | 1e0fe23 | 2019-07-01 14:52:07 -0600 | [diff] [blame] | 55 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 56 | for path in modified_ebuilds: |
| 57 | output_proto.modified_ebuilds.add().path = path |
Alex Klein | 5dd6b1e | 2019-07-31 15:45:24 -0600 | [diff] [blame] | 58 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 59 | 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 Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 64 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 65 | def _UprevVersionedPackageResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 66 | """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 Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 69 | |
| 70 | |
| 71 | @faux.success(_UprevVersionedPackageResponse) |
| 72 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 73 | @validate.require("versions") |
| 74 | @validate.require("package_info.package_name", "package_info.category") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 75 | @validate.validation_complete |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 76 | def UprevVersionedPackage(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 77 | """Uprev a versioned package. |
Evan Hernandez | 38555d4 | 2019-08-05 15:11:54 -0600 | [diff] [blame] | 78 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 79 | 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 Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 89 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 90 | 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 Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 97 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 98 | 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 Klein | 16ea1b3 | 2021-10-01 15:48:50 -0600 | [diff] [blame] | 103 | |
| 104 | |
| 105 | @faux.success(_UprevVersionedPackageResponse) |
| 106 | @faux.empty_error |
| 107 | @validate.validation_complete |
| 108 | def RevBumpChrome(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 109 | result = packages.revbump_chrome() |
Alex Klein | 34afcbc | 2019-08-22 16:14:31 -0600 | [diff] [blame] | 110 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 111 | 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 Shaul | 730814a | 2019-09-10 13:58:25 -0600 | [diff] [blame] | 116 | |
Alex Klein | 8753118 | 2019-08-12 15:23:37 -0600 | [diff] [blame] | 117 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 118 | def _GetBestVisibleResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 119 | """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 Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 126 | |
| 127 | |
| 128 | @faux.success(_GetBestVisibleResponse) |
| 129 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 130 | @validate.require("atom") |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 131 | @validate.validation_complete |
| 132 | def GetBestVisible(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 133 | """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 Klein | bbef2b3 | 2019-08-27 10:38:50 -0600 | [diff] [blame] | 139 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 140 | 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 Klein | 551e805 | 2019-08-29 11:23:48 -0600 | [diff] [blame] | 144 | |
| 145 | |
Michael Mortensen | 68abdb7 | 2019-10-28 09:43:52 -0600 | [diff] [blame] | 146 | def _ChromeVersionResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 147 | """Add a fake chrome version to a successful response.""" |
| 148 | output_proto.version = "78.0.3900.0" |
Michael Mortensen | 68abdb7 | 2019-10-28 09:43:52 -0600 | [diff] [blame] | 149 | |
| 150 | |
| 151 | @faux.success(_ChromeVersionResponse) |
| 152 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 153 | @validate.require("build_target.name") |
Alex Klein | 551e805 | 2019-08-29 11:23:48 -0600 | [diff] [blame] | 154 | @validate.validation_complete |
| 155 | def GetChromeVersion(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 156 | """Returns the chrome version.""" |
| 157 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 158 | chrome_version = packages.determine_chrome_version(build_target) |
| 159 | if chrome_version: |
| 160 | output_proto.version = chrome_version |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 161 | |
| 162 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 163 | def _GetTargetVersionsResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 164 | """Add fake target version fields to a successful response.""" |
| 165 | output_proto.android_version = "5812377" |
| 166 | output_proto.android_branch_version = "git_nyc-mr1-arc" |
| 167 | output_proto.android_target_version = "cheets" |
| 168 | output_proto.chrome_version = "78.0.3900.0" |
| 169 | output_proto.platform_version = "12438.0.0" |
| 170 | output_proto.milestone_version = "78" |
| 171 | output_proto.full_version = "R78-12438.0.0" |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 172 | |
| 173 | |
| 174 | @faux.success(_GetTargetVersionsResponse) |
| 175 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 176 | @validate.require("build_target.name") |
| 177 | @validate.require_each("packages", ["category", "package_name"]) |
Michael Mortensen | b70e8a8 | 2019-10-10 18:43:41 -0600 | [diff] [blame] | 178 | @validate.validation_complete |
| 179 | def GetTargetVersions(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 180 | """Returns the target versions.""" |
| 181 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 182 | package_list = [ |
| 183 | controller_util.PackageInfoToCPV(x) for x in input_proto.packages or [] |
| 184 | ] |
| 185 | target_versions = packages.get_target_versions(build_target, package_list) |
Alex Klein | 445ae3c | 2020-01-08 16:40:43 -0700 | [diff] [blame] | 186 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 187 | output_proto.android_version = target_versions.android_version or "" |
| 188 | output_proto.android_branch_version = target_versions.android_branch or "" |
| 189 | output_proto.android_target_version = target_versions.android_target or "" |
| 190 | output_proto.chrome_version = target_versions.chrome_version or "" |
| 191 | output_proto.platform_version = target_versions.platform_version or "" |
| 192 | output_proto.milestone_version = target_versions.milestone_version or "" |
| 193 | output_proto.full_version = target_versions.full_version or "" |
Michael Mortensen | b70e8a8 | 2019-10-10 18:43:41 -0600 | [diff] [blame] | 194 | |
| 195 | |
Michael Mortensen | bfc5639 | 2020-04-30 15:23:47 -0600 | [diff] [blame] | 196 | def _GetBuilderMetadataResponse(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 197 | """Add fake metadata fields to a successful response.""" |
| 198 | # Populate only a few fields to validate faux testing. |
| 199 | build_target_metadata = output_proto.build_target_metadata.add() |
| 200 | build_target_metadata.build_target = input_proto.build_target.name |
| 201 | build_target_metadata.android_container_branch = "git_pi-arc" |
| 202 | model_metadata = output_proto.model_metadata.add() |
| 203 | model_metadata.model_name = "astronaut" |
| 204 | model_metadata.ec_firmware_version = "coral_v1.1.1234-56789f" |
Michael Mortensen | bfc5639 | 2020-04-30 15:23:47 -0600 | [diff] [blame] | 205 | |
| 206 | |
| 207 | @faux.success(_GetBuilderMetadataResponse) |
| 208 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 209 | @validate.require("build_target.name") |
Michael Mortensen | bfc5639 | 2020-04-30 15:23:47 -0600 | [diff] [blame] | 210 | @validate.validation_complete |
| 211 | def GetBuilderMetadata(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 212 | """Returns the target builder metadata.""" |
| 213 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 214 | build_target_metadata = output_proto.build_target_metadata.add() |
| 215 | build_target_metadata.build_target = build_target.name |
| 216 | # Android version. |
| 217 | android_version = packages.determine_android_version(build_target.name) |
| 218 | logging.info("Found android version: %s", android_version) |
| 219 | if android_version: |
| 220 | build_target_metadata.android_container_version = android_version |
| 221 | # Android branch version. |
| 222 | android_branch_version = packages.determine_android_branch( |
| 223 | build_target.name |
| 224 | ) |
| 225 | logging.info("Found android branch version: %s", android_branch_version) |
| 226 | if android_branch_version: |
| 227 | build_target_metadata.android_container_branch = android_branch_version |
| 228 | # Android target version. |
| 229 | android_target_version = packages.determine_android_target( |
| 230 | build_target.name |
| 231 | ) |
| 232 | logging.info("Found android target version: %s", android_target_version) |
| 233 | if android_target_version: |
| 234 | build_target_metadata.android_container_target = android_target_version |
Michael Mortensen | bbce7e4 | 2020-05-01 15:03:49 -0600 | [diff] [blame] | 235 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 236 | build_target_metadata.arc_use_set = "arc" in portage_util.GetBoardUseFlags( |
| 237 | build_target.name |
| 238 | ) |
Michael Mortensen | bbce7e4 | 2020-05-01 15:03:49 -0600 | [diff] [blame] | 239 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 240 | fw_versions = packages.determine_firmware_versions(build_target) |
| 241 | build_target_metadata.main_firmware_version = ( |
| 242 | fw_versions.main_fw_version or "" |
| 243 | ) |
| 244 | build_target_metadata.ec_firmware_version = fw_versions.ec_fw_version or "" |
Benjamin Shai | 0858cd3 | 2022-01-10 20:23:49 +0000 | [diff] [blame] | 245 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 246 | build_target_metadata.kernel_version = ( |
| 247 | packages.determine_kernel_version(build_target) or "" |
| 248 | ) |
| 249 | fingerprints = packages.find_fingerprints(build_target) |
| 250 | build_target_metadata.fingerprints.extend(fingerprints) |
Michael Mortensen | bfc5639 | 2020-04-30 15:23:47 -0600 | [diff] [blame] | 251 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 252 | models = packages.get_models(build_target) |
| 253 | if models: |
| 254 | all_fw_versions = packages.get_all_firmware_versions(build_target) |
| 255 | for model in models: |
| 256 | if model in all_fw_versions: |
| 257 | fw_versions = all_fw_versions[model] |
| 258 | ec = fw_versions.ec_rw or fw_versions.ec |
| 259 | main_ro = fw_versions.main |
| 260 | main_rw = fw_versions.main_rw or main_ro |
| 261 | # Get the firmware key-id for the current board and model. |
| 262 | key_id = packages.get_key_id(build_target, model) |
| 263 | model_metadata = output_proto.model_metadata.add() |
| 264 | model_metadata.model_name = model |
| 265 | model_metadata.ec_firmware_version = ec or "" |
| 266 | model_metadata.firmware_key_id = key_id |
| 267 | model_metadata.main_readonly_firmware_version = main_ro or "" |
| 268 | model_metadata.main_readwrite_firmware_version = main_rw or "" |
Michael Mortensen | 770bc12 | 2020-05-27 17:53:30 -0600 | [diff] [blame] | 269 | |
| 270 | |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 271 | def _HasPrebuiltSuccess(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 272 | """The mock success case for HasChromePrebuilt.""" |
| 273 | output_proto.has_prebuilt = True |
Michael Mortensen | 68abdb7 | 2019-10-28 09:43:52 -0600 | [diff] [blame] | 274 | |
| 275 | |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 276 | @faux.success(_HasPrebuiltSuccess) |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 277 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 278 | @validate.require("build_target.name") |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 279 | @validate.validation_complete |
| 280 | def HasChromePrebuilt(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 281 | """Checks if the most recent version of Chrome has a prebuilt.""" |
| 282 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 283 | useflags = "chrome_internal" if input_proto.chrome else None |
| 284 | exists = packages.has_prebuilt( |
| 285 | constants.CHROME_CP, build_target=build_target, useflags=useflags |
| 286 | ) |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 287 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 288 | output_proto.has_prebuilt = exists |
Alex Klein | 73fb657 | 2019-09-30 16:55:23 -0600 | [diff] [blame] | 289 | |
| 290 | |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 291 | @faux.success(_HasPrebuiltSuccess) |
| 292 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 293 | @validate.require( |
| 294 | "build_target.name", "package_info.category", "package_info.package_name" |
| 295 | ) |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 296 | @validate.validation_complete |
| 297 | def HasPrebuilt(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 298 | """Checks if the most recent version of Chrome has a prebuilt.""" |
| 299 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 300 | package = controller_util.PackageInfoToCPV(input_proto.package_info).cp |
| 301 | useflags = "chrome_internal" if input_proto.chrome else None |
| 302 | exists = packages.has_prebuilt( |
| 303 | package, build_target=build_target, useflags=useflags |
| 304 | ) |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 305 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 306 | output_proto.has_prebuilt = exists |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 307 | |
| 308 | |
Alex Klein | 73fb657 | 2019-09-30 16:55:23 -0600 | [diff] [blame] | 309 | def _BuildsChromeSuccess(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 310 | """Mock success case for BuildsChrome.""" |
| 311 | output_proto.builds_chrome = True |
Alex Klein | 73fb657 | 2019-09-30 16:55:23 -0600 | [diff] [blame] | 312 | |
| 313 | |
| 314 | @faux.success(_BuildsChromeSuccess) |
| 315 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 316 | @validate.require("build_target.name") |
| 317 | @validate.require_each("packages", ["category", "package_name"]) |
Alex Klein | 73fb657 | 2019-09-30 16:55:23 -0600 | [diff] [blame] | 318 | @validate.validation_complete |
| 319 | def BuildsChrome(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 320 | """Check if the board builds chrome.""" |
| 321 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 322 | cpvs = [controller_util.PackageInfoToCPV(pi) for pi in input_proto.packages] |
| 323 | builds_chrome = packages.builds(constants.CHROME_CP, build_target, cpvs) |
| 324 | output_proto.builds_chrome = builds_chrome |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 325 | |
| 326 | |
| 327 | def _NeedsChromeSourceSuccess(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 328 | """Mock success case for NeedsChromeSource.""" |
| 329 | output_proto.needs_chrome_source = True |
| 330 | output_proto.builds_chrome = True |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 331 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 332 | output_proto.reasons.append( |
| 333 | packages_pb2.NeedsChromeSourceResponse.NO_PREBUILT |
| 334 | ) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 335 | pkg_info_msg = output_proto.packages.add() |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 336 | pkg_info_msg.category = constants.CHROME_CN |
| 337 | pkg_info_msg.package_name = constants.CHROME_PN |
| 338 | |
| 339 | output_proto.reasons.append( |
| 340 | packages_pb2.NeedsChromeSourceResponse.FOLLOWER_LACKS_PREBUILT |
| 341 | ) |
| 342 | for pkg in constants.OTHER_CHROME_PACKAGES: |
| 343 | pkg_info_msg = output_proto.packages.add() |
| 344 | pkg_info = package_info.parse(pkg) |
| 345 | controller_util.serialize_package_info(pkg_info, pkg_info_msg) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 346 | |
| 347 | |
| 348 | @faux.success(_NeedsChromeSourceSuccess) |
| 349 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 350 | @validate.require("install_request.sysroot.build_target.name") |
| 351 | @validate.exists("install_request.sysroot.path") |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 352 | @validate.validation_complete |
| 353 | def NeedsChromeSource(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 354 | """Check if the build will need the chrome source.""" |
| 355 | # Input parsing. |
| 356 | build_target = controller_util.ParseBuildTarget( |
| 357 | input_proto.install_request.sysroot.build_target |
| 358 | ) |
| 359 | compile_source = ( |
| 360 | input_proto.install_request.flags.compile_source |
| 361 | or input_proto.install_request.flags.toolchain_changed |
| 362 | ) |
| 363 | pkgs = [ |
| 364 | controller_util.deserialize_package_info(pi) |
| 365 | for pi in input_proto.install_request.packages |
| 366 | ] |
| 367 | use_flags = [f.flag for f in input_proto.install_request.use_flags] |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 368 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 369 | result = packages.needs_chrome_source( |
| 370 | build_target, |
| 371 | compile_source=compile_source, |
| 372 | packages=pkgs, |
| 373 | useflags=use_flags, |
| 374 | ) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 375 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 376 | # Record everything in the response. |
| 377 | output_proto.needs_chrome_source = result.needs_chrome_source |
| 378 | output_proto.builds_chrome = result.builds_chrome |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 379 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 380 | # Compile source reason. |
| 381 | if compile_source: |
| 382 | output_proto.reasons.append( |
| 383 | packages_pb2.NeedsChromeSourceResponse.COMPILE_SOURCE |
| 384 | ) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 385 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 386 | # Local uprev reason. |
| 387 | if result.local_uprev: |
| 388 | output_proto.reasons.append( |
| 389 | packages_pb2.NeedsChromeSourceResponse.LOCAL_UPREV |
| 390 | ) |
Alex Klein | 9ce3f68 | 2021-06-23 15:06:44 -0600 | [diff] [blame] | 391 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 392 | # No chrome prebuilt reason. |
| 393 | if result.missing_chrome_prebuilt: |
| 394 | output_proto.reasons.append( |
| 395 | packages_pb2.NeedsChromeSourceResponse.NO_PREBUILT |
| 396 | ) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 397 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 398 | # Follower package(s) lack prebuilt reason. |
| 399 | if result.missing_follower_prebuilt: |
| 400 | output_proto.reasons.append( |
| 401 | packages_pb2.NeedsChromeSourceResponse.FOLLOWER_LACKS_PREBUILT |
| 402 | ) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 403 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 404 | for pkg in result.packages: |
| 405 | pkg_info = output_proto.packages.add() |
| 406 | controller_util.serialize_package_info(pkg, pkg_info) |
Shao-Chuan Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 407 | |
| 408 | |
| 409 | def _GetAndroidMetadataResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 410 | """Mock Android metadata on successful run.""" |
| 411 | output_proto.android_package = "android-vm-rvc" |
| 412 | output_proto.android_branch = "git_rvc-arc" |
| 413 | output_proto.android_version = "7123456" |
Shao-Chuan Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 414 | |
| 415 | |
| 416 | @faux.success(_GetAndroidMetadataResponse) |
| 417 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 418 | @validate.require("build_target.name") |
Shao-Chuan Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 419 | @validate.validation_complete |
| 420 | def GetAndroidMetadata(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 421 | """Returns Android-related metadata.""" |
| 422 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 423 | # This returns a full CPVR string, e.g. |
| 424 | # 'chromeos-base/android-vm-rvc-7336577-r1' |
| 425 | android_full_package = packages.determine_android_package(build_target.name) |
| 426 | if android_full_package: |
| 427 | logging.info("Found Android package: %s", android_full_package) |
| 428 | info = package_info.parse(android_full_package) |
| 429 | output_proto.android_package = info.package |
Shao-Chuan Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 430 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 431 | android_branch = packages.determine_android_branch( |
| 432 | build_target.name, package=android_full_package |
| 433 | ) |
| 434 | logging.info("Found Android branch: %s", android_branch) |
| 435 | output_proto.android_branch = android_branch |
Shao-Chuan Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 436 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 437 | android_version = packages.determine_android_version( |
| 438 | build_target.name, package=android_full_package |
| 439 | ) |
| 440 | logging.info("Found Android version: %s", android_version) |
| 441 | output_proto.android_version = android_version |