blob: 1b74b7b53e8a42292c0b1d983dcf373edd623c5e [file] [log] [blame]
Mike Frysingerf1ba7ad2022-09-12 05:42:57 -04001# Copyright 2019 The ChromiumOS Authors
Alex Kleinda35fcf2019-03-07 16:01:15 -07002# 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 McDonald1672ddb2021-07-21 11:48:23 -06007import logging
Michael Mortensen4ccfb082020-01-22 16:24:03 -07008import os
Yoshiki Iguchi0951e112023-08-21 16:31:25 +09009from pathlib import Path
Jack Neus26b94672022-10-27 17:33:21 +000010import traceback
Michael Mortensen4ccfb082020-01-22 16:24:03 -070011
Alex Klein8cb365a2019-05-15 16:24:53 -060012from chromite.api import controller
Alex Klein076841b2019-08-29 15:19:39 -060013from chromite.api import faux
Alex Klein2b236722019-06-19 15:44:26 -060014from chromite.api import validate
Alex Kleina9d500b2019-04-22 15:37:51 -060015from chromite.api.controller import controller_util
Chris McDonald1672ddb2021-07-21 11:48:23 -060016from chromite.api.gen.chromiumos import common_pb2
Will Bradley7e5b8c12019-07-30 12:44:15 -060017from chromite.api.metrics import deserialize_metrics_log
George Engelbrechtc9a8e812021-06-16 18:14:17 -060018from chromite.lib import build_target_lib
19from chromite.lib import chroot_lib
Alex Kleinda35fcf2019-03-07 16:01:15 -070020from chromite.lib import cros_build_lib
Michael Mortensen798ee192020-01-17 13:04:43 -070021from chromite.lib import goma_lib
Alex Kleinaef41942022-04-19 14:13:17 -060022from chromite.lib import metrics_lib
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -070023from chromite.lib import osutils
Alex Kleina9d64602019-05-17 14:55:37 -060024from chromite.lib import portage_util
Yoshiki Iguchi0951e112023-08-21 16:31:25 +090025from chromite.lib import remoteexec_lib
Alex Kleinda35fcf2019-03-07 16:01:15 -070026from chromite.lib import sysroot_lib
27from chromite.service import sysroot
28
Chris McDonald1672ddb2021-07-21 11:48:23 -060029
Alex Klein1699fab2022-09-08 08:46:06 -060030_ACCEPTED_LICENSES = "@CHROMEOS"
Alex Kleinda35fcf2019-03-07 16:01:15 -070031
Sergey Frolovb4f41482023-08-31 22:33:53 +000032DEFAULT_BACKTRACK = 30
Alex Kleineaa48532022-07-28 08:51:32 -060033
Alex Kleind4e1e422019-03-18 16:00:41 -060034
Yoshiki Iguchia43704b2021-12-16 13:31:48 +090035def _GetGomaLogDirectory():
Alex Klein1699fab2022-09-08 08:46:06 -060036 """Get goma's log directory based on the env variables.
Yoshiki Iguchia43704b2021-12-16 13:31:48 +090037
Alex Klein1699fab2022-09-08 08:46:06 -060038 Returns:
Alex Klein611dddd2022-10-11 17:02:01 -060039 a string of a directory name where goma's log may exist, or None if no
40 potential directories exist.
Alex Klein1699fab2022-09-08 08:46:06 -060041 """
42 # TODO(crbug.com/1045001): Replace environment variable with query to
43 # goma object after goma refactoring allows this.
44 candidates = [
45 "GLOG_log_dir",
46 "GOOGLE_LOG_DIR",
47 "TEST_TMPDIR",
48 "TMPDIR",
49 "TMP",
50 ]
51 for candidate in candidates:
52 value = os.environ.get(candidate)
53 if value and os.path.isdir(value):
54 return value
Yoshiki Iguchia43704b2021-12-16 13:31:48 +090055
Alex Klein1699fab2022-09-08 08:46:06 -060056 # "/tmp" will always exist.
57 return "/tmp"
Yoshiki Iguchia43704b2021-12-16 13:31:48 +090058
59
George Engelbrechtc9a8e812021-06-16 18:14:17 -060060def ExampleGetResponse():
Alex Klein1699fab2022-09-08 08:46:06 -060061 """Give an example response to assemble upstream in caller artifacts."""
62 uabs = common_pb2.UploadedArtifactsByService
63 cabs = common_pb2.ArtifactsByService
64 return uabs.Sysroot(
65 artifacts=[
66 uabs.Sysroot.ArtifactPaths(
67 artifact_type=cabs.Sysroot.ArtifactType.SIMPLE_CHROME_SYSROOT,
68 paths=[
69 common_pb2.Path(
Alex Kleinab87ceb2023-01-24 12:00:51 -070070 path=(
71 "/tmp/sysroot_chromeos-base_chromeos-chrome.tar.xz"
72 ),
Alex Klein1699fab2022-09-08 08:46:06 -060073 location=common_pb2.Path.OUTSIDE,
74 )
75 ],
76 ),
77 uabs.Sysroot.ArtifactPaths(
78 artifact_type=cabs.Sysroot.ArtifactType.DEBUG_SYMBOLS,
79 paths=[
80 common_pb2.Path(
81 path="/tmp/debug.tgz", location=common_pb2.Path.OUTSIDE
82 )
83 ],
84 ),
85 uabs.Sysroot.ArtifactPaths(
86 artifact_type=cabs.Sysroot.ArtifactType.BREAKPAD_DEBUG_SYMBOLS,
87 paths=[
88 common_pb2.Path(
89 path="/tmp/debug_breakpad.tar.xz",
90 location=common_pb2.Path.OUTSIDE,
91 )
92 ],
93 ),
94 ]
95 )
George Engelbrechtc9a8e812021-06-16 18:14:17 -060096
97
Alex Klein1699fab2022-09-08 08:46:06 -060098def GetArtifacts(
99 in_proto: common_pb2.ArtifactsByService.Sysroot,
100 chroot: chroot_lib.Chroot,
101 sysroot_class: sysroot_lib.Sysroot,
102 build_target: build_target_lib.BuildTarget,
103 output_dir: str,
104) -> list:
105 """Builds and copies sysroot artifacts to specified output_dir.
George Engelbrechtc9a8e812021-06-16 18:14:17 -0600106
Alex Kleinab87ceb2023-01-24 12:00:51 -0700107 Copies sysroot artifacts to output_dir, returning a list of
108 (output_dir: str) paths to the desired files.
George Engelbrechtc9a8e812021-06-16 18:14:17 -0600109
Alex Klein1699fab2022-09-08 08:46:06 -0600110 Args:
Alex Klein611dddd2022-10-11 17:02:01 -0600111 in_proto: Proto request defining reqs.
112 chroot: The chroot class used for these artifacts.
113 sysroot_class: The sysroot class used for these artifacts.
114 build_target: The build target used for these artifacts.
115 output_dir: The path to write artifacts to.
George Engelbrechtc9a8e812021-06-16 18:14:17 -0600116
Alex Klein1699fab2022-09-08 08:46:06 -0600117 Returns:
Alex Klein611dddd2022-10-11 17:02:01 -0600118 A list of dictionary mappings of ArtifactType to list of paths.
Alex Klein1699fab2022-09-08 08:46:06 -0600119 """
Ian Barkley-Yeungb5274442023-04-28 16:32:20 -0700120
121 def _BundleBreakpadSymbols(chroot, sysroot_class, build_target, output_dir):
Alex Klein1bdd1ed2023-06-15 15:25:32 -0600122 # pylint: disable=line-too-long
Ian Barkley-Yeungb5274442023-04-28 16:32:20 -0700123 ignore_breakpad_symbol_generation_expected_files = [
124 common_pb2.ArtifactsByService.Sysroot.BreakpadSymbolGenerationExpectedFile.Name(
125 x
126 )
127 for x in in_proto.ignore_breakpad_symbol_generation_expected_files
128 if x
129 != common_pb2.ArtifactsByService.Sysroot.BreakpadSymbolGenerationExpectedFile.EXPECTED_FILE_UNSET
130 and x
131 in common_pb2.ArtifactsByService.Sysroot.BreakpadSymbolGenerationExpectedFile.values()
132 ]
Alex Klein1bdd1ed2023-06-15 15:25:32 -0600133 # pylint: enable=line-too-long
Ian Barkley-Yeungb5274442023-04-28 16:32:20 -0700134
135 ignore_breakpad_symbol_generation_expected_files = [
136 x[len("EXPECTED_FILE_") :]
137 for x in ignore_breakpad_symbol_generation_expected_files
138 ]
139
140 return sysroot.BundleBreakpadSymbols(
141 chroot,
142 sysroot_class,
143 build_target,
144 output_dir,
145 in_proto.ignore_breakpad_symbol_generation_errors,
146 ignore_breakpad_symbol_generation_expected_files,
147 )
148
Alex Klein1699fab2022-09-08 08:46:06 -0600149 generated = []
Alex Kleinab87ceb2023-01-24 12:00:51 -0700150 # pylint: disable=line-too-long
Alex Klein1699fab2022-09-08 08:46:06 -0600151 artifact_types = {
152 in_proto.ArtifactType.SIMPLE_CHROME_SYSROOT: sysroot.CreateSimpleChromeSysroot,
153 in_proto.ArtifactType.CHROME_EBUILD_ENV: sysroot.CreateChromeEbuildEnv,
Ian Barkley-Yeungb5274442023-04-28 16:32:20 -0700154 in_proto.ArtifactType.BREAKPAD_DEBUG_SYMBOLS: _BundleBreakpadSymbols,
Alex Klein1699fab2022-09-08 08:46:06 -0600155 in_proto.ArtifactType.DEBUG_SYMBOLS: sysroot.BundleDebugSymbols,
Jack Neus11b6ebd2022-10-21 17:54:36 +0000156 in_proto.ArtifactType.FUZZER_SYSROOT: sysroot.CreateFuzzerSysroot,
Ram Chandrasekar5ba36b22023-03-20 16:10:48 -0600157 in_proto.ArtifactType.SYSROOT_ARCHIVE: sysroot.ArchiveSysroot,
Alex Klein1699fab2022-09-08 08:46:06 -0600158 }
Alex Kleinab87ceb2023-01-24 12:00:51 -0700159 # pylint: enable=line-too-long
Jack Neus5e56fef2021-06-18 16:57:28 +0000160
Alex Klein1699fab2022-09-08 08:46:06 -0600161 for output_artifact in in_proto.output_artifacts:
162 for artifact_type, func in artifact_types.items():
163 if artifact_type in output_artifact.artifact_types:
Jack Neus26b94672022-10-27 17:33:21 +0000164 try:
165 result = func(
166 chroot, sysroot_class, build_target, output_dir
167 )
168 except Exception as e:
169 generated.append(
170 {
171 "type": artifact_type,
172 "failed": True,
173 "failure_reason": str(e),
174 }
175 )
176 artifact_name = (
177 common_pb2.ArtifactsByService.Sysroot.ArtifactType.Name(
178 artifact_type
179 )
180 )
181 logging.warning(
182 "%s artifact generation failed with exception %s",
183 artifact_name,
184 e,
185 )
186 logging.warning("traceback:\n%s", traceback.format_exc())
187 continue
Alex Klein1699fab2022-09-08 08:46:06 -0600188 if result:
189 generated.append(
190 {
Ram Chandrasekar5ba36b22023-03-20 16:10:48 -0600191 "paths": [str(result)]
192 if isinstance(result, (os.PathLike, str))
Alex Klein1699fab2022-09-08 08:46:06 -0600193 else result,
194 "type": artifact_type,
195 }
196 )
Jack Neus5e56fef2021-06-18 16:57:28 +0000197
Alex Klein1699fab2022-09-08 08:46:06 -0600198 return generated
George Engelbrechtc9a8e812021-06-16 18:14:17 -0600199
200
Alex Klein076841b2019-08-29 15:19:39 -0600201@faux.all_empty
Alex Klein1699fab2022-09-08 08:46:06 -0600202@validate.require("build_target.name")
Alex Klein231d2da2019-07-22 16:44:45 -0600203@validate.validation_complete
204def Create(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600205 """Create or replace a sysroot."""
206 update_chroot = not input_proto.flags.chroot_current
207 replace_sysroot = input_proto.flags.replace
Yoshiki Iguchi2f7f0222023-05-17 19:30:09 +0900208 use_cq_prebuilts = input_proto.flags.use_cq_prebuilts
Alex Kleinda35fcf2019-03-07 16:01:15 -0700209
Alex Klein1699fab2022-09-08 08:46:06 -0600210 build_target = controller_util.ParseBuildTarget(
211 input_proto.build_target, input_proto.profile
212 )
213 package_indexes = [
Alex Klein6d718d62023-01-18 15:55:51 -0700214 controller_util.deserialize_package_index_info(x)
Alex Klein1699fab2022-09-08 08:46:06 -0600215 for x in input_proto.package_indexes
216 ]
217 run_configs = sysroot.SetupBoardRunConfig(
218 force=replace_sysroot,
219 upgrade_chroot=update_chroot,
220 package_indexes=package_indexes,
Yoshiki Iguchi2f7f0222023-05-17 19:30:09 +0900221 use_cq_prebuilts=use_cq_prebuilts,
Alex Klein1699fab2022-09-08 08:46:06 -0600222 backtrack=DEFAULT_BACKTRACK,
223 )
Alex Kleinda35fcf2019-03-07 16:01:15 -0700224
Alex Klein1699fab2022-09-08 08:46:06 -0600225 try:
226 created = sysroot.Create(
227 build_target, run_configs, accept_licenses=_ACCEPTED_LICENSES
228 )
229 except sysroot.Error as e:
230 cros_build_lib.Die(e)
Alex Kleinda35fcf2019-03-07 16:01:15 -0700231
Alex Klein1699fab2022-09-08 08:46:06 -0600232 output_proto.sysroot.path = created.path
233 output_proto.sysroot.build_target.name = build_target.name
Alex Kleinda35fcf2019-03-07 16:01:15 -0700234
Alex Klein1699fab2022-09-08 08:46:06 -0600235 return controller.RETURN_CODE_SUCCESS
Alex Kleinda35fcf2019-03-07 16:01:15 -0700236
Alex Klein076841b2019-08-29 15:19:39 -0600237
Michael Mortensen98592f62019-09-27 13:34:18 -0600238@faux.all_empty
Alex Klein1699fab2022-09-08 08:46:06 -0600239@validate.require("build_target.name", "packages")
240@validate.require_each("packages", ["category", "package_name"])
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -0700241@validate.validation_complete
242def GenerateArchive(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600243 """Generate a sysroot. Typically used by informational builders."""
244 build_target_name = input_proto.build_target.name
245 pkg_list = []
246 for package in input_proto.packages:
247 pkg_list.append("%s/%s" % (package.category, package.package_name))
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -0700248
Alex Klein1699fab2022-09-08 08:46:06 -0600249 with osutils.TempDir(delete=False) as temp_output_dir:
250 sysroot_tar_path = sysroot.GenerateArchive(
251 temp_output_dir, build_target_name, pkg_list
252 )
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -0700253
Alex Klein1699fab2022-09-08 08:46:06 -0600254 # By assigning this Path variable to the tar path, the tar file will be
255 # copied out to the input_proto's ResultPath location.
256 output_proto.sysroot_archive.path = sysroot_tar_path
257 output_proto.sysroot_archive.location = common_pb2.Path.INSIDE
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -0700258
259
Alex Klein076841b2019-08-29 15:19:39 -0600260def _MockFailedPackagesResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600261 """Mock error response that populates failed packages."""
262 fail = output_proto.failed_package_data.add()
263 fail.name.package_name = "package"
264 fail.name.category = "category"
265 fail.name.version = "1.0.0_rc-r1"
266 fail.log_path.path = (
267 "/path/to/package:category-1.0.0_rc-r1:20210609-1337.log"
268 )
269 fail.log_path.location = common_pb2.Path.INSIDE
Lizzy Presland7e23a612021-11-09 21:49:42 +0000270
Alex Klein1699fab2022-09-08 08:46:06 -0600271 fail2 = output_proto.failed_package_data.add()
272 fail2.name.package_name = "bar"
273 fail2.name.category = "foo"
274 fail2.name.version = "3.7-r99"
275 fail2.log_path.path = "/path/to/foo:bar-3.7-r99:20210609-1620.log"
276 fail2.log_path.location = common_pb2.Path.INSIDE
Lizzy Presland7e23a612021-11-09 21:49:42 +0000277
Alex Klein076841b2019-08-29 15:19:39 -0600278
279@faux.empty_success
280@faux.error(_MockFailedPackagesResponse)
Alex Klein1699fab2022-09-08 08:46:06 -0600281@validate.require("sysroot.path", "sysroot.build_target.name")
282@validate.exists("sysroot.path")
Alex Klein231d2da2019-07-22 16:44:45 -0600283@validate.validation_complete
284def InstallToolchain(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600285 """Install the toolchain into a sysroot."""
286 compile_source = (
287 input_proto.flags.compile_source or input_proto.flags.toolchain_changed
288 )
Alex Kleinda35fcf2019-03-07 16:01:15 -0700289
Alex Klein1699fab2022-09-08 08:46:06 -0600290 sysroot_path = input_proto.sysroot.path
Alex Kleinda35fcf2019-03-07 16:01:15 -0700291
Alex Klein1699fab2022-09-08 08:46:06 -0600292 build_target = controller_util.ParseBuildTarget(
293 input_proto.sysroot.build_target
294 )
295 target_sysroot = sysroot_lib.Sysroot(sysroot_path)
296 run_configs = sysroot.SetupBoardRunConfig(usepkg=not compile_source)
Alex Kleinda35fcf2019-03-07 16:01:15 -0700297
Alex Klein1699fab2022-09-08 08:46:06 -0600298 _LogBinhost(build_target.name)
Alex Kleina9d64602019-05-17 14:55:37 -0600299
Alex Klein1699fab2022-09-08 08:46:06 -0600300 try:
301 sysroot.InstallToolchain(build_target, target_sysroot, run_configs)
302 except sysroot_lib.ToolchainInstallError as e:
303 controller_util.retrieve_package_log_paths(
304 e.failed_toolchain_info, output_proto, target_sysroot
305 )
Alex Kleinda35fcf2019-03-07 16:01:15 -0700306
Alex Klein1699fab2022-09-08 08:46:06 -0600307 return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
Alex Kleind4e1e422019-03-18 16:00:41 -0600308
Alex Klein1699fab2022-09-08 08:46:06 -0600309 return controller.RETURN_CODE_SUCCESS
Alex Kleind4e1e422019-03-18 16:00:41 -0600310
Alex Klein076841b2019-08-29 15:19:39 -0600311
312@faux.empty_success
313@faux.error(_MockFailedPackagesResponse)
Alex Klein1699fab2022-09-08 08:46:06 -0600314@validate.require("sysroot.build_target.name")
315@validate.exists("sysroot.path")
316@validate.require_each("packages", ["category", "package_name"])
317@validate.require_each("use_flags", ["flag"])
Alex Klein231d2da2019-07-22 16:44:45 -0600318@validate.validation_complete
Alex Kleinaef41942022-04-19 14:13:17 -0600319@metrics_lib.collect_metrics
Alex Klein231d2da2019-07-22 16:44:45 -0600320def InstallPackages(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600321 """Install packages into a sysroot, building as necessary and permitted."""
322 compile_source = (
323 input_proto.flags.compile_source or input_proto.flags.toolchain_changed
324 )
Joanna Wang1ec0c812021-11-17 17:41:27 -0800325
Alex Klein1699fab2022-09-08 08:46:06 -0600326 use_remoteexec = bool(
327 input_proto.remoteexec_config.reproxy_cfg_file
328 and input_proto.remoteexec_config.reclient_dir
329 )
Joanna Wang1ec0c812021-11-17 17:41:27 -0800330
Alex Klein1699fab2022-09-08 08:46:06 -0600331 # Testing if Goma will support unknown compilers now.
332 use_goma = input_proto.flags.use_goma and not use_remoteexec
Alex Kleind4e1e422019-03-18 16:00:41 -0600333
Alex Klein1699fab2022-09-08 08:46:06 -0600334 target_sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path)
335 build_target = controller_util.ParseBuildTarget(
336 input_proto.sysroot.build_target
337 )
Alex Kleinca572ee2020-09-03 10:47:14 -0600338
Alex Klein1699fab2022-09-08 08:46:06 -0600339 # Get the package atom for each specified package. The field is optional, so
340 # error only when we cannot parse an atom for each of the given packages.
341 packages = [
Alex Kleind3b84042023-05-19 14:43:59 -0600342 controller_util.deserialize_package_info(x).atom
343 for x in input_proto.packages
Alex Klein1699fab2022-09-08 08:46:06 -0600344 ]
Alex Kleinca572ee2020-09-03 10:47:14 -0600345
Alex Klein1699fab2022-09-08 08:46:06 -0600346 package_indexes = [
Alex Klein6d718d62023-01-18 15:55:51 -0700347 controller_util.deserialize_package_index_info(x)
Alex Klein1699fab2022-09-08 08:46:06 -0600348 for x in input_proto.package_indexes
349 ]
Alex Kleind4e1e422019-03-18 16:00:41 -0600350
Alex Kleinab87ceb2023-01-24 12:00:51 -0700351 # Calculate which packages would have been merged, but don't install
352 # anything.
Alex Klein1699fab2022-09-08 08:46:06 -0600353 dryrun = input_proto.flags.dryrun
Navil Perez5766d1b2021-05-26 17:38:15 +0000354
Alex Klein8393dc22023-03-30 10:54:27 -0600355 # Allow cros workon packages to build from the unstable ebuilds.
356 workon = input_proto.flags.workon
357
Ryo Hashimoto0845ebf2023-06-06 19:21:13 +0900358 # Use Bazel to build packages.
359 bazel = input_proto.flags.bazel
360
Alex Klein1699fab2022-09-08 08:46:06 -0600361 if not target_sysroot.IsToolchainInstalled():
362 cros_build_lib.Die("Toolchain must first be installed.")
Alex Kleind4e1e422019-03-18 16:00:41 -0600363
Alex Klein1699fab2022-09-08 08:46:06 -0600364 _LogBinhost(build_target.name)
Alex Kleina9d64602019-05-17 14:55:37 -0600365
Alex Klein1699fab2022-09-08 08:46:06 -0600366 use_flags = [u.flag for u in input_proto.use_flags]
367 build_packages_config = sysroot.BuildPackagesRunConfig(
368 use_any_chrome=False,
369 usepkg=not compile_source,
370 install_debug_symbols=True,
371 packages=packages,
372 package_indexes=package_indexes,
373 use_flags=use_flags,
374 use_goma=use_goma,
375 use_remoteexec=use_remoteexec,
376 incremental_build=False,
377 dryrun=dryrun,
378 backtrack=DEFAULT_BACKTRACK,
Alex Klein8393dc22023-03-30 10:54:27 -0600379 workon=workon,
Ryo Hashimoto0845ebf2023-06-06 19:21:13 +0900380 bazel=bazel,
Alex Klein1699fab2022-09-08 08:46:06 -0600381 )
Alex Kleind4e1e422019-03-18 16:00:41 -0600382
Alex Klein1699fab2022-09-08 08:46:06 -0600383 try:
384 sysroot.BuildPackages(
385 build_target, target_sysroot, build_packages_config
386 )
387 except sysroot_lib.PackageInstallError as e:
388 if not e.failed_packages:
389 # No packages to report, so just exit with an error code.
390 return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY
Alex Klein2557b4f2019-07-11 14:34:00 -0600391
Alex Klein1699fab2022-09-08 08:46:06 -0600392 controller_util.retrieve_package_log_paths(
393 e.failed_packages, output_proto, target_sysroot
394 )
Alex Kleind4e1e422019-03-18 16:00:41 -0600395
Alex Klein1699fab2022-09-08 08:46:06 -0600396 return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
397 finally:
398 # Copy goma logs to specified directory if there is a goma_config and
399 # it contains a log_dir to store artifacts.
400 if input_proto.goma_config.log_dir.dir:
401 log_source_dir = _GetGomaLogDirectory()
402 archiver = goma_lib.LogsArchiver(
403 log_source_dir,
404 dest_dir=input_proto.goma_config.log_dir.dir,
405 stats_file=input_proto.goma_config.stats_file,
406 counterz_file=input_proto.goma_config.counterz_file,
407 )
408 archiver_tuple = archiver.Archive()
409 if archiver_tuple.stats_file:
410 output_proto.goma_artifacts.stats_file = (
411 archiver_tuple.stats_file
412 )
413 if archiver_tuple.counterz_file:
414 output_proto.goma_artifacts.counterz_file = (
415 archiver_tuple.counterz_file
416 )
417 output_proto.goma_artifacts.log_files[:] = archiver_tuple.log_files
Alex Kleina9d64602019-05-17 14:55:37 -0600418
Yoshiki Iguchi0951e112023-08-21 16:31:25 +0900419 if input_proto.remoteexec_config.log_dir.dir:
420 archiver = remoteexec_lib.LogsArchiver(
421 dest_dir=Path(input_proto.remoteexec_config.log_dir.dir),
422 )
423 archived_logs = archiver.archive()
424 output_proto.remoteexec_artifacts.log_files[:] = [
425 str(x) for x in archived_logs
426 ]
427
Alex Klein1699fab2022-09-08 08:46:06 -0600428 # Return without populating the response if it is a dryrun.
429 if dryrun:
430 return controller.RETURN_CODE_SUCCESS
Navil Perez5766d1b2021-05-26 17:38:15 +0000431
Alex Klein1699fab2022-09-08 08:46:06 -0600432 # Read metric events log and pipe them into output_proto.events.
433 deserialize_metrics_log(output_proto.events, prefix=build_target.name)
Will Bradley7e5b8c12019-07-30 12:44:15 -0600434
Alex Kleina9d64602019-05-17 14:55:37 -0600435
436def _LogBinhost(board):
Alex Klein1699fab2022-09-08 08:46:06 -0600437 """Log the portage binhost for the given board."""
438 binhost = portage_util.PortageqEnvvar(
439 "PORTAGE_BINHOST", board=board, allow_undefined=True
440 )
441 if not binhost:
442 logging.warning("Portage Binhost not found.")
443 else:
444 logging.info("Portage Binhost: %s", binhost)