blob: a1b60f057ada71757063c9f12ad4b182cbedc1b3 [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
Jack Neus26b94672022-10-27 17:33:21 +00009import traceback
Michael Mortensen4ccfb082020-01-22 16:24:03 -070010
Alex Klein8cb365a2019-05-15 16:24:53 -060011from chromite.api import controller
Alex Klein076841b2019-08-29 15:19:39 -060012from chromite.api import faux
Alex Klein2b236722019-06-19 15:44:26 -060013from chromite.api import validate
Alex Kleina9d500b2019-04-22 15:37:51 -060014from chromite.api.controller import controller_util
Chris McDonald1672ddb2021-07-21 11:48:23 -060015from chromite.api.gen.chromiumos import common_pb2
Will Bradley7e5b8c12019-07-30 12:44:15 -060016from chromite.api.metrics import deserialize_metrics_log
George Engelbrechtc9a8e812021-06-16 18:14:17 -060017from chromite.lib import build_target_lib
18from chromite.lib import chroot_lib
Alex Kleinda35fcf2019-03-07 16:01:15 -070019from chromite.lib import cros_build_lib
Michael Mortensen798ee192020-01-17 13:04:43 -070020from chromite.lib import goma_lib
Alex Kleinaef41942022-04-19 14:13:17 -060021from chromite.lib import metrics_lib
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -070022from chromite.lib import osutils
Alex Kleina9d64602019-05-17 14:55:37 -060023from chromite.lib import portage_util
Alex Kleinda35fcf2019-03-07 16:01:15 -070024from chromite.lib import sysroot_lib
25from chromite.service import sysroot
26
Chris McDonald1672ddb2021-07-21 11:48:23 -060027
Alex Klein1699fab2022-09-08 08:46:06 -060028_ACCEPTED_LICENSES = "@CHROMEOS"
Alex Kleinda35fcf2019-03-07 16:01:15 -070029
Alex Kleineaa48532022-07-28 08:51:32 -060030DEFAULT_BACKTRACK = 30
31
Alex Kleind4e1e422019-03-18 16:00:41 -060032
Yoshiki Iguchia43704b2021-12-16 13:31:48 +090033def _GetGomaLogDirectory():
Alex Klein1699fab2022-09-08 08:46:06 -060034 """Get goma's log directory based on the env variables.
Yoshiki Iguchia43704b2021-12-16 13:31:48 +090035
Alex Klein1699fab2022-09-08 08:46:06 -060036 Returns:
Alex Klein611dddd2022-10-11 17:02:01 -060037 a string of a directory name where goma's log may exist, or None if no
38 potential directories exist.
Alex Klein1699fab2022-09-08 08:46:06 -060039 """
40 # TODO(crbug.com/1045001): Replace environment variable with query to
41 # goma object after goma refactoring allows this.
42 candidates = [
43 "GLOG_log_dir",
44 "GOOGLE_LOG_DIR",
45 "TEST_TMPDIR",
46 "TMPDIR",
47 "TMP",
48 ]
49 for candidate in candidates:
50 value = os.environ.get(candidate)
51 if value and os.path.isdir(value):
52 return value
Yoshiki Iguchia43704b2021-12-16 13:31:48 +090053
Alex Klein1699fab2022-09-08 08:46:06 -060054 # "/tmp" will always exist.
55 return "/tmp"
Yoshiki Iguchia43704b2021-12-16 13:31:48 +090056
57
George Engelbrechtc9a8e812021-06-16 18:14:17 -060058def ExampleGetResponse():
Alex Klein1699fab2022-09-08 08:46:06 -060059 """Give an example response to assemble upstream in caller artifacts."""
60 uabs = common_pb2.UploadedArtifactsByService
61 cabs = common_pb2.ArtifactsByService
62 return uabs.Sysroot(
63 artifacts=[
64 uabs.Sysroot.ArtifactPaths(
65 artifact_type=cabs.Sysroot.ArtifactType.SIMPLE_CHROME_SYSROOT,
66 paths=[
67 common_pb2.Path(
Alex Kleinab87ceb2023-01-24 12:00:51 -070068 path=(
69 "/tmp/sysroot_chromeos-base_chromeos-chrome.tar.xz"
70 ),
Alex Klein1699fab2022-09-08 08:46:06 -060071 location=common_pb2.Path.OUTSIDE,
72 )
73 ],
74 ),
75 uabs.Sysroot.ArtifactPaths(
76 artifact_type=cabs.Sysroot.ArtifactType.DEBUG_SYMBOLS,
77 paths=[
78 common_pb2.Path(
79 path="/tmp/debug.tgz", location=common_pb2.Path.OUTSIDE
80 )
81 ],
82 ),
83 uabs.Sysroot.ArtifactPaths(
84 artifact_type=cabs.Sysroot.ArtifactType.BREAKPAD_DEBUG_SYMBOLS,
85 paths=[
86 common_pb2.Path(
87 path="/tmp/debug_breakpad.tar.xz",
88 location=common_pb2.Path.OUTSIDE,
89 )
90 ],
91 ),
92 ]
93 )
George Engelbrechtc9a8e812021-06-16 18:14:17 -060094
95
Alex Klein1699fab2022-09-08 08:46:06 -060096def GetArtifacts(
97 in_proto: common_pb2.ArtifactsByService.Sysroot,
98 chroot: chroot_lib.Chroot,
99 sysroot_class: sysroot_lib.Sysroot,
100 build_target: build_target_lib.BuildTarget,
101 output_dir: str,
102) -> list:
103 """Builds and copies sysroot artifacts to specified output_dir.
George Engelbrechtc9a8e812021-06-16 18:14:17 -0600104
Alex Kleinab87ceb2023-01-24 12:00:51 -0700105 Copies sysroot artifacts to output_dir, returning a list of
106 (output_dir: str) paths to the desired files.
George Engelbrechtc9a8e812021-06-16 18:14:17 -0600107
Alex Klein1699fab2022-09-08 08:46:06 -0600108 Args:
Alex Klein611dddd2022-10-11 17:02:01 -0600109 in_proto: Proto request defining reqs.
110 chroot: The chroot class used for these artifacts.
111 sysroot_class: The sysroot class used for these artifacts.
112 build_target: The build target used for these artifacts.
113 output_dir: The path to write artifacts to.
George Engelbrechtc9a8e812021-06-16 18:14:17 -0600114
Alex Klein1699fab2022-09-08 08:46:06 -0600115 Returns:
Alex Klein611dddd2022-10-11 17:02:01 -0600116 A list of dictionary mappings of ArtifactType to list of paths.
Alex Klein1699fab2022-09-08 08:46:06 -0600117 """
Ian Barkley-Yeungb5274442023-04-28 16:32:20 -0700118
119 def _BundleBreakpadSymbols(chroot, sysroot_class, build_target, output_dir):
Alex Klein1bdd1ed2023-06-15 15:25:32 -0600120 # pylint: disable=line-too-long
Ian Barkley-Yeungb5274442023-04-28 16:32:20 -0700121 ignore_breakpad_symbol_generation_expected_files = [
122 common_pb2.ArtifactsByService.Sysroot.BreakpadSymbolGenerationExpectedFile.Name(
123 x
124 )
125 for x in in_proto.ignore_breakpad_symbol_generation_expected_files
126 if x
127 != common_pb2.ArtifactsByService.Sysroot.BreakpadSymbolGenerationExpectedFile.EXPECTED_FILE_UNSET
128 and x
129 in common_pb2.ArtifactsByService.Sysroot.BreakpadSymbolGenerationExpectedFile.values()
130 ]
Alex Klein1bdd1ed2023-06-15 15:25:32 -0600131 # pylint: enable=line-too-long
Ian Barkley-Yeungb5274442023-04-28 16:32:20 -0700132
133 ignore_breakpad_symbol_generation_expected_files = [
134 x[len("EXPECTED_FILE_") :]
135 for x in ignore_breakpad_symbol_generation_expected_files
136 ]
137
138 return sysroot.BundleBreakpadSymbols(
139 chroot,
140 sysroot_class,
141 build_target,
142 output_dir,
143 in_proto.ignore_breakpad_symbol_generation_errors,
144 ignore_breakpad_symbol_generation_expected_files,
145 )
146
Alex Klein1699fab2022-09-08 08:46:06 -0600147 generated = []
Alex Kleinab87ceb2023-01-24 12:00:51 -0700148 # pylint: disable=line-too-long
Alex Klein1699fab2022-09-08 08:46:06 -0600149 artifact_types = {
150 in_proto.ArtifactType.SIMPLE_CHROME_SYSROOT: sysroot.CreateSimpleChromeSysroot,
151 in_proto.ArtifactType.CHROME_EBUILD_ENV: sysroot.CreateChromeEbuildEnv,
Ian Barkley-Yeungb5274442023-04-28 16:32:20 -0700152 in_proto.ArtifactType.BREAKPAD_DEBUG_SYMBOLS: _BundleBreakpadSymbols,
Alex Klein1699fab2022-09-08 08:46:06 -0600153 in_proto.ArtifactType.DEBUG_SYMBOLS: sysroot.BundleDebugSymbols,
Jack Neus11b6ebd2022-10-21 17:54:36 +0000154 in_proto.ArtifactType.FUZZER_SYSROOT: sysroot.CreateFuzzerSysroot,
Ram Chandrasekar5ba36b22023-03-20 16:10:48 -0600155 in_proto.ArtifactType.SYSROOT_ARCHIVE: sysroot.ArchiveSysroot,
Alex Klein1699fab2022-09-08 08:46:06 -0600156 }
Alex Kleinab87ceb2023-01-24 12:00:51 -0700157 # pylint: enable=line-too-long
Jack Neus5e56fef2021-06-18 16:57:28 +0000158
Alex Klein1699fab2022-09-08 08:46:06 -0600159 for output_artifact in in_proto.output_artifacts:
160 for artifact_type, func in artifact_types.items():
161 if artifact_type in output_artifact.artifact_types:
Jack Neus26b94672022-10-27 17:33:21 +0000162 try:
163 result = func(
164 chroot, sysroot_class, build_target, output_dir
165 )
166 except Exception as e:
167 generated.append(
168 {
169 "type": artifact_type,
170 "failed": True,
171 "failure_reason": str(e),
172 }
173 )
174 artifact_name = (
175 common_pb2.ArtifactsByService.Sysroot.ArtifactType.Name(
176 artifact_type
177 )
178 )
179 logging.warning(
180 "%s artifact generation failed with exception %s",
181 artifact_name,
182 e,
183 )
184 logging.warning("traceback:\n%s", traceback.format_exc())
185 continue
Alex Klein1699fab2022-09-08 08:46:06 -0600186 if result:
187 generated.append(
188 {
Ram Chandrasekar5ba36b22023-03-20 16:10:48 -0600189 "paths": [str(result)]
190 if isinstance(result, (os.PathLike, str))
Alex Klein1699fab2022-09-08 08:46:06 -0600191 else result,
192 "type": artifact_type,
193 }
194 )
Jack Neus5e56fef2021-06-18 16:57:28 +0000195
Alex Klein1699fab2022-09-08 08:46:06 -0600196 return generated
George Engelbrechtc9a8e812021-06-16 18:14:17 -0600197
198
Alex Klein076841b2019-08-29 15:19:39 -0600199@faux.all_empty
Alex Klein1699fab2022-09-08 08:46:06 -0600200@validate.require("build_target.name")
Alex Klein231d2da2019-07-22 16:44:45 -0600201@validate.validation_complete
202def Create(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600203 """Create or replace a sysroot."""
204 update_chroot = not input_proto.flags.chroot_current
205 replace_sysroot = input_proto.flags.replace
Yoshiki Iguchi2f7f0222023-05-17 19:30:09 +0900206 use_cq_prebuilts = input_proto.flags.use_cq_prebuilts
Alex Kleinda35fcf2019-03-07 16:01:15 -0700207
Alex Klein1699fab2022-09-08 08:46:06 -0600208 build_target = controller_util.ParseBuildTarget(
209 input_proto.build_target, input_proto.profile
210 )
211 package_indexes = [
Alex Klein6d718d62023-01-18 15:55:51 -0700212 controller_util.deserialize_package_index_info(x)
Alex Klein1699fab2022-09-08 08:46:06 -0600213 for x in input_proto.package_indexes
214 ]
215 run_configs = sysroot.SetupBoardRunConfig(
216 force=replace_sysroot,
217 upgrade_chroot=update_chroot,
218 package_indexes=package_indexes,
Yoshiki Iguchi2f7f0222023-05-17 19:30:09 +0900219 use_cq_prebuilts=use_cq_prebuilts,
Alex Klein1699fab2022-09-08 08:46:06 -0600220 backtrack=DEFAULT_BACKTRACK,
221 )
Alex Kleinda35fcf2019-03-07 16:01:15 -0700222
Alex Klein1699fab2022-09-08 08:46:06 -0600223 try:
224 created = sysroot.Create(
225 build_target, run_configs, accept_licenses=_ACCEPTED_LICENSES
226 )
227 except sysroot.Error as e:
228 cros_build_lib.Die(e)
Alex Kleinda35fcf2019-03-07 16:01:15 -0700229
Alex Klein1699fab2022-09-08 08:46:06 -0600230 output_proto.sysroot.path = created.path
231 output_proto.sysroot.build_target.name = build_target.name
Alex Kleinda35fcf2019-03-07 16:01:15 -0700232
Alex Klein1699fab2022-09-08 08:46:06 -0600233 return controller.RETURN_CODE_SUCCESS
Alex Kleinda35fcf2019-03-07 16:01:15 -0700234
Alex Klein076841b2019-08-29 15:19:39 -0600235
Michael Mortensen98592f62019-09-27 13:34:18 -0600236@faux.all_empty
Alex Klein1699fab2022-09-08 08:46:06 -0600237@validate.require("build_target.name", "packages")
238@validate.require_each("packages", ["category", "package_name"])
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -0700239@validate.validation_complete
240def GenerateArchive(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600241 """Generate a sysroot. Typically used by informational builders."""
242 build_target_name = input_proto.build_target.name
243 pkg_list = []
244 for package in input_proto.packages:
245 pkg_list.append("%s/%s" % (package.category, package.package_name))
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -0700246
Alex Klein1699fab2022-09-08 08:46:06 -0600247 with osutils.TempDir(delete=False) as temp_output_dir:
248 sysroot_tar_path = sysroot.GenerateArchive(
249 temp_output_dir, build_target_name, pkg_list
250 )
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -0700251
Alex Klein1699fab2022-09-08 08:46:06 -0600252 # By assigning this Path variable to the tar path, the tar file will be
253 # copied out to the input_proto's ResultPath location.
254 output_proto.sysroot_archive.path = sysroot_tar_path
255 output_proto.sysroot_archive.location = common_pb2.Path.INSIDE
Michael Mortensen3f6b4bd2020-02-07 14:16:43 -0700256
257
Alex Klein076841b2019-08-29 15:19:39 -0600258def _MockFailedPackagesResponse(_input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600259 """Mock error response that populates failed packages."""
260 fail = output_proto.failed_package_data.add()
261 fail.name.package_name = "package"
262 fail.name.category = "category"
263 fail.name.version = "1.0.0_rc-r1"
264 fail.log_path.path = (
265 "/path/to/package:category-1.0.0_rc-r1:20210609-1337.log"
266 )
267 fail.log_path.location = common_pb2.Path.INSIDE
Lizzy Presland7e23a612021-11-09 21:49:42 +0000268
Alex Klein1699fab2022-09-08 08:46:06 -0600269 fail2 = output_proto.failed_package_data.add()
270 fail2.name.package_name = "bar"
271 fail2.name.category = "foo"
272 fail2.name.version = "3.7-r99"
273 fail2.log_path.path = "/path/to/foo:bar-3.7-r99:20210609-1620.log"
274 fail2.log_path.location = common_pb2.Path.INSIDE
Lizzy Presland7e23a612021-11-09 21:49:42 +0000275
Alex Klein076841b2019-08-29 15:19:39 -0600276
277@faux.empty_success
278@faux.error(_MockFailedPackagesResponse)
Alex Klein1699fab2022-09-08 08:46:06 -0600279@validate.require("sysroot.path", "sysroot.build_target.name")
280@validate.exists("sysroot.path")
Alex Klein231d2da2019-07-22 16:44:45 -0600281@validate.validation_complete
282def InstallToolchain(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600283 """Install the toolchain into a sysroot."""
284 compile_source = (
285 input_proto.flags.compile_source or input_proto.flags.toolchain_changed
286 )
Alex Kleinda35fcf2019-03-07 16:01:15 -0700287
Alex Klein1699fab2022-09-08 08:46:06 -0600288 sysroot_path = input_proto.sysroot.path
Alex Kleinda35fcf2019-03-07 16:01:15 -0700289
Alex Klein1699fab2022-09-08 08:46:06 -0600290 build_target = controller_util.ParseBuildTarget(
291 input_proto.sysroot.build_target
292 )
293 target_sysroot = sysroot_lib.Sysroot(sysroot_path)
294 run_configs = sysroot.SetupBoardRunConfig(usepkg=not compile_source)
Alex Kleinda35fcf2019-03-07 16:01:15 -0700295
Alex Klein1699fab2022-09-08 08:46:06 -0600296 _LogBinhost(build_target.name)
Alex Kleina9d64602019-05-17 14:55:37 -0600297
Alex Klein1699fab2022-09-08 08:46:06 -0600298 try:
299 sysroot.InstallToolchain(build_target, target_sysroot, run_configs)
300 except sysroot_lib.ToolchainInstallError as e:
301 controller_util.retrieve_package_log_paths(
302 e.failed_toolchain_info, output_proto, target_sysroot
303 )
Alex Kleinda35fcf2019-03-07 16:01:15 -0700304
Alex Klein1699fab2022-09-08 08:46:06 -0600305 return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
Alex Kleind4e1e422019-03-18 16:00:41 -0600306
Alex Klein1699fab2022-09-08 08:46:06 -0600307 return controller.RETURN_CODE_SUCCESS
Alex Kleind4e1e422019-03-18 16:00:41 -0600308
Alex Klein076841b2019-08-29 15:19:39 -0600309
310@faux.empty_success
311@faux.error(_MockFailedPackagesResponse)
Alex Klein1699fab2022-09-08 08:46:06 -0600312@validate.require("sysroot.build_target.name")
313@validate.exists("sysroot.path")
314@validate.require_each("packages", ["category", "package_name"])
315@validate.require_each("use_flags", ["flag"])
Alex Klein231d2da2019-07-22 16:44:45 -0600316@validate.validation_complete
Alex Kleinaef41942022-04-19 14:13:17 -0600317@metrics_lib.collect_metrics
Alex Klein231d2da2019-07-22 16:44:45 -0600318def InstallPackages(input_proto, output_proto, _config):
Alex Klein1699fab2022-09-08 08:46:06 -0600319 """Install packages into a sysroot, building as necessary and permitted."""
320 compile_source = (
321 input_proto.flags.compile_source or input_proto.flags.toolchain_changed
322 )
Joanna Wang1ec0c812021-11-17 17:41:27 -0800323
Alex Klein1699fab2022-09-08 08:46:06 -0600324 use_remoteexec = bool(
325 input_proto.remoteexec_config.reproxy_cfg_file
326 and input_proto.remoteexec_config.reclient_dir
327 )
Joanna Wang1ec0c812021-11-17 17:41:27 -0800328
Alex Klein1699fab2022-09-08 08:46:06 -0600329 # Testing if Goma will support unknown compilers now.
330 use_goma = input_proto.flags.use_goma and not use_remoteexec
Alex Kleind4e1e422019-03-18 16:00:41 -0600331
Alex Klein1699fab2022-09-08 08:46:06 -0600332 target_sysroot = sysroot_lib.Sysroot(input_proto.sysroot.path)
333 build_target = controller_util.ParseBuildTarget(
334 input_proto.sysroot.build_target
335 )
Alex Kleinca572ee2020-09-03 10:47:14 -0600336
Alex Klein1699fab2022-09-08 08:46:06 -0600337 # Get the package atom for each specified package. The field is optional, so
338 # error only when we cannot parse an atom for each of the given packages.
339 packages = [
Alex Kleind3b84042023-05-19 14:43:59 -0600340 controller_util.deserialize_package_info(x).atom
341 for x in input_proto.packages
Alex Klein1699fab2022-09-08 08:46:06 -0600342 ]
Alex Kleinca572ee2020-09-03 10:47:14 -0600343
Alex Klein1699fab2022-09-08 08:46:06 -0600344 package_indexes = [
Alex Klein6d718d62023-01-18 15:55:51 -0700345 controller_util.deserialize_package_index_info(x)
Alex Klein1699fab2022-09-08 08:46:06 -0600346 for x in input_proto.package_indexes
347 ]
Alex Kleind4e1e422019-03-18 16:00:41 -0600348
Alex Kleinab87ceb2023-01-24 12:00:51 -0700349 # Calculate which packages would have been merged, but don't install
350 # anything.
Alex Klein1699fab2022-09-08 08:46:06 -0600351 dryrun = input_proto.flags.dryrun
Navil Perez5766d1b2021-05-26 17:38:15 +0000352
Alex Klein8393dc22023-03-30 10:54:27 -0600353 # Allow cros workon packages to build from the unstable ebuilds.
354 workon = input_proto.flags.workon
355
Ryo Hashimoto0845ebf2023-06-06 19:21:13 +0900356 # Use Bazel to build packages.
357 bazel = input_proto.flags.bazel
358
Alex Klein1699fab2022-09-08 08:46:06 -0600359 if not target_sysroot.IsToolchainInstalled():
360 cros_build_lib.Die("Toolchain must first be installed.")
Alex Kleind4e1e422019-03-18 16:00:41 -0600361
Alex Klein1699fab2022-09-08 08:46:06 -0600362 _LogBinhost(build_target.name)
Alex Kleina9d64602019-05-17 14:55:37 -0600363
Alex Klein1699fab2022-09-08 08:46:06 -0600364 use_flags = [u.flag for u in input_proto.use_flags]
365 build_packages_config = sysroot.BuildPackagesRunConfig(
366 use_any_chrome=False,
367 usepkg=not compile_source,
368 install_debug_symbols=True,
369 packages=packages,
370 package_indexes=package_indexes,
371 use_flags=use_flags,
372 use_goma=use_goma,
373 use_remoteexec=use_remoteexec,
374 incremental_build=False,
375 dryrun=dryrun,
376 backtrack=DEFAULT_BACKTRACK,
Alex Klein8393dc22023-03-30 10:54:27 -0600377 workon=workon,
Ryo Hashimoto0845ebf2023-06-06 19:21:13 +0900378 bazel=bazel,
Alex Klein1699fab2022-09-08 08:46:06 -0600379 )
Alex Kleind4e1e422019-03-18 16:00:41 -0600380
Alex Klein1699fab2022-09-08 08:46:06 -0600381 try:
382 sysroot.BuildPackages(
383 build_target, target_sysroot, build_packages_config
384 )
385 except sysroot_lib.PackageInstallError as e:
386 if not e.failed_packages:
387 # No packages to report, so just exit with an error code.
388 return controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY
Alex Klein2557b4f2019-07-11 14:34:00 -0600389
Alex Klein1699fab2022-09-08 08:46:06 -0600390 controller_util.retrieve_package_log_paths(
391 e.failed_packages, output_proto, target_sysroot
392 )
Alex Kleind4e1e422019-03-18 16:00:41 -0600393
Alex Klein1699fab2022-09-08 08:46:06 -0600394 return controller.RETURN_CODE_UNSUCCESSFUL_RESPONSE_AVAILABLE
395 finally:
396 # Copy goma logs to specified directory if there is a goma_config and
397 # it contains a log_dir to store artifacts.
398 if input_proto.goma_config.log_dir.dir:
399 log_source_dir = _GetGomaLogDirectory()
400 archiver = goma_lib.LogsArchiver(
401 log_source_dir,
402 dest_dir=input_proto.goma_config.log_dir.dir,
403 stats_file=input_proto.goma_config.stats_file,
404 counterz_file=input_proto.goma_config.counterz_file,
405 )
406 archiver_tuple = archiver.Archive()
407 if archiver_tuple.stats_file:
408 output_proto.goma_artifacts.stats_file = (
409 archiver_tuple.stats_file
410 )
411 if archiver_tuple.counterz_file:
412 output_proto.goma_artifacts.counterz_file = (
413 archiver_tuple.counterz_file
414 )
415 output_proto.goma_artifacts.log_files[:] = archiver_tuple.log_files
Alex Kleina9d64602019-05-17 14:55:37 -0600416
Alex Klein1699fab2022-09-08 08:46:06 -0600417 # Return without populating the response if it is a dryrun.
418 if dryrun:
419 return controller.RETURN_CODE_SUCCESS
Navil Perez5766d1b2021-05-26 17:38:15 +0000420
Alex Klein1699fab2022-09-08 08:46:06 -0600421 # Read metric events log and pipe them into output_proto.events.
422 deserialize_metrics_log(output_proto.events, prefix=build_target.name)
Will Bradley7e5b8c12019-07-30 12:44:15 -0600423
Alex Kleina9d64602019-05-17 14:55:37 -0600424
425def _LogBinhost(board):
Alex Klein1699fab2022-09-08 08:46:06 -0600426 """Log the portage binhost for the given board."""
427 binhost = portage_util.PortageqEnvvar(
428 "PORTAGE_BINHOST", board=board, allow_undefined=True
429 )
430 if not binhost:
431 logging.warning("Portage Binhost not found.")
432 else:
433 logging.info("Portage Binhost: %s", binhost)