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