Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | """Implements ArtifactService.""" |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | import os |
| 11 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 12 | from chromite.api import controller |
Alex Klein | 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 |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 15 | from chromite.cbuildbot import commands |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 16 | from chromite.lib import build_target_util |
| 17 | from chromite.lib import chroot_lib |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 18 | from chromite.lib import constants |
| 19 | from chromite.lib import cros_build_lib |
Evan Hernandez | de44598 | 2019-04-22 13:42:34 -0600 | [diff] [blame] | 20 | from chromite.lib import cros_logging as logging |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 21 | from chromite.lib import sysroot_lib |
| 22 | from chromite.service import artifacts |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 23 | |
| 24 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 25 | def _GetImageDir(build_root, target): |
| 26 | """Return path containing images for the given build target. |
| 27 | |
Alex Klein | e2612a0 | 2019-04-18 13:51:06 -0600 | [diff] [blame] | 28 | TODO(saklein) Expand image_lib.GetLatestImageLink to support this use case. |
| 29 | |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 30 | Args: |
| 31 | build_root (str): Path to checkout where build occurs. |
| 32 | target (str): Name of the build target. |
| 33 | |
| 34 | Returns: |
| 35 | Path to the directory containing target images. |
| 36 | |
| 37 | Raises: |
| 38 | DieSystemExit: If the image dir does not exist. |
| 39 | """ |
| 40 | image_dir = os.path.join(build_root, 'src/build/images', target, 'latest') |
| 41 | if not os.path.exists(image_dir): |
| 42 | cros_build_lib.Die('Expected to find image output for target %s at %s, ' |
| 43 | 'but path does not exist' % (target, image_dir)) |
| 44 | return image_dir |
| 45 | |
| 46 | |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 47 | @validate.require('build_target.name', 'output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 48 | @validate.exists('output_dir') |
| 49 | @validate.validation_complete |
| 50 | def BundleImageZip(input_proto, output_proto, _config): |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 51 | """Bundle image.zip. |
| 52 | |
| 53 | Args: |
| 54 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 55 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 56 | _config (api_config.ApiConfig): The API call config. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 57 | """ |
| 58 | target = input_proto.build_target.name |
| 59 | output_dir = input_proto.output_dir |
| 60 | image_dir = _GetImageDir(constants.SOURCE_ROOT, target) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 61 | |
Michael Mortensen | 0191092 | 2019-07-24 14:48:10 -0600 | [diff] [blame] | 62 | archive = artifacts.BundleImageZip(output_dir, image_dir) |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 63 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
| 64 | |
| 65 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 66 | @validate.require('build_target.name', 'output_dir') |
| 67 | @validate.exists('output_dir') |
| 68 | @validate.validation_complete |
| 69 | def BundleTestUpdatePayloads(input_proto, output_proto, _config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 70 | """Generate minimal update payloads for the build target for testing. |
| 71 | |
| 72 | Args: |
| 73 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 74 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 75 | _config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 76 | """ |
| 77 | target = input_proto.build_target.name |
| 78 | output_dir = input_proto.output_dir |
| 79 | build_root = constants.SOURCE_ROOT |
| 80 | |
| 81 | # Use the first available image to create the update payload. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 82 | img_dir = _GetImageDir(build_root, target) |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 83 | img_types = [constants.IMAGE_TYPE_TEST, constants.IMAGE_TYPE_DEV, |
| 84 | constants.IMAGE_TYPE_BASE] |
| 85 | 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] | 86 | 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] | 87 | 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] | 88 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 89 | if not valid_images: |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 90 | cros_build_lib.Die( |
| 91 | 'Expected to find an image of type among %r for target "%s" ' |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 92 | 'at path %s.', img_types, target, img_dir) |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 93 | image = valid_images[0] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 94 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 95 | payloads = artifacts.BundleTestUpdatePayloads(image, output_dir) |
| 96 | for payload in payloads: |
| 97 | output_proto.artifacts.add().path = payload |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 98 | |
| 99 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 100 | @validate.require('output_dir') |
| 101 | @validate.exists('output_dir') |
| 102 | def BundleAutotestFiles(input_proto, output_proto, config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 103 | """Tar the autotest files for a build target. |
| 104 | |
| 105 | Args: |
| 106 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 107 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 108 | config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 109 | """ |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 110 | output_dir = input_proto.output_dir |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 111 | target = input_proto.build_target.name |
| 112 | if target: |
| 113 | # Legacy call, build out sysroot path from default source root and the |
| 114 | # build target. |
| 115 | target = input_proto.build_target.name |
| 116 | build_root = constants.SOURCE_ROOT |
| 117 | sysroot_path = os.path.join(build_root, constants.DEFAULT_CHROOT_DIR, |
| 118 | 'build', target) |
| 119 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
| 120 | else: |
| 121 | # New style call, use chroot and sysroot. |
| 122 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 123 | |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 124 | sysroot_path = input_proto.sysroot.path |
| 125 | if not sysroot_path: |
| 126 | cros_build_lib.Die('sysroot.path is required.') |
| 127 | |
| 128 | # Since we're staying outside the chroot, prepend the chroot path to the |
| 129 | # sysroot path so we have a valid full path to the sysroot. |
| 130 | sysroot = sysroot_lib.Sysroot(os.path.join(chroot.path, |
| 131 | sysroot_path.lstrip(os.sep))) |
| 132 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 133 | # TODO(saklein): Switch to the validate_only decorator when legacy handling |
| 134 | # is removed. |
| 135 | if config.validate_only: |
| 136 | return controller.RETURN_CODE_VALID_INPUT |
| 137 | |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 138 | if not sysroot.Exists(): |
| 139 | cros_build_lib.Die('Sysroot path must exist: %s', sysroot.path) |
| 140 | |
| 141 | try: |
| 142 | # Note that this returns the full path to *multiple* tarballs. |
| 143 | archives = artifacts.BundleAutotestFiles(sysroot, output_dir) |
| 144 | except artifacts.Error as e: |
| 145 | cros_build_lib.Die(e.message) |
| 146 | |
| 147 | for archive in archives.values(): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 148 | output_proto.artifacts.add().path = archive |
| 149 | |
| 150 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 151 | @validate.require('output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 152 | @validate.exists('output_dir') |
| 153 | def BundleTastFiles(input_proto, output_proto, config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 154 | """Tar the tast files for a build target. |
| 155 | |
| 156 | Args: |
| 157 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 158 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 159 | config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 160 | """ |
| 161 | target = input_proto.build_target.name |
| 162 | output_dir = input_proto.output_dir |
| 163 | build_root = constants.SOURCE_ROOT |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 164 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 165 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 166 | sysroot_path = input_proto.sysroot.path |
| 167 | |
| 168 | # TODO(saklein) Cleanup legacy handling after it has been switched over. |
| 169 | if target: |
| 170 | # Legacy handling. |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 171 | chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot')) |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 172 | sysroot_path = os.path.join('/build', target) |
| 173 | |
| 174 | # New handling - chroot & sysroot based. |
| 175 | # TODO(saklein) Switch this to the require decorator when legacy is removed. |
| 176 | if not sysroot_path: |
| 177 | cros_build_lib.Die('sysroot.path is required.') |
| 178 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 179 | # TODO(saklein): Switch to the validation_complete decorator when legacy |
| 180 | # handling is removed. |
| 181 | if config.validate_only: |
| 182 | return controller.RETURN_CODE_VALID_INPUT |
| 183 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 184 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 185 | if not sysroot.Exists(chroot=chroot): |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 186 | cros_build_lib.Die('Sysroot must exist.') |
| 187 | |
| 188 | archive = artifacts.BundleTastFiles(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 189 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 190 | if archive is None: |
| 191 | cros_build_lib.Die( |
| 192 | 'Could not bundle Tast files. ' |
| 193 | 'No Tast directories found for %s.', target) |
| 194 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 195 | output_proto.artifacts.add().path = archive |
| 196 | |
| 197 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 198 | @validate.require('build_target.name', 'output_dir') |
| 199 | @validate.exists('output_dir') |
| 200 | @validate.validation_complete |
| 201 | def BundlePinnedGuestImages(input_proto, output_proto, _config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 202 | """Tar the pinned guest images for a build target. |
| 203 | |
| 204 | Args: |
| 205 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 206 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 207 | _config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 208 | """ |
| 209 | target = input_proto.build_target.name |
| 210 | output_dir = input_proto.output_dir |
| 211 | build_root = constants.SOURCE_ROOT |
| 212 | |
Alex Klein | e2612a0 | 2019-04-18 13:51:06 -0600 | [diff] [blame] | 213 | # TODO(crbug.com/954299): Replace with a chromite/service implementation. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 214 | archive = commands.BuildPinnedGuestImagesTarball(build_root, target, |
| 215 | output_dir) |
| 216 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 217 | if archive is None: |
Evan Hernandez | de44598 | 2019-04-22 13:42:34 -0600 | [diff] [blame] | 218 | logging.warning('Found no pinned guest images for %s.', target) |
| 219 | return |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 220 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 221 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
| 222 | |
| 223 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 224 | @validate.require('sysroot.path') |
| 225 | @validate.validation_complete |
| 226 | def FetchPinnedGuestImages(input_proto, output_proto, _config): |
Alex Klein | 7bf0ecb | 2019-06-25 10:04:15 -0600 | [diff] [blame] | 227 | """Get the pinned guest image information.""" |
| 228 | sysroot_path = input_proto.sysroot.path |
Alex Klein | 7bf0ecb | 2019-06-25 10:04:15 -0600 | [diff] [blame] | 229 | |
| 230 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 231 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
| 232 | |
| 233 | if not chroot.exists(): |
| 234 | cros_build_lib.Die('Chroot does not exist: %s', chroot.path) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 235 | elif not sysroot.Exists(chroot=chroot): |
Alex Klein | 7bf0ecb | 2019-06-25 10:04:15 -0600 | [diff] [blame] | 236 | cros_build_lib.Die('Sysroot does not exist: %s', |
| 237 | chroot.full_path(sysroot.path)) |
| 238 | |
| 239 | pins = artifacts.FetchPinnedGuestImages(chroot, sysroot) |
| 240 | |
| 241 | for pin in pins: |
| 242 | pinned_image = output_proto.pinned_images.add() |
| 243 | pinned_image.filename = pin.filename |
| 244 | pinned_image.uri = pin.uri |
| 245 | |
| 246 | |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 247 | @validate.require('output_dir', 'sysroot.path') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 248 | @validate.exists('output_dir') |
| 249 | @validate.validation_complete |
| 250 | def BundleFirmware(input_proto, output_proto, _config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 251 | """Tar the firmware images for a build target. |
| 252 | |
| 253 | Args: |
| 254 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 255 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 256 | _config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 257 | """ |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 258 | output_dir = input_proto.output_dir |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 259 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 260 | sysroot_path = input_proto.sysroot.path |
| 261 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 262 | |
| 263 | if not chroot.exists(): |
| 264 | cros_build_lib.Die('Chroot does not exist: %s', chroot.path) |
| 265 | elif not sysroot.Exists(chroot=chroot): |
| 266 | cros_build_lib.Die('Sysroot does not exist: %s', |
| 267 | chroot.full_path(sysroot.path)) |
| 268 | |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 269 | archive = artifacts.BuildFirmwareArchive(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 270 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 271 | if archive is None: |
| 272 | cros_build_lib.Die( |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 273 | 'Could not create firmware archive. No firmware found for %s.', |
| 274 | sysroot_path) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 275 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 276 | output_proto.artifacts.add().path = archive |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 277 | |
| 278 | |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 279 | @validate.exists('output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 280 | def BundleEbuildLogs(input_proto, output_proto, config): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 281 | """Tar the ebuild logs for a build target. |
| 282 | |
| 283 | Args: |
| 284 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 285 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 286 | config (api_config.ApiConfig): The API call config. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 287 | """ |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 288 | output_dir = input_proto.output_dir |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 289 | sysroot_path = input_proto.sysroot.path |
| 290 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Evan Hernandez | a478d80 | 2019-04-08 15:08:24 -0600 | [diff] [blame] | 291 | |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 292 | # TODO(mmortensen) Cleanup legacy handling after it has been switched over. |
| 293 | target = input_proto.build_target.name |
| 294 | if target: |
| 295 | # Legacy handling. |
| 296 | build_root = constants.SOURCE_ROOT |
Alex Klein | 171da61 | 2019-08-06 14:00:42 -0600 | [diff] [blame] | 297 | chroot = chroot_lib.Chroot(path=os.path.join(build_root, 'chroot')) |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 298 | sysroot_path = os.path.join('/build', target) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 299 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 300 | # TODO(saklein): Switch to validation_complete decorator after legacy |
| 301 | # handling has been cleaned up. |
| 302 | if config.validate_only: |
| 303 | return controller.RETURN_CODE_VALID_INPUT |
| 304 | |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 305 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
| 306 | archive = artifacts.BundleEBuildLogsTarball(chroot, sysroot, output_dir) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 307 | if archive is None: |
| 308 | cros_build_lib.Die( |
Michael Mortensen | 3f382cb | 2019-07-29 13:21:49 -0600 | [diff] [blame] | 309 | 'Could not create ebuild logs archive. No logs found for %s.', |
| 310 | sysroot.path) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 311 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 312 | |
| 313 | |
Andrew Lamb | 811aead | 2019-08-12 10:25:05 -0600 | [diff] [blame^] | 314 | @validate.exists('output_dir') |
| 315 | @validate.validation_complete |
| 316 | def BundleChromeOSConfig(input_proto, output_proto, _config): |
| 317 | """Output the ChromeOS Config payload for a build target. |
| 318 | |
| 319 | Args: |
| 320 | input_proto (BundleRequest): The input proto. |
| 321 | output_proto (BundleResponse): The output proto. |
| 322 | _config (api_config.ApiConfig): The API call config. |
| 323 | """ |
| 324 | output_dir = input_proto.output_dir |
| 325 | sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path) |
| 326 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 327 | |
| 328 | chromeos_config = artifacts.BundleChromeOSConfig(chroot, sysroot, output_dir) |
| 329 | if chromeos_config is None: |
| 330 | cros_build_lib.Die( |
| 331 | 'Could not create ChromeOS Config payload. No config found for %s.', |
| 332 | sysroot.path) |
| 333 | output_proto.artifacts.add().path = os.path.join(output_dir, chromeos_config) |
| 334 | |
| 335 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 336 | @validate.require('output_dir', 'sysroot.build_target.name', 'sysroot.path') |
| 337 | @validate.exists('output_dir') |
| 338 | @validate.validation_complete |
| 339 | def BundleSimpleChromeArtifacts(input_proto, output_proto, _config): |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 340 | """Create the simple chrome artifacts.""" |
| 341 | # Required args. |
| 342 | sysroot_path = input_proto.sysroot.path |
| 343 | build_target_name = input_proto.sysroot.build_target.name |
| 344 | output_dir = input_proto.output_dir |
| 345 | |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 346 | # Optional args. |
| 347 | chroot_path = input_proto.chroot.path or constants.DEFAULT_CHROOT_PATH |
| 348 | cache_dir = input_proto.chroot.cache_dir |
| 349 | |
| 350 | # Build out the argument instances. |
| 351 | build_target = build_target_util.BuildTarget(build_target_name) |
| 352 | chroot = chroot_lib.Chroot(path=chroot_path, cache_dir=cache_dir) |
| 353 | # Sysroot.path needs to be the fully qualified path, including the chroot. |
| 354 | full_sysroot_path = os.path.join(chroot.path, sysroot_path.lstrip(os.sep)) |
| 355 | sysroot = sysroot_lib.Sysroot(full_sysroot_path) |
| 356 | |
| 357 | # Quick sanity check that the sysroot exists before we go on. |
| 358 | if not sysroot.Exists(): |
| 359 | cros_build_lib.Die('The sysroot does not exist.') |
| 360 | |
| 361 | try: |
| 362 | results = artifacts.BundleSimpleChromeArtifacts(chroot, sysroot, |
| 363 | build_target, output_dir) |
| 364 | except artifacts.Error as e: |
| 365 | cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', |
| 366 | type(e), e) |
| 367 | |
| 368 | for file_name in results: |
| 369 | output_proto.artifacts.add().path = file_name |
| 370 | |
| 371 | |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 372 | @validate.require('chroot.path', 'test_results_dir', 'output_dir') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 373 | @validate.exists('output_dir') |
| 374 | @validate.validation_complete |
| 375 | def BundleVmFiles(input_proto, output_proto, _config): |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 376 | """Tar VM disk and memory files. |
| 377 | |
| 378 | Args: |
| 379 | input_proto (SysrootBundleRequest): The input proto. |
| 380 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 381 | _config (api_config.ApiConfig): The API call config. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 382 | """ |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 383 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 384 | test_results_dir = input_proto.test_results_dir |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 385 | output_dir = input_proto.output_dir |
| 386 | |
Michael Mortensen | 51f0672 | 2019-07-18 09:55:50 -0600 | [diff] [blame] | 387 | archives = artifacts.BundleVmFiles( |
| 388 | chroot, test_results_dir, output_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 389 | for archive in archives: |
| 390 | output_proto.artifacts.add().path = archive |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 391 | |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 392 | |
| 393 | @validate.require('build_target.name', 'output_dir') |
| 394 | @validate.exists('output_dir') |
| 395 | @validate.validation_complete |
| 396 | def BundleOrderfileGenerationArtifacts(input_proto, output_proto, _config): |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 397 | """Create tarballs of all the artifacts of orderfile_generate builder. |
| 398 | |
| 399 | Args: |
| 400 | input_proto (BundleRequest): The input proto. |
| 401 | output_proto (BundleResponse): The output proto. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 402 | _config (api_config.ApiConfig): The API call config. |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 403 | """ |
| 404 | # Required args. |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 405 | build_target = build_target_util.BuildTarget(input_proto.build_target.name) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 406 | output_dir = input_proto.output_dir |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 407 | |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 408 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 409 | |
| 410 | try: |
| 411 | results = artifacts.BundleOrderfileGenerationArtifacts( |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 412 | chroot, build_target, output_dir) |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 413 | except artifacts.Error as e: |
| 414 | cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', |
| 415 | type(e), e) |
| 416 | |
| 417 | for file_name in results: |
| 418 | output_proto.artifacts.add().path = file_name |