4
4
//! but we can't process `.rlib` and need source code instead. The source code
5
5
//! is typically installed with `rustup component add rust-src` command.
6
6
7
- use std:: { env, fs, ops, process:: Command } ;
7
+ use std:: { env, fs, ops, path :: Path , process:: Command } ;
8
8
9
9
use anyhow:: { format_err, Result } ;
10
10
use base_db:: CrateName ;
@@ -170,7 +170,7 @@ impl Sysroot {
170
170
}
171
171
172
172
/// Returns a command to run a tool preferring the cargo proxies if the sysroot exists.
173
- pub fn tool ( & self , tool : Tool ) -> Command {
173
+ pub fn tool ( & self , tool : Tool , current_dir : impl AsRef < Path > ) -> Command {
174
174
match self . root ( ) {
175
175
Some ( root) => {
176
176
// special case rustc, we can look that up directly in the sysroot's bin folder
@@ -179,15 +179,15 @@ impl Sysroot {
179
179
if let Some ( path) =
180
180
probe_for_binary ( root. join ( "bin" ) . join ( Tool :: Rustc . name ( ) ) . into ( ) )
181
181
{
182
- return Command :: new ( path) ;
182
+ return toolchain :: command ( path, current_dir ) ;
183
183
}
184
184
}
185
185
186
- let mut cmd = Command :: new ( tool. prefer_proxy ( ) ) ;
186
+ let mut cmd = toolchain :: command ( tool. prefer_proxy ( ) , current_dir ) ;
187
187
cmd. env ( "RUSTUP_TOOLCHAIN" , AsRef :: < std:: path:: Path > :: as_ref ( root) ) ;
188
188
cmd
189
189
}
190
- _ => Command :: new ( tool. path ( ) ) ,
190
+ _ => toolchain :: command ( tool. path ( ) , current_dir ) ,
191
191
}
192
192
}
193
193
@@ -436,7 +436,7 @@ fn discover_sysroot_dir(
436
436
current_dir : & AbsPath ,
437
437
extra_env : & FxHashMap < String , String > ,
438
438
) -> Result < AbsPathBuf > {
439
- let mut rustc = Command :: new ( Tool :: Rustc . path ( ) ) ;
439
+ let mut rustc = toolchain :: command ( Tool :: Rustc . path ( ) , current_dir ) ;
440
440
rustc. envs ( extra_env) ;
441
441
rustc. current_dir ( current_dir) . args ( [ "--print" , "sysroot" ] ) ;
442
442
tracing:: debug!( "Discovering sysroot by {:?}" , rustc) ;
@@ -468,9 +468,9 @@ fn discover_sysroot_src_dir_or_add_component(
468
468
) -> Result < AbsPathBuf > {
469
469
discover_sysroot_src_dir ( sysroot_path)
470
470
. or_else ( || {
471
- let mut rustup = Command :: new ( Tool :: Rustup . prefer_proxy ( ) ) ;
471
+ let mut rustup = toolchain :: command ( Tool :: Rustup . prefer_proxy ( ) , current_dir ) ;
472
472
rustup. envs ( extra_env) ;
473
- rustup. current_dir ( current_dir ) . args ( [ "component" , "add" , "rust-src" ] ) ;
473
+ rustup. args ( [ "component" , "add" , "rust-src" ] ) ;
474
474
tracing:: info!( "adding rust-src component by {:?}" , rustup) ;
475
475
utf8_stdout ( & mut rustup) . ok ( ) ?;
476
476
get_rust_src ( sysroot_path)
0 commit comments