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