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 | 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 |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 14 | from chromite.cbuildbot import commands |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 15 | from chromite.cbuildbot.stages import vm_test_stages |
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 | |
| 47 | def BundleImageZip(input_proto, output_proto): |
| 48 | """Bundle image.zip. |
| 49 | |
| 50 | Args: |
| 51 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 52 | output_proto (BundleResponse): The output proto. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 53 | """ |
| 54 | target = input_proto.build_target.name |
| 55 | output_dir = input_proto.output_dir |
| 56 | image_dir = _GetImageDir(constants.SOURCE_ROOT, target) |
| 57 | archive = commands.BuildImageZip(output_dir, image_dir) |
| 58 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
| 59 | |
| 60 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 61 | def BundleTestUpdatePayloads(input_proto, output_proto): |
| 62 | """Generate minimal update payloads for the build target for testing. |
| 63 | |
| 64 | Args: |
| 65 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 66 | output_proto (BundleResponse): The output proto. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 67 | """ |
| 68 | target = input_proto.build_target.name |
| 69 | output_dir = input_proto.output_dir |
| 70 | build_root = constants.SOURCE_ROOT |
| 71 | |
| 72 | # Use the first available image to create the update payload. |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 73 | img_dir = _GetImageDir(build_root, target) |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 74 | img_types = [constants.IMAGE_TYPE_TEST, constants.IMAGE_TYPE_DEV, |
| 75 | constants.IMAGE_TYPE_BASE] |
| 76 | 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^] | 77 | 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] | 78 | 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] | 79 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 80 | if not valid_images: |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 81 | cros_build_lib.Die( |
| 82 | 'Expected to find an image of type among %r for target "%s" ' |
Evan Hernandez | 9f125ac | 2019-04-08 17:18:47 -0600 | [diff] [blame] | 83 | 'at path %s.', img_types, target, img_dir) |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 84 | image = valid_images[0] |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 85 | |
Alex Klein | cb541e8 | 2019-06-26 15:06:11 -0600 | [diff] [blame] | 86 | payloads = artifacts.BundleTestUpdatePayloads(image, output_dir) |
| 87 | for payload in payloads: |
| 88 | output_proto.artifacts.add().path = payload |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 89 | |
| 90 | |
| 91 | def BundleAutotestFiles(input_proto, output_proto): |
| 92 | """Tar the autotest files for a build target. |
| 93 | |
| 94 | Args: |
| 95 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 96 | output_proto (BundleResponse): The output proto. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 97 | """ |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 98 | output_dir = input_proto.output_dir |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 99 | if not output_dir: |
| 100 | cros_build_lib.Die('output_dir is required.') |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 101 | |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 102 | target = input_proto.build_target.name |
| 103 | if target: |
| 104 | # Legacy call, build out sysroot path from default source root and the |
| 105 | # build target. |
| 106 | target = input_proto.build_target.name |
| 107 | build_root = constants.SOURCE_ROOT |
| 108 | sysroot_path = os.path.join(build_root, constants.DEFAULT_CHROOT_DIR, |
| 109 | 'build', target) |
| 110 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
| 111 | else: |
| 112 | # New style call, use chroot and sysroot. |
| 113 | chroot = controller_util.ParseChroot(input_proto.chroot) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 114 | |
Alex Klein | 238d886 | 2019-05-07 11:32:46 -0600 | [diff] [blame] | 115 | sysroot_path = input_proto.sysroot.path |
| 116 | if not sysroot_path: |
| 117 | cros_build_lib.Die('sysroot.path is required.') |
| 118 | |
| 119 | # Since we're staying outside the chroot, prepend the chroot path to the |
| 120 | # sysroot path so we have a valid full path to the sysroot. |
| 121 | sysroot = sysroot_lib.Sysroot(os.path.join(chroot.path, |
| 122 | sysroot_path.lstrip(os.sep))) |
| 123 | |
| 124 | if not sysroot.Exists(): |
| 125 | cros_build_lib.Die('Sysroot path must exist: %s', sysroot.path) |
| 126 | |
| 127 | try: |
| 128 | # Note that this returns the full path to *multiple* tarballs. |
| 129 | archives = artifacts.BundleAutotestFiles(sysroot, output_dir) |
| 130 | except artifacts.Error as e: |
| 131 | cros_build_lib.Die(e.message) |
| 132 | |
| 133 | for archive in archives.values(): |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 134 | output_proto.artifacts.add().path = archive |
| 135 | |
| 136 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 137 | @validate.require('output_dir') |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 138 | def BundleTastFiles(input_proto, output_proto): |
| 139 | """Tar the tast files for a build target. |
| 140 | |
| 141 | Args: |
| 142 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 143 | output_proto (BundleResponse): The output proto. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 144 | """ |
| 145 | target = input_proto.build_target.name |
| 146 | output_dir = input_proto.output_dir |
| 147 | build_root = constants.SOURCE_ROOT |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 148 | |
Alex Klein | b9d810b | 2019-07-01 12:38:02 -0600 | [diff] [blame] | 149 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 150 | sysroot_path = input_proto.sysroot.path |
| 151 | |
| 152 | # TODO(saklein) Cleanup legacy handling after it has been switched over. |
| 153 | if target: |
| 154 | # Legacy handling. |
| 155 | chroot.path = os.path.join(build_root, 'chroot') |
| 156 | sysroot_path = os.path.join('/build', target) |
| 157 | |
| 158 | # New handling - chroot & sysroot based. |
| 159 | # TODO(saklein) Switch this to the require decorator when legacy is removed. |
| 160 | if not sysroot_path: |
| 161 | cros_build_lib.Die('sysroot.path is required.') |
| 162 | |
| 163 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
| 164 | if not sysroot.Exists(chroot): |
| 165 | cros_build_lib.Die('Sysroot must exist.') |
| 166 | |
| 167 | archive = artifacts.BundleTastFiles(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 168 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 169 | if archive is None: |
| 170 | cros_build_lib.Die( |
| 171 | 'Could not bundle Tast files. ' |
| 172 | 'No Tast directories found for %s.', target) |
| 173 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 174 | output_proto.artifacts.add().path = archive |
| 175 | |
| 176 | |
| 177 | def BundlePinnedGuestImages(input_proto, output_proto): |
| 178 | """Tar the pinned guest images for a build target. |
| 179 | |
| 180 | Args: |
| 181 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 182 | output_proto (BundleResponse): The output proto. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 183 | """ |
| 184 | target = input_proto.build_target.name |
| 185 | output_dir = input_proto.output_dir |
| 186 | build_root = constants.SOURCE_ROOT |
| 187 | |
Alex Klein | e2612a0 | 2019-04-18 13:51:06 -0600 | [diff] [blame] | 188 | # TODO(crbug.com/954299): Replace with a chromite/service implementation. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 189 | archive = commands.BuildPinnedGuestImagesTarball(build_root, target, |
| 190 | output_dir) |
| 191 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 192 | if archive is None: |
Evan Hernandez | de44598 | 2019-04-22 13:42:34 -0600 | [diff] [blame] | 193 | logging.warning('Found no pinned guest images for %s.', target) |
| 194 | return |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 195 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 196 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
| 197 | |
| 198 | |
Alex Klein | 7bf0ecb | 2019-06-25 10:04:15 -0600 | [diff] [blame] | 199 | def FetchPinnedGuestImages(input_proto, output_proto): |
| 200 | """Get the pinned guest image information.""" |
| 201 | sysroot_path = input_proto.sysroot.path |
| 202 | if not sysroot_path: |
| 203 | cros_build_lib.Die('sysroot.path is required.') |
| 204 | |
| 205 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 206 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
| 207 | |
| 208 | if not chroot.exists(): |
| 209 | cros_build_lib.Die('Chroot does not exist: %s', chroot.path) |
| 210 | |
| 211 | if not sysroot.Exists(chroot=chroot): |
| 212 | cros_build_lib.Die('Sysroot does not exist: %s', |
| 213 | chroot.full_path(sysroot.path)) |
| 214 | |
| 215 | pins = artifacts.FetchPinnedGuestImages(chroot, sysroot) |
| 216 | |
| 217 | for pin in pins: |
| 218 | pinned_image = output_proto.pinned_images.add() |
| 219 | pinned_image.filename = pin.filename |
| 220 | pinned_image.uri = pin.uri |
| 221 | |
| 222 | |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 223 | @validate.require('output_dir', 'sysroot.path') |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 224 | def BundleFirmware(input_proto, output_proto): |
| 225 | """Tar the firmware images for a build target. |
| 226 | |
| 227 | Args: |
| 228 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 229 | output_proto (BundleResponse): The output proto. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 230 | """ |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 231 | output_dir = input_proto.output_dir |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 232 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 233 | sysroot_path = input_proto.sysroot.path |
| 234 | sysroot = sysroot_lib.Sysroot(sysroot_path) |
| 235 | archive = artifacts.BuildFirmwareArchive(chroot, sysroot, output_dir) |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 236 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 237 | if archive is None: |
| 238 | cros_build_lib.Die( |
Michael Mortensen | 3867519 | 2019-06-28 16:52:55 +0000 | [diff] [blame] | 239 | 'Could not create firmware archive. No firmware found for %s.', |
| 240 | sysroot_path) |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 241 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 242 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
| 243 | |
| 244 | |
| 245 | def BundleEbuildLogs(input_proto, output_proto): |
| 246 | """Tar the ebuild logs for a build target. |
| 247 | |
| 248 | Args: |
| 249 | input_proto (BundleRequest): The input proto. |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 250 | output_proto (BundleResponse): The output proto. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 251 | """ |
| 252 | target = input_proto.build_target.name |
| 253 | output_dir = input_proto.output_dir |
Evan Hernandez | a478d80 | 2019-04-08 15:08:24 -0600 | [diff] [blame] | 254 | |
| 255 | # commands.BuildEbuildLogsTarball conflates "buildroot" with sysroot. |
| 256 | # Adjust accordingly... |
| 257 | build_root = os.path.join(constants.SOURCE_ROOT, 'chroot', 'build') |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 258 | |
Alex Klein | e2612a0 | 2019-04-18 13:51:06 -0600 | [diff] [blame] | 259 | # TODO(crbug.com/954303): Replace with a chromite/service implementation. |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 260 | archive = commands.BuildEbuildLogsTarball(build_root, target, output_dir) |
| 261 | |
Evan Hernandez | 9a5d312 | 2019-04-09 10:51:23 -0600 | [diff] [blame] | 262 | if archive is None: |
| 263 | cros_build_lib.Die( |
| 264 | 'Could not create ebuild logs archive. No logs found for %s.', target) |
| 265 | |
Evan Hernandez | f388cbf | 2019-04-01 11:15:23 -0600 | [diff] [blame] | 266 | output_proto.artifacts.add().path = os.path.join(output_dir, archive) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 267 | |
| 268 | |
Alex Klein | 2275d69 | 2019-04-23 16:04:12 -0600 | [diff] [blame] | 269 | def BundleSimpleChromeArtifacts(input_proto, output_proto): |
| 270 | """Create the simple chrome artifacts.""" |
| 271 | # Required args. |
| 272 | sysroot_path = input_proto.sysroot.path |
| 273 | build_target_name = input_proto.sysroot.build_target.name |
| 274 | output_dir = input_proto.output_dir |
| 275 | |
| 276 | if not build_target_name: |
| 277 | cros_build_lib.Die('build_target.name is required') |
| 278 | if not output_dir: |
| 279 | cros_build_lib.Die('output_dir is required.') |
| 280 | if not os.path.exists(output_dir): |
| 281 | cros_build_lib.Die('output_dir (%s) does not exist.', output_dir) |
| 282 | if not sysroot_path: |
| 283 | cros_build_lib.Die('sysroot.path is required.') |
| 284 | |
| 285 | # Optional args. |
| 286 | chroot_path = input_proto.chroot.path or constants.DEFAULT_CHROOT_PATH |
| 287 | cache_dir = input_proto.chroot.cache_dir |
| 288 | |
| 289 | # Build out the argument instances. |
| 290 | build_target = build_target_util.BuildTarget(build_target_name) |
| 291 | chroot = chroot_lib.Chroot(path=chroot_path, cache_dir=cache_dir) |
| 292 | # Sysroot.path needs to be the fully qualified path, including the chroot. |
| 293 | full_sysroot_path = os.path.join(chroot.path, sysroot_path.lstrip(os.sep)) |
| 294 | sysroot = sysroot_lib.Sysroot(full_sysroot_path) |
| 295 | |
| 296 | # Quick sanity check that the sysroot exists before we go on. |
| 297 | if not sysroot.Exists(): |
| 298 | cros_build_lib.Die('The sysroot does not exist.') |
| 299 | |
| 300 | try: |
| 301 | results = artifacts.BundleSimpleChromeArtifacts(chroot, sysroot, |
| 302 | build_target, output_dir) |
| 303 | except artifacts.Error as e: |
| 304 | cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', |
| 305 | type(e), e) |
| 306 | |
| 307 | for file_name in results: |
| 308 | output_proto.artifacts.add().path = file_name |
| 309 | |
| 310 | |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 311 | @validate.require('chroot.path', 'sysroot.path', 'test_results_dir', |
| 312 | 'output_dir') |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 313 | def BundleVmFiles(input_proto, output_proto): |
| 314 | """Tar VM disk and memory files. |
| 315 | |
| 316 | Args: |
| 317 | input_proto (SysrootBundleRequest): The input proto. |
| 318 | output_proto (BundleResponse): The output proto. |
| 319 | """ |
| 320 | chroot = input_proto.chroot.path |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 321 | sysroot = input_proto.sysroot.path.lstrip(os.sep) |
| 322 | test_results_dir = input_proto.test_results_dir.lstrip(os.sep) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 323 | output_dir = input_proto.output_dir |
| 324 | |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 325 | # TODO(crbug.com/954344): Replace with a chromite/service implementation. |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 326 | image_dir = os.path.join(chroot, sysroot, test_results_dir) |
Alex Klein | 6504eca | 2019-04-18 15:37:56 -0600 | [diff] [blame] | 327 | archives = vm_test_stages.ArchiveVMFilesFromImageDir(image_dir, output_dir) |
| 328 | for archive in archives: |
| 329 | output_proto.artifacts.add().path = archive |
Tiancong Wang | c4805b7 | 2019-06-11 12:12:03 -0700 | [diff] [blame] | 330 | |
| 331 | def BundleOrderfileGenerationArtifacts(input_proto, output_proto): |
| 332 | """Create tarballs of all the artifacts of orderfile_generate builder. |
| 333 | |
| 334 | Args: |
| 335 | input_proto (BundleRequest): The input proto. |
| 336 | output_proto (BundleResponse): The output proto. |
| 337 | """ |
| 338 | # Required args. |
| 339 | build_target_name = input_proto.build_target.name |
| 340 | output_dir = input_proto.output_dir |
| 341 | chrome_version = input_proto.chrome_version |
| 342 | |
| 343 | if not build_target_name: |
| 344 | cros_build_lib.Die('build_target.name is required.') |
| 345 | if not chrome_version: |
| 346 | cros_build_lib.Die('chrome_version is required.') |
| 347 | if not output_dir: |
| 348 | cros_build_lib.Die('output_dir is required.') |
| 349 | elif not os.path.isdir(output_dir): |
| 350 | cros_build_lib.Die('output_dir does not exist.') |
| 351 | |
| 352 | chroot = controller_util.ParseChroot(input_proto.chroot) |
| 353 | |
| 354 | try: |
| 355 | results = artifacts.BundleOrderfileGenerationArtifacts( |
| 356 | chroot, input_proto.build_target, chrome_version, output_dir) |
| 357 | except artifacts.Error as e: |
| 358 | cros_build_lib.Die('Error %s raised in BundleSimpleChromeArtifacts: %s', |
| 359 | type(e), e) |
| 360 | |
| 361 | for file_name in results: |
| 362 | output_proto.artifacts.add().path = file_name |