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