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