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