@@ -123,6 +123,7 @@ impl SysrootDownload {
123123 let components = ToolchainComponents :: from_binaries_and_libdir (
124124 sysroot_bin ( "rustc" ) ?,
125125 Some ( sysroot_bin ( "rustdoc" ) ?) ,
126+ Some ( sysroot_bin ( "clippy" ) ?) ,
126127 sysroot_bin ( "cargo" ) ?,
127128 & self . directory . join ( & self . rust_sha ) . join ( "lib" ) ,
128129 ) ?;
@@ -241,6 +242,7 @@ impl Toolchain {
241242pub struct ToolchainComponents {
242243 pub rustc : PathBuf ,
243244 pub rustdoc : Option < PathBuf > ,
245+ pub clippy : Option < PathBuf > ,
244246 pub cargo : PathBuf ,
245247 pub lib_rustc : Option < PathBuf > ,
246248 pub lib_std : Option < PathBuf > ,
@@ -252,12 +254,14 @@ impl ToolchainComponents {
252254 fn from_binaries_and_libdir (
253255 rustc : PathBuf ,
254256 rustdoc : Option < PathBuf > ,
257+ clippy : Option < PathBuf > ,
255258 cargo : PathBuf ,
256259 libdir : & Path ,
257260 ) -> anyhow:: Result < Self > {
258261 let mut component = ToolchainComponents {
259262 rustc,
260263 rustdoc,
264+ clippy,
261265 cargo,
262266 ..Default :: default ( )
263267 } ;
@@ -298,6 +302,7 @@ pub fn get_local_toolchain(
298302 profiles : & [ Profile ] ,
299303 rustc : & str ,
300304 rustdoc : Option < & Path > ,
305+ clippy : Option < & Path > ,
301306 cargo : Option < & Path > ,
302307 id : Option < & str > ,
303308 id_suffix : & str ,
@@ -400,6 +405,26 @@ pub fn get_local_toolchain(
400405 None
401406 } ;
402407
408+ let clippy =
409+ if let Some ( clippy) = & clippy {
410+ Some ( clippy. canonicalize ( ) . with_context ( || {
411+ format ! ( "failed to canonicalize clippy executable {:?}" , clippy)
412+ } ) ?)
413+ } else if profiles. contains ( & Profile :: Clippy ) {
414+ // We need a `clippy`. Look for one next to `rustc`.
415+ if let Ok ( clippy) = rustc. with_file_name ( "cargo-clippy" ) . canonicalize ( ) {
416+ debug ! ( "found clippy: {:?}" , & clippy) ;
417+ Some ( clippy)
418+ } else {
419+ anyhow:: bail!(
420+ "'Clippy' build specified but '--clippy' not specified and no 'cargo-clippy' found \
421+ next to 'rustc'"
422+ ) ;
423+ }
424+ } else {
425+ // No `clippy` provided, but none needed.
426+ None
427+ } ;
403428 let cargo = if let Some ( cargo) = & cargo {
404429 cargo
405430 . canonicalize ( )
@@ -428,7 +453,7 @@ pub fn get_local_toolchain(
428453 let lib_dir = get_lib_dir_from_rustc ( & rustc) . context ( "Cannot find libdir for rustc" ) ?;
429454
430455 Ok ( Toolchain {
431- components : ToolchainComponents :: from_binaries_and_libdir ( rustc, rustdoc, cargo, & lib_dir) ?,
456+ components : ToolchainComponents :: from_binaries_and_libdir ( rustc, rustdoc, clippy , cargo, & lib_dir) ?,
432457 id,
433458 triple : target_triple,
434459 } )
@@ -465,16 +490,18 @@ pub fn create_toolchain_from_published_version(
465490 } ;
466491 let rustc = which ( "rustc" ) ?;
467492 let rustdoc = which ( "rustdoc" ) ?;
493+ let clippy = which ( "clippy" ) ?;
468494 let cargo = which ( "cargo" ) ?;
469495
470496 debug ! ( "Found rustc: {}" , rustc. display( ) ) ;
471497 debug ! ( "Found rustdoc: {}" , rustdoc. display( ) ) ;
498+ debug ! ( "Found clippy: {}" , clippy. display( ) ) ;
472499 debug ! ( "Found cargo: {}" , cargo. display( ) ) ;
473500
474501 let lib_dir = get_lib_dir_from_rustc ( & rustc) ?;
475502
476503 let components =
477- ToolchainComponents :: from_binaries_and_libdir ( rustc, Some ( rustdoc) , cargo, & lib_dir) ?;
504+ ToolchainComponents :: from_binaries_and_libdir ( rustc, Some ( rustdoc) , Some ( clippy ) , cargo, & lib_dir) ?;
478505
479506 Ok ( Toolchain {
480507 components,
0 commit comments