Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [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 | """Sysroot controller.""" |
| 6 | |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 7 | import glob |
Chris McDonald | 1672ddb | 2021-07-21 11:48:23 -0600 | [diff] [blame] | 8 | import logging |
Michael Mortensen | 4ccfb08 | 2020-01-22 16:24:03 -0700 | [diff] [blame] | 9 | import os |
| 10 | |
Alex Klein | 8cb365a | 2019-05-15 16:24:53 -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 | a9d500b | 2019-04-22 15:37:51 -0600 | [diff] [blame] | 14 | from chromite.api.controller import controller_util |
Chris McDonald | 1672ddb | 2021-07-21 11:48:23 -0600 | [diff] [blame] | 15 | from chromite.api.gen.chromiumos import common_pb2 |
Will Bradley | 7e5b8c1 | 2019-07-30 12:44:15 -0600 | [diff] [blame] | 16 | from chromite.api.metrics import deserialize_metrics_log |
LaMont Jones | feffd1b | 2020-08-05 18:24:59 -0600 | [diff] [blame] | 17 | from chromite.lib import binpkg |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 18 | from chromite.lib import build_target_lib |
| 19 | from chromite.lib import chroot_lib |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 20 | from chromite.lib import cros_build_lib |
Michael Mortensen | 798ee19 | 2020-01-17 13:04:43 -0700 | [diff] [blame] | 21 | from chromite.lib import goma_lib |
Michael Mortensen | 3f6b4bd | 2020-02-07 14:16:43 -0700 | [diff] [blame] | 22 | from chromite.lib import osutils |
Alex Klein | a9d6460 | 2019-05-17 14:55:37 -0600 | [diff] [blame] | 23 | from chromite.lib import portage_util |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 24 | from chromite.lib import sysroot_lib |
| 25 | from chromite.service import sysroot |
Will Bradley | 7e5b8c1 | 2019-07-30 12:44:15 -0600 | [diff] [blame] | 26 | from chromite.utils import metrics |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 27 | |
Chris McDonald | 1672ddb | 2021-07-21 11:48:23 -0600 | [diff] [blame] | 28 | |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 29 | _ACCEPTED_LICENSES = '@CHROMEOS' |
| 30 | |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 31 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 32 | def ExampleGetResponse(): |
| 33 | """Give an example response to assemble upstream in caller artifacts.""" |
| 34 | uabs = common_pb2.UploadedArtifactsByService |
| 35 | cabs = common_pb2.ArtifactsByService |
| 36 | return uabs.Sysroot(artifacts=[ |
Lizzy Presland | b2d6064 | 2021-11-12 01:41:58 +0000 | [diff] [blame] | 37 | uabs.Sysroot.ArtifactPaths( |
George Engelbrecht | 35eeea4 | 2021-07-09 14:10:57 -0600 | [diff] [blame] | 38 | artifact_type=cabs.Sysroot.ArtifactType.SIMPLE_CHROME_SYSROOT, |
| 39 | paths=[ |
| 40 | common_pb2.Path( |
| 41 | path='/tmp/sysroot_chromeos-base_chromeos-chrome.tar.xz', |
| 42 | location=common_pb2.Path.OUTSIDE) |
| 43 | ], |
| 44 | ), |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 45 | uabs.Sysroot.ArtifactPaths( |
| 46 | artifact_type=cabs.Sysroot.ArtifactType.DEBUG_SYMBOLS, |
| 47 | paths=[ |
| 48 | common_pb2.Path( |
| 49 | path='/tmp/debug.tgz', location=common_pb2.Path.OUTSIDE) |
| 50 | ], |
| 51 | ), |
| 52 | uabs.Sysroot.ArtifactPaths( |
| 53 | artifact_type=cabs.Sysroot.ArtifactType.BREAKPAD_DEBUG_SYMBOLS, |
| 54 | paths=[ |
| 55 | common_pb2.Path( |
| 56 | path='/tmp/debug_breakpad.tar.xz', |
| 57 | location=common_pb2.Path.OUTSIDE) |
| 58 | ]) |
| 59 | ]) |
| 60 | |
| 61 | |
| 62 | def GetArtifacts(in_proto: common_pb2.ArtifactsByService.Sysroot, |
Lizzy Presland | b2d6064 | 2021-11-12 01:41:58 +0000 | [diff] [blame] | 63 | chroot: chroot_lib.Chroot, sysroot_class: sysroot_lib.Sysroot, |
| 64 | build_target: build_target_lib.BuildTarget, output_dir: str |
| 65 | ) -> list: |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 66 | """Builds and copies sysroot artifacts to specified output_dir. |
| 67 | |
| 68 | Copies sysroot artifacts to output_dir, returning a list of (output_dir: str) |
| 69 | paths to the desired files. |
| 70 | |
| 71 | Args: |
| 72 | in_proto: Proto request defining reqs. |
| 73 | chroot: The chroot class used for these artifacts. |
| 74 | sysroot_class: The sysroot class used for these artifacts. |
| 75 | build_target: The build target used for these artifacts. |
| 76 | output_dir: The path to write artifacts to. |
| 77 | |
| 78 | Returns: |
| 79 | A list of dictionary mappings of ArtifactType to list of paths. |
| 80 | """ |
| 81 | generated = [] |
Jack Neus | 5e56fef | 2021-06-18 16:57:28 +0000 | [diff] [blame] | 82 | artifact_types = { |
Lizzy Presland | b2d6064 | 2021-11-12 01:41:58 +0000 | [diff] [blame] | 83 | in_proto.ArtifactType.SIMPLE_CHROME_SYSROOT: |
| 84 | sysroot.CreateSimpleChromeSysroot, |
| 85 | in_proto.ArtifactType.CHROME_EBUILD_ENV: sysroot.CreateChromeEbuildEnv, |
| 86 | in_proto.ArtifactType.BREAKPAD_DEBUG_SYMBOLS: |
| 87 | sysroot.BundleBreakpadSymbols, |
| 88 | in_proto.ArtifactType.DEBUG_SYMBOLS: sysroot.BundleDebugSymbols, |
Jack Neus | 5e56fef | 2021-06-18 16:57:28 +0000 | [diff] [blame] | 89 | } |
| 90 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 91 | for output_artifact in in_proto.output_artifacts: |
Jack Neus | 5e56fef | 2021-06-18 16:57:28 +0000 | [diff] [blame] | 92 | for artifact_type, func in artifact_types.items(): |
| 93 | if artifact_type in output_artifact.artifact_types: |
| 94 | result = func(chroot, sysroot_class, build_target, output_dir) |
| 95 | if result: |
| 96 | generated.append({ |
| 97 | 'paths': [result] if isinstance(result, str) else result, |
| 98 | 'type': artifact_type, |
| 99 | }) |
| 100 | |
George Engelbrecht | c9a8e81 | 2021-06-16 18:14:17 -0600 | [diff] [blame] | 101 | return generated |
| 102 | |
| 103 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 104 | @faux.all_empty |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 105 | @validate.require('build_target.name') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 106 | @validate.validation_complete |
| 107 | def Create(input_proto, output_proto, _config): |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 108 | """Create or replace a sysroot.""" |
| 109 | update_chroot = not input_proto.flags.chroot_current |
| 110 | replace_sysroot = input_proto.flags.replace |
| 111 | |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 112 | build_target = controller_util.ParseBuildTarget(input_proto.build_target, |
| 113 | input_proto.profile) |
LaMont Jones | feffd1b | 2020-08-05 18:24:59 -0600 | [diff] [blame] | 114 | package_indexes = [ |
| 115 | binpkg.PackageIndexInfo.from_protobuf(x) |
| 116 | for x in input_proto.package_indexes |
| 117 | ] |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 118 | run_configs = sysroot.SetupBoardRunConfig( |
LaMont Jones | feffd1b | 2020-08-05 18:24:59 -0600 | [diff] [blame] | 119 | force=replace_sysroot, upgrade_chroot=update_chroot, |
| 120 | package_indexes=package_indexes) |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 121 | |
| 122 | try: |
| 123 | created = sysroot.Create(build_target, run_configs, |
| 124 | accept_licenses=_ACCEPTED_LICENSES) |
| 125 | except sysroot.Error as e: |
Mike Frysinger | 6b5c3cd | 2019-08-27 16:51:00 -0400 | [diff] [blame] | 126 | cros_build_lib.Die(e) |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 127 | |
| 128 | output_proto.sysroot.path = created.path |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 129 | output_proto.sysroot.build_target.name = build_target.name |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 130 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 131 | return controller.RETURN_CODE_SUCCESS |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 132 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 133 | |
Michael Mortensen | 98592f6 | 2019-09-27 13:34:18 -0600 | [diff] [blame] | 134 | @faux.all_empty |
Michael Mortensen | 3f6b4bd | 2020-02-07 14:16:43 -0700 | [diff] [blame] | 135 | @validate.require('build_target.name', 'packages') |
Alex Klein | 45b7343 | 2020-09-23 13:51:20 -0600 | [diff] [blame] | 136 | @validate.require_each('packages', ['category', 'package_name']) |
Michael Mortensen | 3f6b4bd | 2020-02-07 14:16:43 -0700 | [diff] [blame] | 137 | @validate.validation_complete |
| 138 | def GenerateArchive(input_proto, output_proto, _config): |
| 139 | """Generate a sysroot. Typically used by informational builders.""" |
| 140 | build_target_name = input_proto.build_target.name |
| 141 | pkg_list = [] |
| 142 | for package in input_proto.packages: |
| 143 | pkg_list.append('%s/%s' % (package.category, package.package_name)) |
| 144 | |
| 145 | with osutils.TempDir(delete=False) as temp_output_dir: |
| 146 | sysroot_tar_path = sysroot.GenerateArchive(temp_output_dir, |
| 147 | build_target_name, |
| 148 | pkg_list) |
| 149 | |
| 150 | # By assigning this Path variable to the tar path, the tar file will be |
| 151 | # copied out to the input_proto's ResultPath location. |
| 152 | output_proto.sysroot_archive.path = sysroot_tar_path |
Alex Klein | 6b499df | 2020-11-19 14:26:56 -0700 | [diff] [blame] | 153 | output_proto.sysroot_archive.location = common_pb2.Path.INSIDE |
Michael Mortensen | 3f6b4bd | 2020-02-07 14:16:43 -0700 | [diff] [blame] | 154 | |
| 155 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 156 | def _MockFailedPackagesResponse(_input_proto, output_proto, _config): |
| 157 | """Mock error response that populates failed packages.""" |
| 158 | pkg = output_proto.failed_packages.add() |
| 159 | pkg.package_name = 'package' |
| 160 | pkg.category = 'category' |
| 161 | pkg.version = '1.0.0_rc-r1' |
| 162 | |
| 163 | pkg2 = output_proto.failed_packages.add() |
| 164 | pkg2.package_name = 'bar' |
| 165 | pkg2.category = 'foo' |
| 166 | pkg2.version = '3.7-r99' |
| 167 | |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 168 | fail = output_proto.failed_package_data.add() |
| 169 | fail.name.package_name = 'package' |
| 170 | fail.name.category = 'category' |
| 171 | fail.name.version = '1.0.0_rc-r1' |
| 172 | fail.log_path.path = '/path/to/package:category-1.0.0_rc-r1:20210609-1337.log' |
| 173 | fail.log_path.location = common_pb2.Path.INSIDE |
| 174 | |
| 175 | fail2 = output_proto.failed_package_data.add() |
| 176 | fail2.name.package_name = 'bar' |
| 177 | fail2.name.category = 'foo' |
| 178 | fail2.name.version = '3.7-r99' |
| 179 | fail2.log_path.path = '/path/to/foo:bar-3.7-r99:20210609-1620.log' |
| 180 | fail2.log_path.location = common_pb2.Path.INSIDE |
| 181 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 182 | |
| 183 | @faux.empty_success |
| 184 | @faux.error(_MockFailedPackagesResponse) |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 185 | @validate.require('sysroot.path', 'sysroot.build_target.name') |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 186 | @validate.exists('sysroot.path') |
| 187 | @validate.validation_complete |
| 188 | def InstallToolchain(input_proto, output_proto, _config): |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 189 | """Install the toolchain into a sysroot.""" |
Chris McDonald | 68faa2a | 2020-01-13 12:23:05 -0700 | [diff] [blame] | 190 | compile_source = ( |
| 191 | input_proto.flags.compile_source or input_proto.flags.toolchain_changed) |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 192 | |
| 193 | sysroot_path = input_proto.sysroot.path |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 194 | |
Alex Klein | 26e472b | 2020-03-10 14:35:01 -0600 | [diff] [blame] | 195 | build_target = controller_util.ParseBuildTarget( |
| 196 | input_proto.sysroot.build_target) |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 197 | target_sysroot = sysroot_lib.Sysroot(sysroot_path) |
Alex Klein | 6682ae1 | 2019-06-25 13:50:32 -0600 | [diff] [blame] | 198 | run_configs = sysroot.SetupBoardRunConfig(usepkg=not compile_source) |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 199 | |
Alex Klein | a9d6460 | 2019-05-17 14:55:37 -0600 | [diff] [blame] | 200 | _LogBinhost(build_target.name) |
| 201 | |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 202 | try: |
| 203 | sysroot.InstallToolchain(build_target, target_sysroot, run_configs) |
| 204 | except sysroot_lib.ToolchainInstallError as e: |
| 205 | # Error installing - populate the failed package info. |
Alex Klein | ea0c89e | 2021-09-09 15:17:35 -0600 | [diff] [blame] | 206 | for pkg_info in e.failed_toolchain_info: |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 207 | # TODO(b/206514844): remove when field is deleted |
Alex Klein | ea0c89e | 2021-09-09 15:17:35 -0600 | [diff] [blame] | 208 | package_info_msg = output_proto.failed_packages.add() |
| 209 | controller_util.serialize_package_info(pkg_info, package_info_msg) |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 210 | # Grab the paths to the log files for each failed package from the |
| 211 | # sysroot. |
| 212 | # Logs currently exist within the sysroot in the form of: |
| 213 | # /build/${BOARD}/tmp/portage/logs/$CATEGORY:$PF:$TIMESTAMP.log |
| 214 | failed_pkg_data_msg = output_proto.failed_package_data.add() |
| 215 | controller_util.serialize_package_info(pkg_info, failed_pkg_data_msg.name) |
Lizzy Presland | 4c27983 | 2021-11-19 20:27:43 +0000 | [diff] [blame] | 216 | glob_path = os.path.join(target_sysroot.portage_logdir, |
Lizzy Presland | 7774178 | 2021-12-13 19:46:42 +0000 | [diff] [blame] | 217 | f'{pkg_info.category}:{pkg_info.pvr}:*.log') |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 218 | log_files = glob.glob(glob_path) |
| 219 | log_files.sort(reverse=True) |
| 220 | # Omit path if files don't exist for some reason |
| 221 | if not log_files: |
Lizzy Presland | 7774178 | 2021-12-13 19:46:42 +0000 | [diff] [blame] | 222 | logging.warning('Log file for %s was not found. Search path: %s', |
| 223 | pkg_info.cpvr, glob_path) |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 224 | continue |
| 225 | failed_pkg_data_msg.log_path.path = log_files[0] |
| 226 | failed_pkg_data_msg.log_path.location = common_pb2.Path.INSIDE |
Alex Klein | da35fcf | 2019-03-07 16:01:15 -0700 | [diff] [blame] | 227 | |
Alex Klein | 8cb365a | 2019-05-15 16:24:53 -0600 | [diff] [blame] | 228 | return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 229 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 230 | return controller.RETURN_CODE_SUCCESS |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 231 | |
Alex Klein | 076841b | 2019-08-29 15:19:39 -0600 | [diff] [blame] | 232 | |
| 233 | @faux.empty_success |
| 234 | @faux.error(_MockFailedPackagesResponse) |
Alex Klein | 566d80e | 2019-09-24 12:27:58 -0600 | [diff] [blame] | 235 | @validate.require('sysroot.build_target.name') |
| 236 | @validate.exists('sysroot.path') |
Alex Klein | 45b7343 | 2020-09-23 13:51:20 -0600 | [diff] [blame] | 237 | @validate.require_each('packages', ['category', 'package_name']) |
| 238 | @validate.require_each('use_flags', ['flag']) |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 239 | @validate.validation_complete |
Will Bradley | 7e5b8c1 | 2019-07-30 12:44:15 -0600 | [diff] [blame] | 240 | @metrics.collect_metrics |
Alex Klein | 231d2da | 2019-07-22 16:44:45 -0600 | [diff] [blame] | 241 | def InstallPackages(input_proto, output_proto, _config): |
Alex Klein | 2b23672 | 2019-06-19 15:44:26 -0600 | [diff] [blame] | 242 | """Install packages into a sysroot, building as necessary and permitted.""" |
Chris McDonald | 68faa2a | 2020-01-13 12:23:05 -0700 | [diff] [blame] | 243 | compile_source = ( |
| 244 | input_proto.flags.compile_source or input_proto.flags.toolchain_changed) |
Joanna Wang | 1ec0c81 | 2021-11-17 17:41:27 -0800 | [diff] [blame] | 245 | |
Joanna Wang | f773c1b | 2021-12-09 11:46:44 -0800 | [diff] [blame] | 246 | use_remoteexec = bool(input_proto.remoteexec_config.reproxy_cfg_file and |
| 247 | input_proto.remoteexec_config.reclient_dir) |
Joanna Wang | 1ec0c81 | 2021-11-17 17:41:27 -0800 | [diff] [blame] | 248 | |
LaMont Jones | 6dc755b | 2020-07-17 12:06:29 -0600 | [diff] [blame] | 249 | # Testing if Goma will support unknown compilers now. |
Joanna Wang | 1ec0c81 | 2021-11-17 17:41:27 -0800 | [diff] [blame] | 250 | use_goma = input_proto.flags.use_goma and not use_remoteexec |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 251 | |
Alex Klein | 566d80e | 2019-09-24 12:27:58 -0600 | [diff] [blame] | 252 | target_sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path) |
| 253 | build_target = controller_util.ParseBuildTarget( |
| 254 | input_proto.sysroot.build_target) |
Alex Klein | ca572ee | 2020-09-03 10:47:14 -0600 | [diff] [blame] | 255 | |
| 256 | # Get the package atom for each specified package. The field is optional, so |
| 257 | # error only when we cannot parse an atom for each of the given packages. |
| 258 | packages = [controller_util.PackageInfoToCPV(x).cp |
Mike Frysinger | 66ce413 | 2019-07-17 22:52:52 -0400 | [diff] [blame] | 259 | for x in input_proto.packages] |
Alex Klein | ca572ee | 2020-09-03 10:47:14 -0600 | [diff] [blame] | 260 | |
LaMont Jones | feffd1b | 2020-08-05 18:24:59 -0600 | [diff] [blame] | 261 | package_indexes = [ |
| 262 | binpkg.PackageIndexInfo.from_protobuf(x) |
| 263 | for x in input_proto.package_indexes |
| 264 | ] |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 265 | |
Navil Perez | 5766d1b | 2021-05-26 17:38:15 +0000 | [diff] [blame] | 266 | # Calculate which packages would have been merged, but don't install anything. |
| 267 | dryrun = input_proto.flags.dryrun |
| 268 | |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 269 | if not target_sysroot.IsToolchainInstalled(): |
| 270 | cros_build_lib.Die('Toolchain must first be installed.') |
| 271 | |
Alex Klein | a9d6460 | 2019-05-17 14:55:37 -0600 | [diff] [blame] | 272 | _LogBinhost(build_target.name) |
| 273 | |
Alex Klein | be0bae4 | 2019-05-06 13:01:49 -0600 | [diff] [blame] | 274 | use_flags = [u.flag for u in input_proto.use_flags] |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 275 | build_packages_config = sysroot.BuildPackagesRunConfig( |
Alex Klein | 566d80e | 2019-09-24 12:27:58 -0600 | [diff] [blame] | 276 | usepkg=not compile_source, |
| 277 | install_debug_symbols=True, |
| 278 | packages=packages, |
LaMont Jones | feffd1b | 2020-08-05 18:24:59 -0600 | [diff] [blame] | 279 | package_indexes=package_indexes, |
Alex Klein | 566d80e | 2019-09-24 12:27:58 -0600 | [diff] [blame] | 280 | use_flags=use_flags, |
Alex Klein | 5b94048 | 2019-12-26 10:38:39 -0700 | [diff] [blame] | 281 | use_goma=use_goma, |
Joanna Wang | 1ec0c81 | 2021-11-17 17:41:27 -0800 | [diff] [blame] | 282 | use_remoteexec=use_remoteexec, |
Alex Klein | eb76da7 | 2021-03-19 10:43:09 -0600 | [diff] [blame] | 283 | incremental_build=False, |
Navil Perez | 5766d1b | 2021-05-26 17:38:15 +0000 | [diff] [blame] | 284 | setup_board=False, |
| 285 | dryrun=dryrun) |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 286 | |
| 287 | try: |
| 288 | sysroot.BuildPackages(build_target, target_sysroot, build_packages_config) |
| 289 | except sysroot_lib.PackageInstallError as e: |
Alex Klein | 2557b4f | 2019-07-11 14:34:00 -0600 | [diff] [blame] | 290 | if not e.failed_packages: |
| 291 | # No packages to report, so just exit with an error code. |
| 292 | return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY |
| 293 | |
| 294 | # We need to report the failed packages. |
Alex Klein | ea0c89e | 2021-09-09 15:17:35 -0600 | [diff] [blame] | 295 | for pkg_info in e.failed_packages: |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 296 | # TODO(b/206514844): remove when field is deleted |
Alex Klein | ea0c89e | 2021-09-09 15:17:35 -0600 | [diff] [blame] | 297 | package_info_msg = output_proto.failed_packages.add() |
| 298 | controller_util.serialize_package_info(pkg_info, package_info_msg) |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 299 | # Grab the paths to the log files for each failed package from the |
| 300 | # sysroot. |
| 301 | # Logs currently exist within the sysroot in the form of: |
| 302 | # /build/${BOARD}/tmp/portage/logs/$CATEGORY:$PF:$TIMESTAMP.log |
| 303 | failed_pkg_data_msg = output_proto.failed_package_data.add() |
| 304 | controller_util.serialize_package_info(pkg_info, failed_pkg_data_msg.name) |
Lizzy Presland | 4c27983 | 2021-11-19 20:27:43 +0000 | [diff] [blame] | 305 | glob_path = os.path.join(target_sysroot.portage_logdir, |
Lizzy Presland | 7774178 | 2021-12-13 19:46:42 +0000 | [diff] [blame] | 306 | f'{pkg_info.category}:{pkg_info.pvr}:*.log') |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 307 | log_files = glob.glob(glob_path) |
| 308 | log_files.sort(reverse=True) |
| 309 | # Omit path if files don't exist for some reason |
| 310 | if not log_files: |
Lizzy Presland | 7774178 | 2021-12-13 19:46:42 +0000 | [diff] [blame] | 311 | logging.warning('Log file for %s was not found. Search path: %s', |
| 312 | pkg_info.cpvr, glob_path) |
Lizzy Presland | 7e23a61 | 2021-11-09 21:49:42 +0000 | [diff] [blame] | 313 | continue |
| 314 | failed_pkg_data_msg.log_path.path = log_files[0] |
| 315 | failed_pkg_data_msg.log_path.location = common_pb2.Path.INSIDE |
Alex Klein | d4e1e42 | 2019-03-18 16:00:41 -0600 | [diff] [blame] | 316 | |
Alex Klein | 8cb365a | 2019-05-15 16:24:53 -0600 | [diff] [blame] | 317 | return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE |
Yoshiki Iguchi | 6d2e305 | 2021-12-13 11:06:04 +0900 | [diff] [blame] | 318 | finally: |
| 319 | # Copy goma logs to specified directory if there is a goma_config and |
| 320 | # it contains a log_dir to store artifacts. |
| 321 | if input_proto.goma_config.log_dir.dir: |
| 322 | # Get the goma log directory based on the GLOG_log_dir env variable. |
| 323 | # TODO(crbug.com/1045001): Replace environment variable with query to |
| 324 | # goma object after goma refactoring allows this. |
| 325 | log_source_dir = os.getenv('GLOG_log_dir') |
| 326 | if not log_source_dir: |
| 327 | cros_build_lib.Die('GLOG_log_dir must be defined.') |
| 328 | archiver = goma_lib.LogsArchiver( |
| 329 | log_source_dir, |
| 330 | dest_dir=input_proto.goma_config.log_dir.dir, |
| 331 | stats_file=input_proto.goma_config.stats_file, |
| 332 | counterz_file=input_proto.goma_config.counterz_file) |
| 333 | archiver_tuple = archiver.Archive() |
| 334 | if archiver_tuple.stats_file: |
| 335 | output_proto.goma_artifacts.stats_file = archiver_tuple.stats_file |
| 336 | if archiver_tuple.counterz_file: |
| 337 | output_proto.goma_artifacts.counterz_file = archiver_tuple.counterz_file |
| 338 | output_proto.goma_artifacts.log_files[:] = archiver_tuple.log_files |
Alex Klein | a9d6460 | 2019-05-17 14:55:37 -0600 | [diff] [blame] | 339 | |
Navil Perez | 5766d1b | 2021-05-26 17:38:15 +0000 | [diff] [blame] | 340 | # Return without populating the response if it is a dryrun. |
| 341 | if dryrun: |
| 342 | return controller.RETURN_CODE_SUCCESS |
| 343 | |
Will Bradley | 7e5b8c1 | 2019-07-30 12:44:15 -0600 | [diff] [blame] | 344 | # Read metric events log and pipe them into output_proto.events. |
Alex Klein | 566d80e | 2019-09-24 12:27:58 -0600 | [diff] [blame] | 345 | deserialize_metrics_log(output_proto.events, prefix=build_target.name) |
Will Bradley | 7e5b8c1 | 2019-07-30 12:44:15 -0600 | [diff] [blame] | 346 | |
Alex Klein | a9d6460 | 2019-05-17 14:55:37 -0600 | [diff] [blame] | 347 | |
| 348 | def _LogBinhost(board): |
| 349 | """Log the portage binhost for the given board.""" |
| 350 | binhost = portage_util.PortageqEnvvar('PORTAGE_BINHOST', board=board, |
| 351 | allow_undefined=True) |
| 352 | if not binhost: |
| 353 | logging.warning('Portage Binhost not found.') |
| 354 | else: |
| 355 | logging.info('Portage Binhost: %s', binhost) |