|
2 | 2 | //! metadata` or `rust-project.json`) into representation stored in the salsa
|
3 | 3 | //! database -- `CrateGraph`.
|
4 | 4 |
|
5 |
| -use std::{collections::VecDeque, fmt, fs, iter, process::Command, str::FromStr, sync}; |
| 5 | +use std::{collections::VecDeque, fmt, fs, iter, str::FromStr, sync}; |
6 | 6 |
|
7 | 7 | use anyhow::{format_err, Context};
|
8 | 8 | use base_db::{
|
@@ -172,11 +172,13 @@ impl fmt::Debug for ProjectWorkspace {
|
172 | 172 |
|
173 | 173 | fn get_toolchain_version(
|
174 | 174 | current_dir: &AbsPath,
|
175 |
| - mut cmd: Command, |
| 175 | + sysroot: Option<&Sysroot>, |
| 176 | + tool: Tool, |
176 | 177 | extra_env: &FxHashMap<String, String>,
|
177 | 178 | prefix: &str,
|
178 | 179 | ) -> Result<Option<Version>, anyhow::Error> {
|
179 | 180 | let cargo_version = utf8_stdout({
|
| 181 | + let mut cmd = Sysroot::tool(sysroot, tool); |
180 | 182 | cmd.envs(extra_env);
|
181 | 183 | cmd.arg("--version").current_dir(current_dir);
|
182 | 184 | cmd
|
@@ -297,11 +299,8 @@ impl ProjectWorkspace {
|
297 | 299 |
|
298 | 300 | let toolchain = get_toolchain_version(
|
299 | 301 | cargo_toml.parent(),
|
300 |
| - { |
301 |
| - let mut cmd = Command::new(toolchain::Tool::Cargo.path()); |
302 |
| - Sysroot::set_rustup_toolchain_env(&mut cmd, sysroot_ref); |
303 |
| - cmd |
304 |
| - }, |
| 302 | + sysroot_ref, |
| 303 | + Tool::Cargo, |
305 | 304 | &config.extra_env,
|
306 | 305 | "cargo ",
|
307 | 306 | )?;
|
@@ -386,7 +385,8 @@ impl ProjectWorkspace {
|
386 | 385 | let data_layout_config = RustcDataLayoutConfig::Rustc(sysroot_ref);
|
387 | 386 | let toolchain = match get_toolchain_version(
|
388 | 387 | project_json.path(),
|
389 |
| - Sysroot::rustc(sysroot_ref), |
| 388 | + sysroot_ref, |
| 389 | + Tool::Rustc, |
390 | 390 | extra_env,
|
391 | 391 | "rustc ",
|
392 | 392 | ) {
|
@@ -433,18 +433,15 @@ impl ProjectWorkspace {
|
433 | 433 | };
|
434 | 434 |
|
435 | 435 | let sysroot_ref = sysroot.as_ref().ok();
|
436 |
| - let toolchain = match get_toolchain_version( |
437 |
| - dir, |
438 |
| - Sysroot::rustc(sysroot_ref), |
439 |
| - &config.extra_env, |
440 |
| - "rustc ", |
441 |
| - ) { |
442 |
| - Ok(it) => it, |
443 |
| - Err(e) => { |
444 |
| - tracing::error!("{e}"); |
445 |
| - None |
446 |
| - } |
447 |
| - }; |
| 436 | + let toolchain = |
| 437 | + match get_toolchain_version(dir, sysroot_ref, Tool::Rustc, &config.extra_env, "rustc ") |
| 438 | + { |
| 439 | + Ok(it) => it, |
| 440 | + Err(e) => { |
| 441 | + tracing::error!("{e}"); |
| 442 | + None |
| 443 | + } |
| 444 | + }; |
448 | 445 |
|
449 | 446 | let rustc_cfg = rustc_cfg::get(None, &config.extra_env, RustcCfgConfig::Rustc(sysroot_ref));
|
450 | 447 | let data_layout = target_data_layout::get(
|
@@ -1573,8 +1570,7 @@ fn cargo_config_env(
|
1573 | 1570 | extra_env: &FxHashMap<String, String>,
|
1574 | 1571 | sysroot: Option<&Sysroot>,
|
1575 | 1572 | ) -> FxHashMap<String, String> {
|
1576 |
| - let mut cargo_config = Command::new(Tool::Cargo.path()); |
1577 |
| - Sysroot::set_rustup_toolchain_env(&mut cargo_config, sysroot); |
| 1573 | + let mut cargo_config = Sysroot::tool(sysroot, Tool::Cargo); |
1578 | 1574 | cargo_config.envs(extra_env);
|
1579 | 1575 | cargo_config
|
1580 | 1576 | .current_dir(cargo_toml.parent())
|
|
0 commit comments