blob: aea031959413237be35b0a07b6fd9012d9d8154c [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
LaMont Jonesb20b3d92019-11-23 11:47:48 -070010
LaMont Jones5d2edcb2019-12-23 11:32:03 -070011from chromite.api import controller
Alex Klein076841b2019-08-29 15:19:39 -060012from chromite.api import faux
Alex Klein231d2da2019-07-22 16:44:45 -060013from chromite.api import validate
LaMont Jones5d2edcb2019-12-23 11:32:03 -070014from chromite.api.controller import controller_util
Tiancong Wang24a3df72019-08-20 15:48:51 -070015from chromite.api.gen.chromite.api import toolchain_pb2
LaMont Jonesfd68cb12020-04-29 16:43:06 -060016from chromite.api.gen.chromite.api.artifacts_pb2 import PrepareForBuildResponse
Chris McDonald1672ddb2021-07-21 11:48:23 -060017from chromite.api.gen.chromiumos.builder_config_pb2 import BuilderConfig
18from chromite.lib import chroot_util
19from chromite.lib import cros_build_lib
20from chromite.lib import toolchain_util
Ryan Beltran40e4ad12021-05-17 19:55:03 +000021from chromite.scripts import tricium_cargo_clippy
Tiancong Wangaf050172019-07-10 11:52:03 -070022
Chris McDonald1672ddb2021-07-21 11:48:23 -060023
LaMont Jonesb20b3d92019-11-23 11:47:48 -070024_Handlers = collections.namedtuple('_Handlers', ['name', 'prepare', 'bundle'])
25_TOOLCHAIN_ARTIFACT_HANDLERS = {
LaMont Jonescd1503d2020-03-04 09:09:59 -070026 BuilderConfig.Artifacts.UNVERIFIED_CHROME_LLVM_ORDERFILE:
LaMont Jonesd3944582020-03-04 10:37:05 -070027 _Handlers('UnverifiedChromeLlvmOrderfile',
LaMont Jones5d2edcb2019-12-23 11:32:03 -070028 toolchain_util.PrepareForBuild,
29 toolchain_util.BundleArtifacts),
LaMont Jonescd1503d2020-03-04 09:09:59 -070030 BuilderConfig.Artifacts.VERIFIED_CHROME_LLVM_ORDERFILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070031 _Handlers('VerifiedChromeLlvmOrderfile', toolchain_util.PrepareForBuild,
LaMont Jones5d2edcb2019-12-23 11:32:03 -070032 toolchain_util.BundleArtifacts),
LaMont Jonesb20b3d92019-11-23 11:47:48 -070033 BuilderConfig.Artifacts.CHROME_CLANG_WARNINGS_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070034 _Handlers('ChromeClangWarningsFile', toolchain_util.PrepareForBuild,
LaMont Jones90bab632020-01-27 15:58:26 -070035 toolchain_util.BundleArtifacts),
LaMont Jonesb20b3d92019-11-23 11:47:48 -070036 BuilderConfig.Artifacts.UNVERIFIED_LLVM_PGO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070037 _Handlers('UnverifiedLlvmPgoFile', toolchain_util.PrepareForBuild,
LaMont Jones90bab632020-01-27 15:58:26 -070038 toolchain_util.BundleArtifacts),
LaMont Jones45ca6c42020-02-05 09:39:09 -070039 BuilderConfig.Artifacts.UNVERIFIED_CHROME_BENCHMARK_AFDO_FILE:
40 _Handlers('UnverifiedChromeBenchmarkAfdoFile',
LaMont Jones90bab632020-01-27 15:58:26 -070041 toolchain_util.PrepareForBuild,
42 toolchain_util.BundleArtifacts),
LaMont Jones3fed7f22020-03-04 10:15:11 -070043 BuilderConfig.Artifacts.CHROME_DEBUG_BINARY:
Tiancong Wangba2a1c22021-01-19 10:45:06 -080044 _Handlers('ChromeDebugBinary', toolchain_util.PrepareForBuild,
LaMont Jones3fed7f22020-03-04 10:15:11 -070045 toolchain_util.BundleArtifacts),
LaMont Jones53bddd02020-03-12 15:02:54 -060046 BuilderConfig.Artifacts.UNVERIFIED_CHROME_BENCHMARK_PERF_FILE:
47 _Handlers('UnverifiedChromeBenchmarkPerfFile',
48 toolchain_util.PrepareForBuild,
49 toolchain_util.BundleArtifacts),
LaMont Jones45ca6c42020-02-05 09:39:09 -070050 BuilderConfig.Artifacts.VERIFIED_CHROME_BENCHMARK_AFDO_FILE:
51 _Handlers('VerifiedChromeBenchmarkAfdoFile',
LaMont Jones90bab632020-01-27 15:58:26 -070052 toolchain_util.PrepareForBuild,
53 toolchain_util.BundleArtifacts),
LaMont Jones45ca6c42020-02-05 09:39:09 -070054 BuilderConfig.Artifacts.UNVERIFIED_KERNEL_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070055 _Handlers('UnverifiedKernelCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070056 toolchain_util.BundleArtifacts),
57 BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070058 _Handlers('VerifiedKernelCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070059 toolchain_util.BundleArtifacts),
60 BuilderConfig.Artifacts.UNVERIFIED_CHROME_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070061 _Handlers('UnverifiedChromeCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070062 toolchain_util.BundleArtifacts),
63 BuilderConfig.Artifacts.VERIFIED_CHROME_CWP_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070064 _Handlers('VerifiedChromeCwpAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones45ca6c42020-02-05 09:39:09 -070065 toolchain_util.BundleArtifacts),
66 BuilderConfig.Artifacts.VERIFIED_RELEASE_AFDO_FILE:
LaMont Jones3fed7f22020-03-04 10:15:11 -070067 _Handlers('VerifiedReleaseAfdoFile', toolchain_util.PrepareForBuild,
LaMont Jones90bab632020-01-27 15:58:26 -070068 toolchain_util.BundleArtifacts),
Tiancong Wang91cf1dd2020-05-05 10:30:22 -070069 BuilderConfig.Artifacts.TOOLCHAIN_WARNING_LOGS:
70 _Handlers('ToolchainWarningLogs', toolchain_util.PrepareForBuild,
71 toolchain_util.BundleArtifacts),
Tiancong Wangfe3dbd22020-06-12 15:45:55 -070072 BuilderConfig.Artifacts.CHROME_AFDO_PROFILE_FOR_ANDROID_LINUX:
73 _Handlers('ChromeAFDOProfileForAndroidLinux',
74 toolchain_util.PrepareForBuild,
75 toolchain_util.BundleArtifacts),
Jian Cai6190cc82020-06-12 16:24:32 -070076 BuilderConfig.Artifacts.CLANG_CRASH_DIAGNOSES:
77 _Handlers('ClangCrashDiagnoses', toolchain_util.PrepareForBuild,
78 toolchain_util.BundleArtifacts),
Ryan Beltran0be7dcf2020-12-09 18:31:53 +000079 BuilderConfig.Artifacts.COMPILER_RUSAGE_LOG:
80 _Handlers('CompilerRusageLogs', toolchain_util.PrepareForBuild,
81 toolchain_util.BundleArtifacts),
LaMont Jonesb20b3d92019-11-23 11:47:48 -070082}
83
Tiancong Wangd5214132021-01-12 10:43:57 -080084_TOOLCHAIN_COMMIT_HANDLERS = {
85 BuilderConfig.Artifacts.VERIFIED_KERNEL_CWP_AFDO_FILE:
86 'VerifiedKernelCwpAfdoFile'
87}
88
LaMont Jonesb20b3d92019-11-23 11:47:48 -070089
LaMont Jonese7821672020-04-09 08:56:26 -060090def _GetProfileInfoDict(profile_info):
91 """Convert profile_info to a dict.
92
93 Args:
94 profile_info (ArtifactProfileInfo): The artifact profile_info.
95
96 Returns:
97 A dictionary containing profile info.
98 """
99 ret = {}
100 which = profile_info.WhichOneof('artifact_profile_info')
101 if which:
102 value = getattr(profile_info, which)
103 # If it is a message, then use the contents of the message. This works as
104 # long as simple types do not have a 'DESCRIPTOR' attribute. (And protobuf
105 # messages do.)
106 if getattr(value, 'DESCRIPTOR', None):
107 ret.update({k.name: v for k, v in value.ListFields()})
108 else:
109 ret[which] = value
110 return ret
111
112
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700113# TODO(crbug/1031213): When @faux is expanded to have more than success/failure,
114# this should be changed.
115@faux.all_empty
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700116@validate.require('artifact_types')
117# Note: chroot and sysroot are unspecified the first time that the build_target
118# recipe calls PrepareForBuild. The second time, they are specified. No
119# validation check because "all" values are valid.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700120@validate.validation_complete
121def PrepareForBuild(input_proto, output_proto, _config):
122 """Prepare to build toolchain artifacts.
123
124 The handlers (from _TOOLCHAIN_ARTIFACT_HANDLERS above) are called with:
125 artifact_name (str): name of the artifact type.
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700126 chroot (chroot_lib.Chroot): chroot. Will be None if the chroot has not
127 yet been created.
128 sysroot_path (str): sysroot path inside the chroot (e.g., /build/atlas).
129 Will be an empty string if the sysroot has not yet been created.
130 build_target_name (str): name of the build target (e.g., atlas). Will be
131 an empty string if the sysroot has not yet been created.
132 input_artifacts ({(str) name:[str gs_locations]}): locations for possible
133 input artifacts. The handler is expected to know which keys it should
134 be using, and ignore any keys that it does not understand.
LaMont Jonese7821672020-04-09 08:56:26 -0600135 profile_info ({(str) name: (str) value}) Dictionary containing profile
136 information.
LaMont Jonesa215f1e2019-12-06 10:18:58 -0700137
138 They locate and modify any ebuilds and/or source required for the artifact
139 being created, then return a value from toolchain_util.PrepareForBuildReturn.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700140
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700141 This function sets output_proto.build_relevance to the result.
142
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700143 Args:
144 input_proto (PrepareForToolchainBuildRequest): The input proto
145 output_proto (PrepareForToolchainBuildResponse): The output proto
146 _config (api_config.ApiConfig): The API call config.
147 """
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700148 if input_proto.chroot.path:
149 chroot = controller_util.ParseChroot(input_proto.chroot)
150 else:
151 chroot = None
LaMont Jones4579e8c2019-12-06 14:20:37 -0700152
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700153 input_artifacts = collections.defaultdict(list)
154 for art in input_proto.input_artifacts:
155 item = _TOOLCHAIN_ARTIFACT_HANDLERS.get(art.input_artifact_type)
156 if item:
157 input_artifacts[item.name].extend(
158 ['gs://%s' % str(x) for x in art.input_artifact_gs_locations])
159
LaMont Jonese7821672020-04-09 08:56:26 -0600160 profile_info = _GetProfileInfoDict(input_proto.profile_info)
LaMont Jones45ca6c42020-02-05 09:39:09 -0700161
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700162 results = set()
163 sysroot_path = input_proto.sysroot.path
164 build_target = input_proto.sysroot.build_target.name
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700165 for artifact_type in input_proto.artifact_types:
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700166 # Unknown artifact_types are an error.
167 handler = _TOOLCHAIN_ARTIFACT_HANDLERS[artifact_type]
168 if handler.prepare:
Tiancong Wangba2a1c22021-01-19 10:45:06 -0800169 results.add(
170 handler.prepare(handler.name, chroot, sysroot_path, build_target,
171 input_artifacts, profile_info))
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700172
173 # Translate the returns from the handlers we called.
174 # If any NEEDED => NEEDED
175 # elif any UNKNOWN => UNKNOWN
176 # elif any POINTLESS => POINTLESS
177 # else UNKNOWN.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700178 if toolchain_util.PrepareForBuildReturn.NEEDED in results:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600179 output_proto.build_relevance = PrepareForBuildResponse.NEEDED
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700180 elif toolchain_util.PrepareForBuildReturn.UNKNOWN in results:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600181 output_proto.build_relevance = PrepareForBuildResponse.UNKNOWN
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700182 elif toolchain_util.PrepareForBuildReturn.POINTLESS in results:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600183 output_proto.build_relevance = PrepareForBuildResponse.POINTLESS
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700184 else:
LaMont Jonesfd68cb12020-04-29 16:43:06 -0600185 output_proto.build_relevance = PrepareForBuildResponse.UNKNOWN
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700186 return controller.RETURN_CODE_SUCCESS
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700187
188
189# TODO(crbug/1031213): When @faux is expanded to have more than success/failure,
190# this should be changed.
191@faux.all_empty
LaMont Jonese911df02020-04-16 12:40:17 -0600192@validate.require('chroot.path', 'output_dir', 'artifact_types')
LaMont Jones4579e8c2019-12-06 14:20:37 -0700193@validate.exists('output_dir')
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700194@validate.validation_complete
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700195def BundleArtifacts(input_proto, output_proto, _config):
Alex Kleincd03a5e2021-10-18 13:23:47 -0600196 """Bundle valid toolchain artifacts.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700197
198 The handlers (from _TOOLCHAIN_ARTIFACT_HANDLERS above) are called with:
LaMont Jonesa215f1e2019-12-06 10:18:58 -0700199 artifact_name (str): name of the artifact type
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700200 chroot (chroot_lib.Chroot): chroot
LaMont Jonese911df02020-04-16 12:40:17 -0600201 sysroot_path (str): sysroot path inside the chroot (e.g., /build/atlas),
202 or None.
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700203 chrome_root (str): path to chrome root. (e.g., /b/s/w/ir/k/chrome)
LaMont Jonese911df02020-04-16 12:40:17 -0600204 build_target_name (str): name of the build target (e.g., atlas), or None.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700205 output_dir (str): absolute path where artifacts are being bundled.
206 (e.g., /b/s/w/ir/k/recipe_cleanup/artifactssptfMU)
LaMont Jonese7821672020-04-09 08:56:26 -0600207 profile_info ({(str) name: (str) value}) Dictionary containing profile
208 information.
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700209
210 Note: the actual upload to GS is done by CI, not here.
211
212 Args:
213 input_proto (BundleToolchainRequest): The input proto
214 output_proto (BundleToolchainResponse): The output proto
215 _config (api_config.ApiConfig): The API call config.
216 """
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700217 chroot = controller_util.ParseChroot(input_proto.chroot)
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700218
LaMont Jonese7821672020-04-09 08:56:26 -0600219 profile_info = _GetProfileInfoDict(input_proto.profile_info)
LaMont Jones45ca6c42020-02-05 09:39:09 -0700220
Alex Kleincd03a5e2021-10-18 13:23:47 -0600221 output_path = Path(input_proto.output_dir)
222
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700223 for artifact_type in input_proto.artifact_types:
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700224 if artifact_type not in _TOOLCHAIN_ARTIFACT_HANDLERS:
225 logging.error('%s not understood', artifact_type)
226 return controller.RETURN_CODE_UNRECOVERABLE
Alex Kleincd03a5e2021-10-18 13:23:47 -0600227
LaMont Jones5d2edcb2019-12-23 11:32:03 -0700228 handler = _TOOLCHAIN_ARTIFACT_HANDLERS[artifact_type]
Alex Kleincd03a5e2021-10-18 13:23:47 -0600229 if not handler or not handler.bundle:
230 logging.warning('%s does not have a handler with a bundle function.',
231 artifact_type)
232 continue
233
234 artifacts = handler.bundle(handler.name, chroot, input_proto.sysroot.path,
235 input_proto.sysroot.build_target.name,
236 input_proto.output_dir, profile_info)
237 if not artifacts:
238 continue
239
240 # Filter out artifacts that do not exist or are empty.
241 usable_artifacts = []
242 for artifact in artifacts:
243 artifact_path = output_path / artifact
244 if not artifact_path.exists():
245 logging.warning('%s is not in the output directory.', artifact)
246 elif not artifact_path.stat().st_size:
247 logging.warning('%s is empty.', artifact)
248 else:
249 usable_artifacts.append(artifact)
250
251 if not usable_artifacts:
252 logging.warning('No usable artifacts for artifact type %s', artifact_type)
253 continue
254
255 # Add all usable artifacts.
256 art_info = output_proto.artifacts_info.add()
257 art_info.artifact_type = artifact_type
258 for artifact in usable_artifacts:
259 art_info.artifacts.add().path = artifact
LaMont Jonesb20b3d92019-11-23 11:47:48 -0700260
261
Tiancong Wangd5214132021-01-12 10:43:57 -0800262def _GetUpdatedFilesResponse(_input_proto, output_proto, _config):
263 """Add successful status to the faux response."""
264 file_info = output_proto.updated_files.add()
265 file_info.path = '/any/modified/file'
266 output_proto.commit_message = 'Commit message'
267
268
269@faux.empty_error
270@faux.success(_GetUpdatedFilesResponse)
271@validate.require('uploaded_artifacts')
272@validate.validation_complete
273def GetUpdatedFiles(input_proto, output_proto, _config):
274 """Use uploaded artifacts to update some updates in a chromeos checkout.
275
276 The function will call toolchain_util.GetUpdatedFiles using the type of
277 uploaded artifacts to make some changes in a checkout, and return the list
278 of change files together with commit message.
279 updated_artifacts: A list of UpdatedArtifacts type which contains a tuple
280 of artifact info and profile info.
281 Note: the actual creation of the commit is done by CI, not here.
282
283 Args:
284 input_proto (GetUpdatedFilesRequest): The input proto
285 output_proto (GetUpdatedFilesResponse): The output proto
286 _config (api_config.ApiConfig): The API call config.
287 """
288 commit_message = ''
289 for artifact in input_proto.uploaded_artifacts:
290 artifact_type = artifact.artifact_info.artifact_type
291 if artifact_type not in _TOOLCHAIN_COMMIT_HANDLERS:
292 logging.error('%s not understood', artifact_type)
293 return controller.RETURN_CODE_UNRECOVERABLE
294 artifact_name = _TOOLCHAIN_COMMIT_HANDLERS[artifact_type]
295 if artifact_name:
296 assert len(artifact.artifact_info.artifacts) == 1, (
297 'Only one file to update per each artifact')
298 updated_files, message = toolchain_util.GetUpdatedFiles(
299 artifact_name, artifact.artifact_info.artifacts[0].path,
300 _GetProfileInfoDict(artifact.profile_info))
301 for f in updated_files:
302 file_info = output_proto.updated_files.add()
303 file_info.path = f
304
305 commit_message += message + '\n'
306 output_proto.commit_message = commit_message
307 # No commit footer is added for now. Can add more here if needed
308
309
Ryan Beltran0df7fb02021-11-10 20:58:51 +0000310@faux.all_empty
311@validate.exists('sysroot.path')
312@validate.require('packages')
313@validate.validation_complete
314def EmergeWithLinting(input_proto, output_proto, _config):
315 """Emerge packages with linter features enabled and retrieves all findings.
316
317 Args:
318 input_proto (LinterRequest): The nput proto with package and sysroot info.
319 output_proto (LinterResponse): The output proto where findings are stored.
320 _config (api_config.ApiConfig): The API call config (unused).
321 """
322 packages = [
323 f'{package.category}/{package.package_name}'
324 for package in input_proto.packages]
325 emerge_cmd = chroot_util.GetEmergeCommand(input_proto.sysroot.path)
326 cros_build_lib.sudo_run(
327 emerge_cmd + packages,
328 preserve_env=True,
329 extra_env={
330 'ENABLE_RUST_CLIPPY': 1,
331 'WITH_TIDY': 'tricium'
332 }
333 )
334
335 output_proto.findings.extend(_fetch_clippy_lints())
336
Ryan Beltran40e4ad12021-05-17 19:55:03 +0000337
338def _fetch_clippy_lints():
339 """Get lints created by Cargo Clippy during emerge."""
340 lints_dir = '/tmp/cargo_clippy'
Ryan Beltran923a1312021-07-30 00:28:13 +0000341 # FIXME(b/195056381): default git-repo should be replaced with logic in
342 # build_linters recipe to detect the repo path for applied patches.
343 # As of 07-29-21 only platform2 is supported so this value works temporarily.
344 git_repo_path = '/mnt/host/source/src/platform2'
345 findings = tricium_cargo_clippy.parse_files(lints_dir, git_repo_path)
346 findings = tricium_cargo_clippy.filter_diagnostics(findings)
Ryan Beltran40e4ad12021-05-17 19:55:03 +0000347 findings_protos = []
348 for finding in findings:
349 location_protos = []
350 for location in finding.locations:
351 location_protos.append(
352 toolchain_pb2.LinterFindingLocation(
353 filepath=location.file_path,
354 line_start=location.line_start,
355 line_end=location.line_end
356 )
357 )
358 findings_protos.append(
359 toolchain_pb2.LinterFinding(
360 message=finding.message,
361 locations=location_protos
362 )
363 )
364 return findings_protos
365
366
Ryan Beltran0df7fb02021-11-10 20:58:51 +0000367# FIXME(b/187790543): remove this endpoint oboleted by "EmergeWithLinting".
368# This refactor has the following dependency chain:
369# 1) Create EmergeWithLinting endpoint
370# 2) Let Recipe Roller update the Build API for recipes
371# 3) Update the recipe to use EmergeWithLinting
372# 4) Delete GetClippyLints endpoint
Ryan Beltran55a84832021-06-30 23:01:21 +0000373@validate.exists('sysroot.path')
374@validate.require('packages')
375@validate.validation_complete
Ryan Beltran40e4ad12021-05-17 19:55:03 +0000376def GetClippyLints(input_proto, output_proto, _config):
377 """Emerges the given packages and retrieves any findings from Cargo Clippy."""
Ryan Beltranb8909ae2021-06-30 19:59:12 +0000378 emerge_cmd = chroot_util.GetEmergeCommand(input_proto.sysroot.path)
Ryan Beltran7adc04b2021-08-03 20:16:17 +0000379 packages = [
380 f'{package.category}/{package.package_name}'
381 for package in input_proto.packages]
Ryan Beltranb8909ae2021-06-30 19:59:12 +0000382 cros_build_lib.sudo_run(
Ryan Beltran7adc04b2021-08-03 20:16:17 +0000383 emerge_cmd + packages,
384 preserve_env=True,
385 extra_env={'ENABLE_RUST_CLIPPY': 1}
Ryan Beltran40e4ad12021-05-17 19:55:03 +0000386 )
387 output_proto.findings.extend(_fetch_clippy_lints())