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