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