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: |
Andrew Lamb | 701696f | 2023-09-15 17:22:45 +0000 | [diff] [blame] | 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) |
Alex Klein | d3b8404 | 2023-05-19 14:43:59 -0600 | [diff] [blame] | 83 | package = controller_util.deserialize_package_info(input_proto.package_info) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 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) |
Gilberto Contreras | 4f2d145 | 2023-01-30 23:22:58 +0000 | [diff] [blame] | 158 | chrome_version = packages.determine_package_version( |
| 159 | constants.CHROME_CP, build_target |
| 160 | ) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 161 | if chrome_version: |
| 162 | output_proto.version = chrome_version |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 163 | |
| 164 | |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 165 | def _GetTargetVersionsResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 166 | """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 Contreras | 4f2d145 | 2023-01-30 23:22:58 +0000 | [diff] [blame] | 174 | output_proto.lacros_version = "111.0.5550.0" |
Michael Mortensen | 2677bf6 | 2019-10-29 08:31:25 -0600 | [diff] [blame] | 175 | |
| 176 | |
| 177 | @faux.success(_GetTargetVersionsResponse) |
| 178 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 179 | @validate.require("build_target.name") |
| 180 | @validate.require_each("packages", ["category", "package_name"]) |
Michael Mortensen | b70e8a8 | 2019-10-10 18:43:41 -0600 | [diff] [blame] | 181 | @validate.validation_complete |
| 182 | def GetTargetVersions(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 183 | """Returns the target versions.""" |
| 184 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 185 | package_list = [ |
Alex Klein | d3b8404 | 2023-05-19 14:43:59 -0600 | [diff] [blame] | 186 | controller_util.deserialize_package_info(x) |
| 187 | for x in input_proto.packages |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 188 | ] |
| 189 | target_versions = packages.get_target_versions(build_target, package_list) |
Alex Klein | 445ae3c | 2020-01-08 16:40:43 -0700 | [diff] [blame] | 190 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 191 | 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 Contreras | 4f2d145 | 2023-01-30 23:22:58 +0000 | [diff] [blame] | 198 | output_proto.lacros_version = target_versions.lacros_version or "" |
Michael Mortensen | b70e8a8 | 2019-10-10 18:43:41 -0600 | [diff] [blame] | 199 | |
| 200 | |
Michael Mortensen | bfc5639 | 2020-04-30 15:23:47 -0600 | [diff] [blame] | 201 | def _GetBuilderMetadataResponse(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 202 | """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 Mortensen | bfc5639 | 2020-04-30 15:23:47 -0600 | [diff] [blame] | 210 | |
| 211 | |
| 212 | @faux.success(_GetBuilderMetadataResponse) |
| 213 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 214 | @validate.require("build_target.name") |
Michael Mortensen | bfc5639 | 2020-04-30 15:23:47 -0600 | [diff] [blame] | 215 | @validate.validation_complete |
| 216 | def GetBuilderMetadata(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 217 | """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 Mortensen | bbce7e4 | 2020-05-01 15:03:49 -0600 | [diff] [blame] | 240 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 241 | build_target_metadata.arc_use_set = "arc" in portage_util.GetBoardUseFlags( |
| 242 | build_target.name |
| 243 | ) |
Michael Mortensen | bbce7e4 | 2020-05-01 15:03:49 -0600 | [diff] [blame] | 244 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 245 | 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 Shai | 0858cd3 | 2022-01-10 20:23:49 +0000 | [diff] [blame] | 250 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 251 | 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 Mortensen | bfc5639 | 2020-04-30 15:23:47 -0600 | [diff] [blame] | 256 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 257 | 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 Mortensen | 770bc12 | 2020-05-27 17:53:30 -0600 | [diff] [blame] | 274 | |
| 275 | |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 276 | def _HasPrebuiltSuccess(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 277 | """The mock success case for HasChromePrebuilt.""" |
| 278 | output_proto.has_prebuilt = True |
Michael Mortensen | 68abdb7 | 2019-10-28 09:43:52 -0600 | [diff] [blame] | 279 | |
| 280 | |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 281 | @faux.success(_HasPrebuiltSuccess) |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 282 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 283 | @validate.require("build_target.name") |
Alex Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 284 | @validate.validation_complete |
| 285 | def HasChromePrebuilt(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 286 | """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 Klein | da39c6d | 2019-09-16 14:36:36 -0600 | [diff] [blame] | 292 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 293 | output_proto.has_prebuilt = exists |
Alex Klein | 73fb657 | 2019-09-30 16:55:23 -0600 | [diff] [blame] | 294 | |
| 295 | |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 296 | @faux.success(_HasPrebuiltSuccess) |
| 297 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 298 | @validate.require( |
| 299 | "build_target.name", "package_info.category", "package_info.package_name" |
| 300 | ) |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 301 | @validate.validation_complete |
| 302 | def HasPrebuilt(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 303 | """Checks if the most recent version of Chrome has a prebuilt.""" |
| 304 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
Alex Klein | d3b8404 | 2023-05-19 14:43:59 -0600 | [diff] [blame] | 305 | package = controller_util.deserialize_package_info(input_proto.package_info) |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 306 | useflags = "chrome_internal" if input_proto.chrome else None |
| 307 | exists = packages.has_prebuilt( |
Alex Klein | d3b8404 | 2023-05-19 14:43:59 -0600 | [diff] [blame] | 308 | package.atom, build_target=build_target, useflags=useflags |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 309 | ) |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 310 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 311 | output_proto.has_prebuilt = exists |
Alex Klein | 7d66c09 | 2020-03-23 15:13:18 -0600 | [diff] [blame] | 312 | |
| 313 | |
Alex Klein | 73fb657 | 2019-09-30 16:55:23 -0600 | [diff] [blame] | 314 | def _BuildsChromeSuccess(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 315 | """Mock success case for BuildsChrome.""" |
| 316 | output_proto.builds_chrome = True |
Alex Klein | 73fb657 | 2019-09-30 16:55:23 -0600 | [diff] [blame] | 317 | |
| 318 | |
| 319 | @faux.success(_BuildsChromeSuccess) |
| 320 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 321 | @validate.require("build_target.name") |
| 322 | @validate.require_each("packages", ["category", "package_name"]) |
Alex Klein | 73fb657 | 2019-09-30 16:55:23 -0600 | [diff] [blame] | 323 | @validate.validation_complete |
| 324 | def BuildsChrome(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 325 | """Check if the board builds chrome.""" |
| 326 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
Alex Klein | d3b8404 | 2023-05-19 14:43:59 -0600 | [diff] [blame] | 327 | 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 Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 332 | output_proto.builds_chrome = builds_chrome |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 333 | |
| 334 | |
| 335 | def _NeedsChromeSourceSuccess(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 336 | """Mock success case for NeedsChromeSource.""" |
| 337 | output_proto.needs_chrome_source = True |
| 338 | output_proto.builds_chrome = True |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 339 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 340 | output_proto.reasons.append( |
| 341 | packages_pb2.NeedsChromeSourceResponse.NO_PREBUILT |
| 342 | ) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 343 | pkg_info_msg = output_proto.packages.add() |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 344 | 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 Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 354 | |
| 355 | |
| 356 | @faux.success(_NeedsChromeSourceSuccess) |
| 357 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 358 | @validate.require("install_request.sysroot.build_target.name") |
| 359 | @validate.exists("install_request.sysroot.path") |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 360 | @validate.validation_complete |
| 361 | def NeedsChromeSource(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 362 | """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 Hashimoto | 5272b03 | 2023-09-29 08:22:13 +0000 | [diff] [blame^] | 370 | or input_proto.install_request.flags.bazel |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 371 | ) |
| 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 Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 377 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 378 | result = packages.needs_chrome_source( |
| 379 | build_target, |
| 380 | compile_source=compile_source, |
| 381 | packages=pkgs, |
| 382 | useflags=use_flags, |
| 383 | ) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 384 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 385 | # Record everything in the response. |
| 386 | output_proto.needs_chrome_source = result.needs_chrome_source |
| 387 | output_proto.builds_chrome = result.builds_chrome |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 388 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 389 | # Compile source reason. |
| 390 | if compile_source: |
| 391 | output_proto.reasons.append( |
| 392 | packages_pb2.NeedsChromeSourceResponse.COMPILE_SOURCE |
| 393 | ) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 394 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 395 | # Local uprev reason. |
| 396 | if result.local_uprev: |
| 397 | output_proto.reasons.append( |
| 398 | packages_pb2.NeedsChromeSourceResponse.LOCAL_UPREV |
| 399 | ) |
Alex Klein | 9ce3f68 | 2021-06-23 15:06:44 -0600 | [diff] [blame] | 400 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 401 | # No chrome prebuilt reason. |
| 402 | if result.missing_chrome_prebuilt: |
| 403 | output_proto.reasons.append( |
| 404 | packages_pb2.NeedsChromeSourceResponse.NO_PREBUILT |
| 405 | ) |
Alex Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 406 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 407 | # 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 Klein | 6becabc | 2020-09-11 14:03:05 -0600 | [diff] [blame] | 412 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 413 | for pkg in result.packages: |
| 414 | pkg_info = output_proto.packages.add() |
| 415 | controller_util.serialize_package_info(pkg, pkg_info) |
Shao-Chuan Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 416 | |
| 417 | |
| 418 | def _GetAndroidMetadataResponse(_input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 419 | """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 Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 423 | |
| 424 | |
| 425 | @faux.success(_GetAndroidMetadataResponse) |
| 426 | @faux.empty_error |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 427 | @validate.require("build_target.name") |
Shao-Chuan Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 428 | @validate.validation_complete |
| 429 | def GetAndroidMetadata(input_proto, output_proto, _config): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 430 | """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 Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 439 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 440 | 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 Lee | eb834a3 | 2021-05-12 17:10:55 +0900 | [diff] [blame] | 445 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 446 | 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 |