blob: b166d823f67aea5664f4b3300aa470e56003a764 [file] [log] [blame]
Tiancong Wangaf050172019-07-10 11:52:03 -07001# 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"""Toolchain-related operations."""
6
LaMont Jonesb20b3d92019-11-23 11:47:48 -07007import collections
Chris McDonald1672ddb2021-07-21 11:48:23 -06008import logging
Alex Kleincd03a5e2021-10-18 13:23:47 -06009from pathlib import Path
Jack Neus4ee7b1d2022-06-27 19:54:18 +000010from typing import TYPE_CHECKING
LaMont Jonesb20b3d92019-11-23 11:47:48 -070011
LaMont Jones5d2edcb2019-12-23 11:32:03 -070012from chromite.api import controller
Alex Klein076841b2019-08-29 15:19:39 -060013from chromite.api import faux
Alex Klein231d2da2019-07-22 16:44:45 -060014from chromite.api import validate
LaMont Jones5d2edcb2019-12-23 11:32:03 -070015from chromite.api.controller import controller_util
Tiancong Wang24a3df72019-08-20 15:48:51 -070016from chromite.api.gen.chromite.api import toolchain_pb2
LaMont Jonesfd68cb12020-04-29 16:43:06 -060017from chromite.api.gen.chromite.api.artifacts_pb2 import PrepareForBuildResponse
Chris McDonald1672ddb2021-07-21 11:48:23 -060018from chromite.api.gen.chromiumos.builder_config_pb2 import BuilderConfig
Jack Neus4ee7b1d2022-06-27 19:54:18 +000019from chromite.lib import toolchain as toolchain_lib
Chris McDonald1672ddb2021-07-21 11:48:23 -060020from chromite.lib import toolchain_util
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +000021from chromite.service import toolchain
Ryan Beltran7d191802021-11-24 00:08:17 +000022
Mike Frysingerea11fdd2022-05-06 22:59:33 -040023
Jack Neus4ee7b1d2022-06-27 19:54:18 +000024if TYPE_CHECKING:
25 from chromite.api import api_config
26
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +000027# TODO(b/229665884): Move the implementation details for most/all endpoints to:
28# chromite/services/toolchain.py
29# This migration has been done for linting endpoints but not yet for others.
Chris McDonald1672ddb2021-07-21 11:48:23 -060030
LaMont Jonesb20b3d92019-11-23 11:47:48 -070031_Handlers = collections.namedtuple('_Handlers', ['name', 'prepare', 'bundle'])
32_TOOLCHAIN_ARTIFACT_HANDLERS = {
LaMont Jonescd1503d2020-03-04 09:09:59 -070033 BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE:
LaMont Jonesd3944582020-03-04 10:37:05 -070034 _Handlers('UnverifiedChromeLlvmOrderfile',
LaMont Jones5d2edcb2019-12-23 11:32:03 -070035 toolchain_util.PrepareForBuild,
36 toolchain_util.BundleArtifacts),
LaMont Jonescd1503d2020-03-04 09:09:59 -070037 BuilderConfig.Artifacts.VERIFIED_CHROME_LLVM_ORDERFILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070038 _Handlers('VerifiedChromeLlvmOrderfile', toolchain_util.PrepareForBuild,
LaMont Jones5d2edcb2019-12-23 11:32:03 -070039 toolchain_util.BundleArtifacts),
LaMont Jonesb20b3d92019-11-23 11:47:48 -070040 BuilderConfig.Artifacts.CHROME_CLANG_WARNINGS_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070041 _Handlers('ChromeClangWarningsFile', toolchain_util.PrepareForBuild,
LaMont Jones90bab632020-01-27 15:58:26 -070042 toolchain_util.BundleArtifacts),
LaMont Jonesb20b3d92019-11-23 11:47:48 -070043 BuilderConfig.Artifacts.UNVERIFIED_LLVM_PGO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070044 _Handlers('UnverifiedLlvmPgoFile', toolchain_util.PrepareForBuild,
LaMont Jones90bab632020-01-27 15:58:26 -070045 toolchain_util.BundleArtifacts),
LaMont Jones45ca6c42020-02-05 09:39:09 -070046 BuilderConfig.Artifacts.UNVERIFIED_CHROME_BENCHMARK_AFDO_FILE:
47 _Handlers('UnverifiedChromeBenchmarkAfdoFile',
LaMont Jones90bab632020-01-27 15:58:26 -070048 toolchain_util.PrepareForBuild,
49 toolchain_util.BundleArtifacts),
LaMont Jones3fed7f22020-03-04 10:15:11 -070050 BuilderConfig.Artifacts.CHROME_DEBUG_BINARY:
Tiancong Wangba2a1c22021-01-19 10:45:06 -080051 _Handlers('ChromeDebugBinary', toolchain_util.PrepareForBuild,
LaMont Jones3fed7f22020-03-04 10:15:11 -070052 toolchain_util.BundleArtifacts),
LaMont Jones53bddd02020-03-12 15:02:54 -060053 BuilderConfig.Artifacts.UNVERIFIED_CHROME_BENCHMARK_PERF_FILE:
54 _Handlers('UnverifiedChromeBenchmarkPerfFile',
55 toolchain_util.PrepareForBuild,
56 toolchain_util.BundleArtifacts),
LaMont Jones45ca6c42020-02-05 09:39:09 -070057 BuilderConfig.Artifacts.VERIFIED_CHROME_BENCHMARK_AFDO_FILE:
58 _Handlers('VerifiedChromeBenchmarkAfdoFile',
LaMont Jones90bab632020-01-27 15:58:26 -070059 toolchain_util.PrepareForBuild,
60 toolchain_util.BundleArtifacts),
LaMont Jones45ca6c42020-02-05 09:39:09 -070061 BuilderConfig.Artifacts.UNVERIFIED_KERNEL_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070062 _Handlers('UnverifiedKernelCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070063 toolchain_util.BundleArtifacts),
64 BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070065 _Handlers('VerifiedKernelCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070066 toolchain_util.BundleArtifacts),
67 BuilderConfig.Artifacts.UNVERIFIED_CHROME_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070068 _Handlers('UnverifiedChromeCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070069 toolchain_util.BundleArtifacts),
70 BuilderConfig.Artifacts.VERIFIED_CHROME_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070071 _Handlers('VerifiedChromeCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070072 toolchain_util.BundleArtifacts),
73 BuilderConfig.Artifacts.VERIFIED_RELEASE_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070074 _Handlers('VerifiedReleaseAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones90bab632020-01-27 15:58:26 -070075 toolchain_util.BundleArtifacts),
Tiancong Wang91cf1dd2020-05-05 10:30:22 -070076 BuilderConfig.Artifacts.TOOLCHAIN_WARNING_LOGS:
77 _Handlers('ToolchainWarningLogs', toolchain_util.PrepareForBuild,
78 toolchain_util.BundleArtifacts),
Tiancong Wangfe3dbd22020-06-12 15:45:55 -070079 BuilderConfig.Artifacts.CHROME_AFDO_PROFILE_FOR_ANDROID_LINUX:
80 _Handlers('ChromeAFDOProfileForAndroidLinux',
81 toolchain_util.PrepareForBuild,
82 toolchain_util.BundleArtifacts),
Jian Cai6190cc82020-06-12 16:24:32 -070083 BuilderConfig.Artifacts.CLANG_CRASH_DIAGNOSES:
84 _Handlers('ClangCrashDiagnoses', toolchain_util.PrepareForBuild,
85 toolchain_util.BundleArtifacts),
Ryan Beltran0be7dcf2020-12-09 18:31:53 +000086 BuilderConfig.Artifacts.COMPILER_RUSAGE_LOG:
87 _Handlers('CompilerRusageLogs', toolchain_util.PrepareForBuild,
88 toolchain_util.BundleArtifacts),
LaMont Jonesb20b3d92019-11-23 11:47:48 -070089}
90
Tiancong Wangd5214132021-01-12 10:43:57 -080091_TOOLCHAIN_COMMIT_HANDLERS = {
92 BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE:
93 'VerifiedKernelCwpAfdoFile'
94}
95
LaMont Jonese7821672020-04-09 08:56:26 -060096
LaMont Jonesb20b3d92019-11-23 11:47:48 -070097# TODO(crbug/1031213): When @faux is expanded to have more than success/failure,
98# this should be changed.
99@faux.all_empty
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700100@validate.require('artifact_types')
101# Note: chroot and sysroot are unspecified the first time that the build_target
102# recipe calls PrepareForBuild. The second time, they are specified. No
103# validation check because "all" values are valid.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700104@validate.validation_complete
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000105def PrepareForBuild(
106 input_proto: 'toolchain_pb2.PrepareForToolchainBuildRequest',
107 output_proto: 'toolchain_pb2.PrepareForToolchainBuildResponse',
108 _config: 'api_config.ApiConfig'):
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700109 """Prepare to build toolchain artifacts.
110
111 The handlers (from _TOOLCHAIN_ARTIFACT_HANDLERS above) are called with:
112 artifact_name (str): name of the artifact type.
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700113 chroot (chroot_lib.Chroot): chroot. Will be None if the chroot has not
114 yet been created.
115 sysroot_path (str): sysroot path inside the chroot (e.g., /build/atlas).
116 Will be an empty string if the sysroot has not yet been created.
117 build_target_name (str): name of the build target (e.g., atlas). Will be
118 an empty string if the sysroot has not yet been created.
119 input_artifacts ({(str) name:[str gs_locations]}): locations for possible
120 input artifacts. The handler is expected to know which keys it should
121 be using, and ignore any keys that it does not understand.
LaMont Jonese7821672020-04-09 08:56:26 -0600122 profile_info ({(str) name: (str) value}) Dictionary containing profile
123 information.
LaMont Jonesa215f1e2019-12-06 10:18:58 -0700124
125 They locate and modify any ebuilds and/or source required for the artifact
126 being created, then return a value from toolchain_util.PrepareForBuildReturn.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700127
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700128 This function sets output_proto.build_relevance to the result.
129
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700130 Args:
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000131 input_proto: The input proto
132 output_proto: The output proto
133 _config): The API call config.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700134 """
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700135 if input_proto.chroot.path:
136 chroot = controller_util.ParseChroot(input_proto.chroot)
137 else:
138 chroot = None
LaMont Jones4579e8c2019-12-06 14:20:37 -0700139
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700140 input_artifacts = collections.defaultdict(list)
141 for art in input_proto.input_artifacts:
142 item = _TOOLCHAIN_ARTIFACT_HANDLERS.get(art.input_artifact_type)
143 if item:
144 input_artifacts[item.name].extend(
145 ['gs://%s' % str(x) for x in art.input_artifact_gs_locations])
146
LaMont Jonese7821672020-04-09 08:56:26 -0600147 profile_info = _GetProfileInfoDict(input_proto.profile_info)
LaMont Jones45ca6c42020-02-05 09:39:09 -0700148
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700149 results = set()
150 sysroot_path = input_proto.sysroot.path
151 build_target = input_proto.sysroot.build_target.name
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700152 for artifact_type in input_proto.artifact_types:
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700153 # Unknown artifact_types are an error.
154 handler = _TOOLCHAIN_ARTIFACT_HANDLERS[artifact_type]
155 if handler.prepare:
Tiancong Wangba2a1c22021-01-19 10:45:06 -0800156 results.add(
157 handler.prepare(handler.name, chroot, sysroot_path, build_target,
158 input_artifacts, profile_info))
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700159
160 # Translate the returns from the handlers we called.
161 # If any NEEDED => NEEDED
162 # elif any UNKNOWN => UNKNOWN
163 # elif any POINTLESS => POINTLESS
164 # else UNKNOWN.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700165 if toolchain_util.PrepareForBuildReturn.NEEDED in results:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600166 output_proto.build_relevance = PrepareForBuildResponse.NEEDED
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700167 elif toolchain_util.PrepareForBuildReturn.UNKNOWN in results:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600168 output_proto.build_relevance = PrepareForBuildResponse.UNKNOWN
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700169 elif toolchain_util.PrepareForBuildReturn.POINTLESS in results:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600170 output_proto.build_relevance = PrepareForBuildResponse.POINTLESS
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700171 else:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600172 output_proto.build_relevance = PrepareForBuildResponse.UNKNOWN
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700173 return controller.RETURN_CODE_SUCCESS
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700174
175
176# TODO(crbug/1031213): When @faux is expanded to have more than success/failure,
177# this should be changed.
178@faux.all_empty
LaMont Jonese911df02020-04-16 12:40:17 -0600179@validate.require('chroot.path', 'output_dir', 'artifact_types')
LaMont Jones4579e8c2019-12-06 14:20:37 -0700180@validate.exists('output_dir')
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700181@validate.validation_complete
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000182def BundleArtifacts(input_proto: 'toolchain_pb2.BundleToolchainRequest',
183 output_proto: 'toolchain_pb2.BundleToolchainResponse',
184 _config: 'api_config.ApiConfig'):
Alex Kleincd03a5e2021-10-18 13:23:47 -0600185 """Bundle valid toolchain artifacts.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700186
187 The handlers (from _TOOLCHAIN_ARTIFACT_HANDLERS above) are called with:
LaMont Jonesa215f1e2019-12-06 10:18:58 -0700188 artifact_name (str): name of the artifact type
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700189 chroot (chroot_lib.Chroot): chroot
LaMont Jonese911df02020-04-16 12:40:17 -0600190 sysroot_path (str): sysroot path inside the chroot (e.g., /build/atlas),
191 or None.
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700192 chrome_root (str): path to chrome root. (e.g., /b/s/w/ir/k/chrome)
LaMont Jonese911df02020-04-16 12:40:17 -0600193 build_target_name (str): name of the build target (e.g., atlas), or None.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700194 output_dir (str): absolute path where artifacts are being bundled.
195 (e.g., /b/s/w/ir/k/recipe_cleanup/artifactssptfMU)
LaMont Jonese7821672020-04-09 08:56:26 -0600196 profile_info ({(str) name: (str) value}) Dictionary containing profile
197 information.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700198
199 Note: the actual upload to GS is done by CI, not here.
200
201 Args:
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000202 input_proto: The input proto
203 output_proto: The output proto
204 _config: The API call config.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700205 """
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700206 chroot = controller_util.ParseChroot(input_proto.chroot)
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700207
LaMont Jonese7821672020-04-09 08:56:26 -0600208 profile_info = _GetProfileInfoDict(input_proto.profile_info)
LaMont Jones45ca6c42020-02-05 09:39:09 -0700209
Alex Kleincd03a5e2021-10-18 13:23:47 -0600210 output_path = Path(input_proto.output_dir)
211
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700212 for artifact_type in input_proto.artifact_types:
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700213 if artifact_type not in _TOOLCHAIN_ARTIFACT_HANDLERS:
214 logging.error('%s not understood', artifact_type)
215 return controller.RETURN_CODE_UNRECOVERABLE
Alex Kleincd03a5e2021-10-18 13:23:47 -0600216
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700217 handler = _TOOLCHAIN_ARTIFACT_HANDLERS[artifact_type]
Alex Kleincd03a5e2021-10-18 13:23:47 -0600218 if not handler or not handler.bundle:
219 logging.warning('%s does not have a handler with a bundle function.',
220 artifact_type)
221 continue
222
223 artifacts = handler.bundle(handler.name, chroot, input_proto.sysroot.path,
224 input_proto.sysroot.build_target.name,
225 input_proto.output_dir, profile_info)
226 if not artifacts:
227 continue
228
229 # Filter out artifacts that do not exist or are empty.
230 usable_artifacts = []
231 for artifact in artifacts:
232 artifact_path = output_path / artifact
233 if not artifact_path.exists():
234 logging.warning('%s is not in the output directory.', artifact)
235 elif not artifact_path.stat().st_size:
236 logging.warning('%s is empty.', artifact)
237 else:
238 usable_artifacts.append(artifact)
239
240 if not usable_artifacts:
241 logging.warning('No usable artifacts for artifact type %s', artifact_type)
242 continue
243
244 # Add all usable artifacts.
245 art_info = output_proto.artifacts_info.add()
246 art_info.artifact_type = artifact_type
247 for artifact in usable_artifacts:
248 art_info.artifacts.add().path = artifact
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700249
250
Tiancong Wangd5214132021-01-12 10:43:57 -0800251def _GetUpdatedFilesResponse(_input_proto, output_proto, _config):
252 """Add successful status to the faux response."""
253 file_info = output_proto.updated_files.add()
254 file_info.path = '/any/modified/file'
255 output_proto.commit_message = 'Commit message'
256
257
258@faux.empty_error
259@faux.success(_GetUpdatedFilesResponse)
260@validate.require('uploaded_artifacts')
261@validate.validation_complete
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000262def GetUpdatedFiles(input_proto: 'toolchain_pb2.GetUpdatedFilesRequest',
263 output_proto: 'toolchain_pb2.GetUpdatedFilesResponse',
264 _config: 'api_config.ApiConfig'):
Tiancong Wangd5214132021-01-12 10:43:57 -0800265 """Use uploaded artifacts to update some updates in a chromeos checkout.
266
267 The function will call toolchain_util.GetUpdatedFiles using the type of
268 uploaded artifacts to make some changes in a checkout, and return the list
269 of change files together with commit message.
270 updated_artifacts: A list of UpdatedArtifacts type which contains a tuple
271 of artifact info and profile info.
272 Note: the actual creation of the commit is done by CI, not here.
273
274 Args:
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000275 input_proto: The input proto
276 output_proto: The output proto
277 _config: The API call config.
Tiancong Wangd5214132021-01-12 10:43:57 -0800278 """
279 commit_message = ''
280 for artifact in input_proto.uploaded_artifacts:
281 artifact_type = artifact.artifact_info.artifact_type
282 if artifact_type not in _TOOLCHAIN_COMMIT_HANDLERS:
283 logging.error('%s not understood', artifact_type)
284 return controller.RETURN_CODE_UNRECOVERABLE
285 artifact_name = _TOOLCHAIN_COMMIT_HANDLERS[artifact_type]
286 if artifact_name:
287 assert len(artifact.artifact_info.artifacts) == 1, (
288 'Only one file to update per each artifact')
289 updated_files, message = toolchain_util.GetUpdatedFiles(
290 artifact_name, artifact.artifact_info.artifacts[0].path,
291 _GetProfileInfoDict(artifact.profile_info))
292 for f in updated_files:
293 file_info = output_proto.updated_files.add()
294 file_info.path = f
295
296 commit_message += message + '\n'
297 output_proto.commit_message = commit_message
298 # No commit footer is added for now. Can add more here if needed
299
300
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000301def _GetProfileInfoDict(profile_info: 'toolchain_pb2.ArtifactProfileInfo'):
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000302 """Convert profile_info to a dict.
303
304 Args:
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000305 profile_info: The artifact profile_info.
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000306
307 Returns:
308 A dictionary containing profile info.
309 """
310 ret = {}
311 which = profile_info.WhichOneof('artifact_profile_info')
312 if which:
313 value = getattr(profile_info, which)
314 # If it is a message, then use the contents of the message. This works as
315 # long as simple types do not have a 'DESCRIPTOR' attribute. (And protobuf
316 # messages do.)
317 if getattr(value, 'DESCRIPTOR', None):
318 ret.update({k.name: v for k, v in value.ListFields()})
319 else:
320 ret[which] = value
321 return ret
322
323
324LINTER_CODES = {
325 'clang_tidy': toolchain_pb2.LinterFinding.CLANG_TIDY,
326 'cargo_clippy': toolchain_pb2.LinterFinding.CARGO_CLIPPY
327}
328
329
Ryan Beltran0df7fb02021-11-10 20:58:51 +0000330@faux.all_empty
331@validate.exists('sysroot.path')
332@validate.require('packages')
333@validate.validation_complete
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000334def EmergeWithLinting(input_proto: 'toolchain_pb2.LinterRequest',
335 output_proto: 'toolchain_pb2.LinterResponse',
336 _config: 'api_config.ApiConfig'):
Ryan Beltran0df7fb02021-11-10 20:58:51 +0000337 """Emerge packages with linter features enabled and retrieves all findings.
338
339 Args:
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000340 input_proto: The nput proto with package and sysroot info.
341 output_proto: The output proto where findings are stored.
342 _config: The API call config (unused).
Ryan Beltran0df7fb02021-11-10 20:58:51 +0000343 """
344 packages = [
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000345 controller_util.deserialize_package_info(package)
346 for package in input_proto.packages
347 ]
Ryan Beltran7d191802021-11-24 00:08:17 +0000348
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000349 build_linter = toolchain.BuildLinter(
350 packages,
351 input_proto.sysroot.path,
352 differential=input_proto.filter_modified)
Ryan Beltran7d191802021-11-24 00:08:17 +0000353
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000354 findings = build_linter.emerge_with_linting(use_clippy=True, use_tidy=True)
Ryan Beltranf9a86f42022-04-13 20:58:18 +0000355
Ryan Beltran7d191802021-11-24 00:08:17 +0000356 for finding in findings:
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000357 locations = []
Ryan Beltran40e4ad12021-05-17 19:55:03 +0000358 for location in finding.locations:
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000359 locations.append(
Ryan Beltran40e4ad12021-05-17 19:55:03 +0000360 toolchain_pb2.LinterFindingLocation(
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000361 filepath=location.filepath,
Ryan Beltran40e4ad12021-05-17 19:55:03 +0000362 line_start=location.line_start,
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000363 line_end=location.line_end))
364 output_proto.findings.append(
Ryan Beltran40e4ad12021-05-17 19:55:03 +0000365 toolchain_pb2.LinterFinding(
366 message=finding.message,
Ryan Beltranf2a5dcc2022-04-19 20:34:00 +0000367 locations=locations,
368 linter=LINTER_CODES[finding.linter]))
Jack Neus4ee7b1d2022-06-27 19:54:18 +0000369
370
371@faux.all_empty
372@validate.require('board')
373@validate.validation_complete
374def GetToolchainsForBoard(input_proto: 'toolchain_pb2.ToolchainsRequest',
375 output_proto: 'toolchain_pb2.ToolchainsReponse',
376 _config: 'api_config.ApiConfig'):
377 """Gets the default and non-default toolchains for a board.
378
379 Args:
380 input_proto: The input proto with board and sysroot info.
381 output_proto: The output proto where findings are stored.
382 _config: The API call config (unused).
383 """
384 toolchains = toolchain_lib.GetToolchainsForBoard(input_proto.board)
385 output_proto.default_toolchains.extend(
386 list(toolchain_lib.FilterToolchains(toolchains, 'default', True)))
387 output_proto.nondefault_toolchains.extend(
388 list(toolchain_lib.FilterToolchains(toolchains, 'default', False)))