Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Implements ArtifactService.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 12 | from chromite.api import controller |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 13 | from chromite.api import faux |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 14 | from chromite.api import validate |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 15 | from chromite.api.controller import controller_util |
LaMont Jones | 58362a4 | 2021-02-04 17:40:08 -0700 | [diff] [blame] | 16 | from chromite.api.gen.chromite.api import artifacts_pb2 |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 17 | from chromite.api.gen.chromite.api import toolchain_pb2 |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 18 | from chromite.lib import chroot_lib |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 19 | from chromite.lib import constants |
| 20 | from chromite.lib import cros_build_lib |
Evan Hernandez | de44598 | 2019-04-22 13:42:34 -0600 | [diff] [blame] | 21 | from chromite.lib import cros_logging as logging |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 22 | from chromite.lib import sysroot_lib |
| 23 | from chromite.service import artifacts |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 24 | |
| 25 | |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 26 | def _GetResponse(_input_proto, _output_proto, _config): |
| 27 | """Currently bundles nothing.""" |
| 28 | # TODO(crbug/1034529): As methods migrate, begin populating them based on what |
| 29 | # input_proto has defined. |
| 30 | |
| 31 | |
| 32 | @faux.success(_GetResponse) |
| 33 | @faux.empty_error |
| 34 | @validate.exists('result_path.path.path') |
| 35 | @validate.validation_complete |
Chinglin Yu | e84119f | 2021-04-13 07:57:23 +0000 | [diff] [blame] | 36 | def Get(_input_proto, _output_proto, _config): |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 37 | """Get all artifacts. |
| 38 | |
| 39 | Get all artifacts for the build. |
| 40 | |
| 41 | Note: crbug/1034529 introduces this method as a noop. As the individual |
| 42 | artifact_type bundlers are added here, they *must* stop uploading it via the |
| 43 | individual bundler function. |
| 44 | |
| 45 | Args: |
Chinglin Yu | e84119f | 2021-04-13 07:57:23 +0000 | [diff] [blame] | 46 | _input_proto (GetRequest): The input proto. |
| 47 | _output_proto (GetResponse): The output proto. |
LaMont Jones | 0f5171b | 2021-01-29 12:28:56 -0700 | [diff] [blame] | 48 | _config (api_config.ApiConfig): The API call config. |
| 49 | """ |
| 50 | return controller.RETURN_CODE_SUCCESS |
| 51 | |
| 52 | |
LaMont Jones | 58362a4 | 2021-02-04 17:40:08 -0700 | [diff] [blame] | 53 | def _BuildSetupResponse(_input_proto, output_proto, _config): |
| 54 | """Just return POINTLESS for now.""" |
| 55 | # All of the artifact types we support claim that the build is POINTLESS. |
| 56 | output_proto.build_relevance = artifacts_pb2.BuildSetupResponse.POINTLESS |
| 57 | |
| 58 | |
| 59 | @faux.success(_BuildSetupResponse) |
| 60 | @faux.empty_error |
| 61 | @validate.validation_complete |
| 62 | def BuildSetup(_input_proto, output_proto, _config): |
| 63 | """Setup anything needed for building artifacts |
| 64 | |
| 65 | If any artifact types require steps prior to building the package, they go |
| 66 | here. For example, see ToolchainService/PrepareForBuild. |
| 67 | |
| 68 | Note: crbug/1034529 introduces this method as a noop. As the individual |
| 69 | artifact_type bundlers are added here, they *must* stop uploading it via the |
| 70 | individual bundler function. |
| 71 | |
| 72 | Args: |
| 73 | _input_proto (GetRequest): The input proto. |
| 74 | output_proto (GetResponse): The output proto. |
| 75 | _config (api_config.ApiConfig): The API call config. |
| 76 | """ |
| 77 | # If any artifact_type says "NEEDED", the return is NEEDED. |
| 78 | # Otherwise, if any artifact_type says "UNKNOWN", the return is UNKNOWN. |
| 79 | # Otherwise, the return is POINTLESS. |
| 80 | output_proto.build_relevance = artifacts_pb2.BuildSetupResponse.POINTLESS |
| 81 | return controller.RETURN_CODE_SUCCESS |
| 82 | |
| 83 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 84 | def _GetImageDir(build_root, target): |
| 85 | """Return path containing images for the given build target. |
| 86 | |
Alex Klein | e2612a0 | 2019-04-18 13:51:06 -0600 | [diff] [blame] | 87 | TODO(saklein) Expand image_lib.GetLatestImageLink to support this use case. |
| 88 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 89 | Args: |
| 90 | build_root (str): Path to checkout where build occurs. |
| 91 | target (str): Name of the build target. |
| 92 | |
| 93 | Returns: |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 94 | Path to the latest directory containing target images or None. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 95 | """ |
| 96 | image_dir = os.path.join(build_root, 'src/build/images', target, 'latest') |
| 97 | if not os.path.exists(image_dir): |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 98 | logging.warning('Expected to find image output for target %s at %s, but ' |
| 99 | 'path does not exist', target, image_dir) |
| 100 | return None |
| 101 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 102 | return image_dir |
| 103 | |
| 104 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 105 | def _BundleImageArchivesResponse(input_proto, output_proto, _config): |
| 106 | """Add artifact paths to a successful response.""" |
| 107 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 108 | 'path0.tar.xz') |
| 109 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 110 | 'path1.tar.xz') |
| 111 | |
| 112 | |
| 113 | @faux.success(_BundleImageArchivesResponse) |
| 114 | @faux.empty_error |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 115 | @validate.require('build_target.name') |
| 116 | @validate.exists('output_dir') |
| 117 | @validate.validation_complete |
| 118 | def BundleImageArchives(input_proto, output_proto, _config): |
| 119 | """Create a .tar.xz archive for each image that has been created.""" |
| 120 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 121 | output_dir = input_proto.output_dir |
| 122 | image_dir = _GetImageDir(constants.SOURCE_ROOT, build_target.name) |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 123 | if image_dir is None: |
| 124 | return |
Alex Klein | d91e95a | 2019-09-17 10:39:02 -0600 | [diff] [blame] | 125 | |
| 126 | archives = artifacts.ArchiveImages(image_dir, output_dir) |
| 127 | |
| 128 | for archive in archives: |
| 129 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
| 130 | |
| 131 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 132 | def _BundleImageZipResponse(input_proto, output_proto, _config): |
| 133 | """Add artifact zip files to a successful response.""" |
| 134 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 135 | 'image.zip') |
| 136 | |
| 137 | |
| 138 | @faux.success(_BundleImageZipResponse) |
| 139 | @faux.empty_error |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 140 | @validate.require('build_target.name', 'output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 141 | @validate.exists('output_dir') |
| 142 | @validate.validation_complete |
| 143 | def BundleImageZip(input_proto, output_proto, _config): |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 144 | """Bundle image.zip. |
| 145 | |
| 146 | Args: |
| 147 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 148 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 149 | _config (api_config.ApiConfig): The API call config. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 150 | """ |
| 151 | target = input_proto.build_target.name |
| 152 | output_dir = input_proto.output_dir |
| 153 | image_dir = _GetImageDir(constants.SOURCE_ROOT, target) |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 154 | if image_dir is None: |
| 155 | return None |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 156 | |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 157 | archive = artifacts.BundleImageZip(output_dir, image_dir) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 158 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
| 159 | |
| 160 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 161 | def _BundleTestUpdatePayloadsResponse(input_proto, output_proto, _config): |
| 162 | """Add test payload files to a successful response.""" |
| 163 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 164 | 'payload1.bin') |
| 165 | |
| 166 | |
| 167 | @faux.success(_BundleTestUpdatePayloadsResponse) |
| 168 | @faux.empty_error |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 169 | @validate.require('build_target.name', 'output_dir') |
| 170 | @validate.exists('output_dir') |
| 171 | @validate.validation_complete |
| 172 | def BundleTestUpdatePayloads(input_proto, output_proto, _config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 173 | """Generate minimal update payloads for the build target for testing. |
| 174 | |
| 175 | Args: |
| 176 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 177 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 178 | _config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 179 | """ |
| 180 | target = input_proto.build_target.name |
| 181 | output_dir = input_proto.output_dir |
| 182 | build_root = constants.SOURCE_ROOT |
| 183 | |
| 184 | # Use the first available image to create the update payload. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 185 | img_dir = _GetImageDir(build_root, target) |
Alex Klein | d2bf146 | 2019-10-24 16:37:04 -0600 | [diff] [blame] | 186 | if img_dir is None: |
| 187 | return None |
| 188 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 189 | img_types = [constants.IMAGE_TYPE_TEST, constants.IMAGE_TYPE_DEV, |
| 190 | constants.IMAGE_TYPE_BASE] |
| 191 | img_names = [constants.IMAGE_TYPE_TO_NAME[t] for t in img_types] |
Mike Frysinger | 66ce413 | 2019-07-17 22:52:52 -0400 | [diff] [blame] | 192 | img_paths = [os.path.join(img_dir, x) for x in img_names] |
Mike Frysinger | a552be4 | 2018-08-17 14:39:32 -0400 | [diff] [blame] | 193 | valid_images = [x for x in img_paths if os.path.exists(x)] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 194 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 195 | if not valid_images: |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 196 | cros_build_lib.Die( |
| 197 | 'Expected to find an image of type among %r for target "%s" ' |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 198 | 'at path %s.', img_types, target, img_dir) |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 199 | image = valid_images[0] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 200 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 201 | payloads = artifacts.BundleTestUpdatePayloads(image, output_dir) |
| 202 | for payload in payloads: |
| 203 | output_proto.artifacts.add().path = payload |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 204 | |
| 205 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 206 | def _BundleAutotestFilesResponse(input_proto, output_proto, _config): |
| 207 | """Add test autotest files to a successful response.""" |
| 208 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 209 | 'autotest-a.tar.gz') |
| 210 | |
| 211 | |
| 212 | @faux.success(_BundleAutotestFilesResponse) |
| 213 | @faux.empty_error |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 214 | @validate.require('output_dir') |
| 215 | @validate.exists('output_dir') |
| 216 | def BundleAutotestFiles(input_proto, output_proto, config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 217 | """Tar the autotest files for a build target. |
| 218 | |
| 219 | Args: |
| 220 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 221 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 222 | config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 223 | """ |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 224 | output_dir = input_proto.output_dir |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 225 | target = input_proto.build_target.name |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 226 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 227 | |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 228 | if target: |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 229 | sysroot_path = os.path.join('/build', target) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 230 | else: |
| 231 | # New style call, use chroot and sysroot. |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 232 | sysroot_path = input_proto.sysroot.path |
| 233 | if not sysroot_path: |
| 234 | cros_build_lib.Die('sysroot.path is required.') |
| 235 | |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 236 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 237 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 238 | # TODO(saklein): Switch to the validate_only decorator when legacy handling |
| 239 | # is removed. |
| 240 | if config.validate_only: |
| 241 | return controller.RETURN_CODE_VALID_INPUT |
| 242 | |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 243 | if not sysroot.Exists(chroot=chroot): |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 244 | cros_build_lib.Die('Sysroot path must exist: %s', sysroot.path) |
| 245 | |
| 246 | try: |
| 247 | # Note that this returns the full path to *multiple* tarballs. |
Alex Klein | e21a095 | 2019-08-23 16:08:16 -0600 | [diff] [blame] | 248 | archives = artifacts.BundleAutotestFiles(chroot, sysroot, output_dir) |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 249 | except artifacts.Error as e: |
Alex Klein | 0389031 | 2020-06-30 09:59:50 -0600 | [diff] [blame] | 250 | logging.warning(e) |
| 251 | return |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 252 | |
| 253 | for archive in archives.values(): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 254 | output_proto.artifacts.add().path = archive |
| 255 | |
| 256 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 257 | def _BundleTastFilesResponse(input_proto, output_proto, _config): |
| 258 | """Add test tast files to a successful response.""" |
| 259 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 260 | 'tast_bundles.tar.gz') |
| 261 | |
| 262 | |
| 263 | @faux.success(_BundleTastFilesResponse) |
| 264 | @faux.empty_error |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 265 | @validate.require('output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 266 | @validate.exists('output_dir') |
| 267 | def BundleTastFiles(input_proto, output_proto, config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 268 | """Tar the tast files for a build target. |
| 269 | |
| 270 | Args: |
| 271 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 272 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 273 | config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 274 | """ |
| 275 | target = input_proto.build_target.name |
| 276 | output_dir = input_proto.output_dir |
| 277 | build_root = constants.SOURCE_ROOT |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 278 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 279 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 280 | sysroot_path = input_proto.sysroot.path |
| 281 | |
| 282 | # TODO(saklein) Cleanup legacy handling after it has been switched over. |
| 283 | if target: |
| 284 | # Legacy handling. |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 285 | chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot')) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 286 | sysroot_path = os.path.join('/build', target) |
| 287 | |
| 288 | # New handling - chroot & sysroot based. |
| 289 | # TODO(saklein) Switch this to the require decorator when legacy is removed. |
| 290 | if not sysroot_path: |
| 291 | cros_build_lib.Die('sysroot.path is required.') |
| 292 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 293 | # TODO(saklein): Switch to the validation_complete decorator when legacy |
| 294 | # handling is removed. |
| 295 | if config.validate_only: |
| 296 | return controller.RETURN_CODE_VALID_INPUT |
| 297 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 298 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 299 | if not sysroot.Exists(chroot=chroot): |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 300 | cros_build_lib.Die('Sysroot must exist.') |
| 301 | |
| 302 | archive = artifacts.BundleTastFiles(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 303 | |
LaMont Jones | b9793cd | 2020-06-11 08:14:46 -0600 | [diff] [blame] | 304 | if archive: |
| 305 | output_proto.artifacts.add().path = archive |
| 306 | else: |
| 307 | logging.warning('Found no tast files for %s.', target) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 308 | |
| 309 | |
Fergus Dall | 34d74e1 | 2020-09-29 15:52:32 +1000 | [diff] [blame] | 310 | def BundlePinnedGuestImages(_input_proto, _output_proto, _config): |
| 311 | # TODO(crbug/1034529): Remove this endpoint |
| 312 | pass |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 313 | |
Fergus Dall | 34d74e1 | 2020-09-29 15:52:32 +1000 | [diff] [blame] | 314 | def FetchPinnedGuestImageUris(_input_proto, _output_proto, _config): |
| 315 | # TODO(crbug/1034529): Remove this endpoint |
| 316 | pass |
Alex Klein | 7bf0ecb | 2019-06-25 10:04:15 -0600 | [diff] [blame] | 317 | |
| 318 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 319 | def _BundleFirmwareResponse(input_proto, output_proto, _config): |
| 320 | """Add test firmware image files to a successful response.""" |
| 321 | output_proto.artifacts.add().path = os.path.join( |
| 322 | input_proto.output_dir, 'firmware.tar.gz') |
| 323 | |
| 324 | |
| 325 | @faux.success(_BundleFirmwareResponse) |
| 326 | @faux.empty_error |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 327 | @validate.require('output_dir', 'sysroot.path') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 328 | @validate.exists('output_dir') |
| 329 | @validate.validation_complete |
| 330 | def BundleFirmware(input_proto, output_proto, _config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 331 | """Tar the firmware images for a build target. |
| 332 | |
| 333 | Args: |
| 334 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 335 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 336 | _config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 337 | """ |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 338 | output_dir = input_proto.output_dir |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 339 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 340 | sysroot_path = input_proto.sysroot.path |
| 341 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 342 | |
| 343 | if not chroot.exists(): |
| 344 | cros_build_lib.Die('Chroot does not exist: %s', chroot.path) |
| 345 | elif not sysroot.Exists(chroot=chroot): |
| 346 | cros_build_lib.Die('Sysroot does not exist: %s', |
| 347 | chroot.full_path(sysroot.path)) |
| 348 | |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 349 | archive = artifacts.BuildFirmwareArchive(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 350 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 351 | if archive is None: |
| 352 | cros_build_lib.Die( |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 353 | 'Could not create firmware archive. No firmware found for %s.', |
| 354 | sysroot_path) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 355 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 356 | output_proto.artifacts.add().path = archive |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 357 | |
| 358 | |
Yicheng Li | ea1181f | 2020-09-22 11:51:10 -0700 | [diff] [blame] | 359 | def _BundleFpmcuUnittestsResponse(input_proto, output_proto, _config): |
| 360 | """Add fingerprint MCU unittest binaries to a successful response.""" |
| 361 | output_proto.artifacts.add().path = os.path.join( |
| 362 | input_proto.output_dir, 'fpmcu_unittests.tar.gz') |
| 363 | |
| 364 | |
| 365 | @faux.success(_BundleFpmcuUnittestsResponse) |
| 366 | @faux.empty_error |
| 367 | @validate.require('output_dir', 'sysroot.path') |
| 368 | @validate.exists('output_dir') |
| 369 | @validate.validation_complete |
| 370 | def BundleFpmcuUnittests(input_proto, output_proto, _config): |
| 371 | """Tar the fingerprint MCU unittest binaries for a build target. |
| 372 | |
| 373 | Args: |
| 374 | input_proto (BundleRequest): The input proto. |
| 375 | output_proto (BundleResponse): The output proto. |
| 376 | _config (api_config.ApiConfig): The API call config. |
| 377 | """ |
| 378 | output_dir = input_proto.output_dir |
| 379 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 380 | sysroot_path = input_proto.sysroot.path |
| 381 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
| 382 | |
| 383 | if not chroot.exists(): |
| 384 | cros_build_lib.Die('Chroot does not exist: %s', chroot.path) |
| 385 | elif not sysroot.Exists(chroot=chroot): |
| 386 | cros_build_lib.Die('Sysroot does not exist: %s', |
| 387 | chroot.full_path(sysroot.path)) |
| 388 | |
| 389 | archive = artifacts.BundleFpmcuUnittests(chroot, sysroot, output_dir) |
| 390 | |
| 391 | if archive is None: |
| 392 | logging.warning( |
| 393 | 'No fpmcu unittests found for %s.', sysroot_path) |
| 394 | return |
| 395 | |
| 396 | output_proto.artifacts.add().path = archive |
| 397 | |
| 398 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 399 | def _BundleEbuildLogsResponse(input_proto, output_proto, _config): |
| 400 | """Add test log files to a successful response.""" |
| 401 | output_proto.artifacts.add().path = os.path.join( |
| 402 | input_proto.output_dir, 'ebuild-logs.tar.gz') |
| 403 | |
| 404 | |
| 405 | @faux.success(_BundleEbuildLogsResponse) |
| 406 | @faux.empty_error |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 407 | @validate.exists('output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 408 | def BundleEbuildLogs(input_proto, output_proto, config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 409 | """Tar the ebuild logs for a build target. |
| 410 | |
| 411 | Args: |
| 412 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 413 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 414 | config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 415 | """ |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 416 | output_dir = input_proto.output_dir |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 417 | sysroot_path = input_proto.sysroot.path |
| 418 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Evan Hernandez | a478d80 | 2019-04-08 15:08:24 -0600 | [diff] [blame] | 419 | |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 420 | # TODO(mmortensen) Cleanup legacy handling after it has been switched over. |
| 421 | target = input_proto.build_target.name |
| 422 | if target: |
| 423 | # Legacy handling. |
| 424 | build_root = constants.SOURCE_ROOT |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 425 | chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot')) |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 426 | sysroot_path = os.path.join('/build', target) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 427 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 428 | # TODO(saklein): Switch to validation_complete decorator after legacy |
| 429 | # handling has been cleaned up. |
| 430 | if config.validate_only: |
| 431 | return controller.RETURN_CODE_VALID_INPUT |
| 432 | |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 433 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
| 434 | archive = artifacts.BundleEBuildLogsTarball(chroot, sysroot, output_dir) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 435 | if archive is None: |
| 436 | cros_build_lib.Die( |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 437 | 'Could not create ebuild logs archive. No logs found for %s.', |
| 438 | sysroot.path) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 439 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 440 | |
| 441 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 442 | def _BundleChromeOSConfigResponse(input_proto, output_proto, _config): |
| 443 | """Add test config files to a successful response.""" |
| 444 | output_proto.artifacts.add().path = os.path.join( |
| 445 | input_proto.output_dir, 'config.yaml') |
| 446 | |
| 447 | |
| 448 | @faux.success(_BundleChromeOSConfigResponse) |
| 449 | @faux.empty_error |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 450 | @validate.exists('output_dir') |
| 451 | @validate.validation_complete |
| 452 | def BundleChromeOSConfig(input_proto, output_proto, _config): |
| 453 | """Output the ChromeOS Config payload for a build target. |
| 454 | |
| 455 | Args: |
| 456 | input_proto (BundleRequest): The input proto. |
| 457 | output_proto (BundleResponse): The output proto. |
| 458 | _config (api_config.ApiConfig): The API call config. |
| 459 | """ |
| 460 | output_dir = input_proto.output_dir |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 461 | sysroot_path = input_proto.sysroot.path |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 462 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 463 | |
Andrew Lamb | 67bd68f | 2019-08-15 09:09:15 -0600 | [diff] [blame] | 464 | # TODO(mmortensen) Cleanup legacy handling after it has been switched over. |
| 465 | target = input_proto.build_target.name |
| 466 | if target: |
| 467 | # Legacy handling. |
| 468 | build_root = constants.SOURCE_ROOT |
| 469 | chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot')) |
| 470 | sysroot_path = os.path.join('/build', target) |
| 471 | |
| 472 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame] | 473 | chromeos_config = artifacts.BundleChromeOSConfig(chroot, sysroot, output_dir) |
| 474 | if chromeos_config is None: |
| 475 | cros_build_lib.Die( |
| 476 | 'Could not create ChromeOS Config payload. No config found for %s.', |
| 477 | sysroot.path) |
| 478 | output_proto.artifacts.add().path = os.path.join(output_dir, chromeos_config) |
| 479 | |
| 480 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 481 | def _BundleSimpleChromeArtifactsResponse(input_proto, output_proto, _config): |
| 482 | """Add test simple chrome files to a successful response.""" |
| 483 | output_proto.artifacts.add().path = os.path.join( |
| 484 | input_proto.output_dir, 'simple_chrome.txt') |
| 485 | |
| 486 | |
| 487 | @faux.success(_BundleSimpleChromeArtifactsResponse) |
| 488 | @faux.empty_error |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 489 | @validate.require('output_dir', 'sysroot.build_target.name', 'sysroot.path') |
| 490 | @validate.exists('output_dir') |
| 491 | @validate.validation_complete |
| 492 | def BundleSimpleChromeArtifacts(input_proto, output_proto, _config): |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 493 | """Create the simple chrome artifacts.""" |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 494 | sysroot_path = input_proto.sysroot.path |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 495 | output_dir = input_proto.output_dir |
| 496 | |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 497 | # Build out the argument instances. |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 498 | build_target = controller_util.ParseBuildTarget( |
| 499 | input_proto.sysroot.build_target) |
| 500 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 501 | # Sysroot.path needs to be the fully qualified path, including the chroot. |
| 502 | full_sysroot_path = os.path.join(chroot.path, sysroot_path.lstrip(os.sep)) |
| 503 | sysroot = sysroot_lib.Sysroot(full_sysroot_path) |
| 504 | |
| 505 | # Quick sanity check that the sysroot exists before we go on. |
| 506 | if not sysroot.Exists(): |
| 507 | cros_build_lib.Die('The sysroot does not exist.') |
| 508 | |
| 509 | try: |
| 510 | results = artifacts.BundleSimpleChromeArtifacts(chroot, sysroot, |
| 511 | build_target, output_dir) |
| 512 | except artifacts.Error as e: |
| 513 | cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', |
| 514 | type(e), e) |
| 515 | |
| 516 | for file_name in results: |
| 517 | output_proto.artifacts.add().path = file_name |
| 518 | |
| 519 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 520 | def _BundleVmFilesResponse(input_proto, output_proto, _config): |
| 521 | """Add test vm files to a successful response.""" |
| 522 | output_proto.artifacts.add().path = os.path.join( |
| 523 | input_proto.output_dir, 'f1.tar') |
| 524 | |
| 525 | |
| 526 | @faux.success(_BundleVmFilesResponse) |
| 527 | @faux.empty_error |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 528 | @validate.require('chroot.path', 'test_results_dir', 'output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 529 | @validate.exists('output_dir') |
| 530 | @validate.validation_complete |
| 531 | def BundleVmFiles(input_proto, output_proto, _config): |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 532 | """Tar VM disk and memory files. |
| 533 | |
| 534 | Args: |
Trent Begin | 008cade | 2019-10-31 13:40:59 -0600 | [diff] [blame] | 535 | input_proto (BundleVmFilesRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 536 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 537 | _config (api_config.ApiConfig): The API call config. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 538 | """ |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 539 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 540 | test_results_dir = input_proto.test_results_dir |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 541 | output_dir = input_proto.output_dir |
| 542 | |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 543 | archives = artifacts.BundleVmFiles( |
| 544 | chroot, test_results_dir, output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 545 | for archive in archives: |
| 546 | output_proto.artifacts.add().path = archive |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 547 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 548 | def _BundleAFDOGenerationArtifactsResponse(input_proto, output_proto, _config): |
| 549 | """Add test tarball AFDO file to a successful response.""" |
| 550 | output_proto.artifacts.add().path = os.path.join( |
| 551 | input_proto.output_dir, 'artifact1') |
| 552 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 553 | |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 554 | _VALID_ARTIFACT_TYPES = [toolchain_pb2.BENCHMARK_AFDO, |
| 555 | toolchain_pb2.ORDERFILE] |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 556 | @faux.success(_BundleAFDOGenerationArtifactsResponse) |
| 557 | @faux.empty_error |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 558 | @validate.require('build_target.name', 'output_dir') |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 559 | @validate.is_in('artifact_type', _VALID_ARTIFACT_TYPES) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 560 | @validate.exists('output_dir') |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 561 | @validate.exists('chroot.chrome_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 562 | @validate.validation_complete |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 563 | def BundleAFDOGenerationArtifacts(input_proto, output_proto, _config): |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 564 | """Generic function for creating tarballs of both AFDO and orderfile. |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 565 | |
| 566 | Args: |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 567 | input_proto (BundleChromeAFDORequest): The input proto. |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 568 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 569 | _config (api_config.ApiConfig): The API call config. |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 570 | """ |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 571 | chrome_root = input_proto.chroot.chrome_dir |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 572 | output_dir = input_proto.output_dir |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 573 | artifact_type = input_proto.artifact_type |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 574 | |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 575 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 576 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 577 | |
| 578 | try: |
Tiancong Wang | 24a3df7 | 2019-08-20 15:48:51 -0700 | [diff] [blame] | 579 | is_orderfile = bool(artifact_type is toolchain_pb2.ORDERFILE) |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 580 | results = artifacts.BundleAFDOGenerationArtifacts( |
Tiancong Wang | 2ade793 | 2019-09-27 14:15:40 -0700 | [diff] [blame] | 581 | is_orderfile, chroot, chrome_root, |
Tiancong Wang | 50b80a9 | 2019-08-01 14:46:15 -0700 | [diff] [blame] | 582 | build_target, output_dir) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 583 | except artifacts.Error as e: |
| 584 | cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', |
| 585 | type(e), e) |
| 586 | |
| 587 | for file_name in results: |
| 588 | output_proto.artifacts.add().path = file_name |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 589 | |
| 590 | |
Michael Mortensen | 2d6a240 | 2019-11-26 13:40:40 -0700 | [diff] [blame] | 591 | def _ExportCpeReportResponse(input_proto, output_proto, _config): |
| 592 | """Add test cpe results to a successful response.""" |
| 593 | output_proto.artifacts.add().path = os.path.join( |
| 594 | input_proto.output_dir, 'cpe_report.txt') |
| 595 | output_proto.artifacts.add().path = os.path.join( |
| 596 | input_proto.output_dir, 'cpe_warnings.txt') |
| 597 | |
| 598 | |
| 599 | @faux.success(_ExportCpeReportResponse) |
| 600 | @faux.empty_error |
Alex Klein | 0b1cbfc | 2019-08-14 10:09:58 -0600 | [diff] [blame] | 601 | @validate.exists('output_dir') |
| 602 | def ExportCpeReport(input_proto, output_proto, config): |
| 603 | """Export a CPE report. |
| 604 | |
| 605 | Args: |
| 606 | input_proto (BundleRequest): The input proto. |
| 607 | output_proto (BundleResponse): The output proto. |
| 608 | config (api_config.ApiConfig): The API call config. |
| 609 | """ |
| 610 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 611 | output_dir = input_proto.output_dir |
| 612 | |
| 613 | if input_proto.build_target.name: |
| 614 | # Legacy handling - use the default sysroot path for the build target. |
| 615 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
| 616 | sysroot = sysroot_lib.Sysroot(build_target.root) |
| 617 | elif input_proto.sysroot.path: |
| 618 | sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path) |
| 619 | else: |
| 620 | # TODO(saklein): Switch to validate decorators once legacy handling can be |
| 621 | # cleaned up. |
| 622 | cros_build_lib.Die('sysroot.path is required.') |
| 623 | |
| 624 | if config.validate_only: |
| 625 | return controller.RETURN_CODE_VALID_INPUT |
| 626 | |
| 627 | cpe_result = artifacts.GenerateCpeReport(chroot, sysroot, output_dir) |
| 628 | |
| 629 | output_proto.artifacts.add().path = cpe_result.report |
| 630 | output_proto.artifacts.add().path = cpe_result.warnings |
Shao-Chuan Lee | a44dddc | 2020-10-30 17:16:55 +0900 | [diff] [blame] | 631 | |
| 632 | |
| 633 | def _BundleGceTarballResponse(input_proto, output_proto, _config): |
| 634 | """Add artifact tarball to a successful response.""" |
| 635 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 636 | constants.TEST_IMAGE_GCE_TAR) |
| 637 | |
| 638 | |
| 639 | @faux.success(_BundleGceTarballResponse) |
| 640 | @faux.empty_error |
| 641 | @validate.require('build_target.name', 'output_dir') |
| 642 | @validate.exists('output_dir') |
| 643 | @validate.validation_complete |
| 644 | def BundleGceTarball(input_proto, output_proto, _config): |
| 645 | """Bundle the test image into a tarball suitable for importing into GCE. |
| 646 | |
| 647 | Args: |
| 648 | input_proto (BundleRequest): The input proto. |
| 649 | output_proto (BundleResponse): The output proto. |
| 650 | _config (api_config.ApiConfig): The API call config. |
| 651 | """ |
| 652 | target = input_proto.build_target.name |
| 653 | output_dir = input_proto.output_dir |
| 654 | image_dir = _GetImageDir(constants.SOURCE_ROOT, target) |
| 655 | if image_dir is None: |
| 656 | return None |
| 657 | |
| 658 | tarball = artifacts.BundleGceTarball(output_dir, image_dir) |
| 659 | output_proto.artifacts.add().path = tarball |
Michael Mortensen | 6667b54 | 2020-12-12 11:09:55 -0700 | [diff] [blame] | 660 | |
| 661 | |
| 662 | def _BundleDebugSymbolsResponse(input_proto, output_proto, _config): |
| 663 | """Add artifact tarball to a successful response.""" |
| 664 | output_proto.artifacts.add().path = os.path.join(input_proto.output_dir, |
| 665 | constants.DEBUG_SYMBOLS_TAR) |
| 666 | |
| 667 | |
| 668 | @faux.success(_BundleDebugSymbolsResponse) |
| 669 | @faux.empty_error |
| 670 | @validate.require('build_target.name', 'output_dir') |
| 671 | @validate.exists('output_dir') |
| 672 | @validate.validation_complete |
| 673 | def BundleDebugSymbols(input_proto, output_proto, _config): |
| 674 | """Bundle the debug symbols into a tarball suitable for importing into GCE. |
| 675 | |
| 676 | Args: |
| 677 | input_proto (BundleRequest): The input proto. |
| 678 | output_proto (BundleResponse): The output proto. |
| 679 | _config (api_config.ApiConfig): The API call config. |
| 680 | """ |
Michael Mortensen | 6667b54 | 2020-12-12 11:09:55 -0700 | [diff] [blame] | 681 | output_dir = input_proto.output_dir |
| 682 | |
| 683 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Michael Mortensen | 7da39cc | 2021-03-09 10:28:45 -0700 | [diff] [blame] | 684 | build_target = controller_util.ParseBuildTarget(input_proto.build_target) |
Michael Mortensen | 6667b54 | 2020-12-12 11:09:55 -0700 | [diff] [blame] | 685 | result = artifacts.GenerateBreakpadSymbols(chroot, |
Michael Mortensen | 7da39cc | 2021-03-09 10:28:45 -0700 | [diff] [blame] | 686 | build_target, |
Michael Mortensen | 6667b54 | 2020-12-12 11:09:55 -0700 | [diff] [blame] | 687 | debug=True) |
| 688 | |
| 689 | # Verify breakpad symbol generation before gathering the sym files. |
| 690 | if result.returncode != 0: |
| 691 | return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY |
| 692 | |
| 693 | with chroot.tempdir() as symbol_tmpdir, chroot.tempdir() as dest_tmpdir: |
Michael Mortensen | 7da39cc | 2021-03-09 10:28:45 -0700 | [diff] [blame] | 694 | breakpad_dir = os.path.join('/build', build_target.name, |
| 695 | 'usr/lib/debug/breakpad') |
Michael Mortensen | 5044d27 | 2021-04-09 16:15:16 -0600 | [diff] [blame] | 696 | # Call list on the atifacts.GatherSymbolFiles generator function to |
| 697 | # materialize and consume all entries so that all are copied to |
| 698 | # dest dir and complete list of all symbol files is returned. |
| 699 | sym_file_list = list(artifacts.GatherSymbolFiles(tempdir=symbol_tmpdir, |
| 700 | destdir=dest_tmpdir, |
| 701 | paths=[breakpad_dir])) |
| 702 | if not sym_file_list: |
Michael Mortensen | 6667b54 | 2020-12-12 11:09:55 -0700 | [diff] [blame] | 703 | logging.warning('No sym files found in %s.', breakpad_dir) |
| 704 | # Create tarball from destination_tmp, then copy it... |
| 705 | tarball_path = os.path.join(output_dir, constants.DEBUG_SYMBOLS_TAR) |
| 706 | result = cros_build_lib.CreateTarball(tarball_path, dest_tmpdir) |
| 707 | if result.returncode != 0: |
| 708 | logging.error('Error (%d) when creating tarball %s from %s', |
| 709 | result.returncode, |
| 710 | tarball_path, |
| 711 | dest_tmpdir) |
| 712 | return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY |
| 713 | output_proto.artifacts.add().path = tarball_path |
| 714 | |
| 715 | return controller.RETURN_CODE_SUCCESS |