mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 20:31:59 +00:00
allow using null to unset an environment variable
this makes three changes: - all callsites of `toolchain::command` are changed to use `command(path, extra_env)`, instead of manually adding the env after the fact. - all `map<str, str>` are changed to `map<str, option<str>>`. - `command` checks for None and calls `env_remove` if so. this caught several places where environment variables weren't being propagated: - when running `rustc --print=target-libdir` - when running `cargo rustc -- --print=target-spec-json` - when running the custom DiscoverLinkedProjects config. I *think* this is for use with non-cargo build systems, so I didn't change it.
This commit is contained in:
parent
a09a5502c3
commit
3b964a7105
19 changed files with 114 additions and 91 deletions
|
|
@ -66,7 +66,7 @@ pub fn load_workspace_at(
|
||||||
|
|
||||||
pub fn load_workspace(
|
pub fn load_workspace(
|
||||||
ws: ProjectWorkspace,
|
ws: ProjectWorkspace,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
load_config: &LoadCargoConfig,
|
load_config: &LoadCargoConfig,
|
||||||
) -> anyhow::Result<(RootDatabase, vfs::Vfs, Option<ProcMacroClient>)> {
|
) -> anyhow::Result<(RootDatabase, vfs::Vfs, Option<ProcMacroClient>)> {
|
||||||
let (sender, receiver) = unbounded();
|
let (sender, receiver) = unbounded();
|
||||||
|
|
|
||||||
|
|
@ -105,10 +105,11 @@ impl fmt::Display for ServerError {
|
||||||
|
|
||||||
impl ProcMacroClient {
|
impl ProcMacroClient {
|
||||||
/// Spawns an external process as the proc macro server and returns a client connected to it.
|
/// Spawns an external process as the proc macro server and returns a client connected to it.
|
||||||
pub fn spawn(
|
pub fn spawn<'a>(
|
||||||
process_path: &AbsPath,
|
process_path: &AbsPath,
|
||||||
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>
|
env: impl IntoIterator<
|
||||||
+ Clone,
|
Item = (impl AsRef<std::ffi::OsStr>, &'a Option<impl 'a + AsRef<std::ffi::OsStr>>),
|
||||||
|
> + Clone,
|
||||||
) -> io::Result<ProcMacroClient> {
|
) -> io::Result<ProcMacroClient> {
|
||||||
let process = ProcMacroServerProcess::run(process_path, env)?;
|
let process = ProcMacroServerProcess::run(process_path, env)?;
|
||||||
Ok(ProcMacroClient { process: Arc::new(process), path: process_path.to_owned() })
|
Ok(ProcMacroClient { process: Arc::new(process), path: process_path.to_owned() })
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,11 @@ struct ProcessSrvState {
|
||||||
|
|
||||||
impl ProcMacroServerProcess {
|
impl ProcMacroServerProcess {
|
||||||
/// Starts the proc-macro server and performs a version check
|
/// Starts the proc-macro server and performs a version check
|
||||||
pub(crate) fn run(
|
pub(crate) fn run<'a>(
|
||||||
process_path: &AbsPath,
|
process_path: &AbsPath,
|
||||||
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>
|
env: impl IntoIterator<
|
||||||
+ Clone,
|
Item = (impl AsRef<std::ffi::OsStr>, &'a Option<impl 'a + AsRef<std::ffi::OsStr>>),
|
||||||
|
> + Clone,
|
||||||
) -> io::Result<ProcMacroServerProcess> {
|
) -> io::Result<ProcMacroServerProcess> {
|
||||||
let create_srv = || {
|
let create_srv = || {
|
||||||
let mut process = Process::run(process_path, env.clone())?;
|
let mut process = Process::run(process_path, env.clone())?;
|
||||||
|
|
@ -193,9 +194,11 @@ struct Process {
|
||||||
|
|
||||||
impl Process {
|
impl Process {
|
||||||
/// Runs a new proc-macro server process with the specified environment variables.
|
/// Runs a new proc-macro server process with the specified environment variables.
|
||||||
fn run(
|
fn run<'a>(
|
||||||
path: &AbsPath,
|
path: &AbsPath,
|
||||||
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>,
|
env: impl IntoIterator<
|
||||||
|
Item = (impl AsRef<std::ffi::OsStr>, &'a Option<impl 'a + AsRef<std::ffi::OsStr>>),
|
||||||
|
>,
|
||||||
) -> io::Result<Process> {
|
) -> io::Result<Process> {
|
||||||
let child = JodChild(mk_child(path, env)?);
|
let child = JodChild(mk_child(path, env)?);
|
||||||
Ok(Process { child })
|
Ok(Process { child })
|
||||||
|
|
@ -212,14 +215,21 @@ impl Process {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates and configures a new child process for the proc-macro server.
|
/// Creates and configures a new child process for the proc-macro server.
|
||||||
fn mk_child(
|
fn mk_child<'a>(
|
||||||
path: &AbsPath,
|
path: &AbsPath,
|
||||||
env: impl IntoIterator<Item = (impl AsRef<std::ffi::OsStr>, impl AsRef<std::ffi::OsStr>)>,
|
extra_env: impl IntoIterator<
|
||||||
|
Item = (impl AsRef<std::ffi::OsStr>, &'a Option<impl 'a + AsRef<std::ffi::OsStr>>),
|
||||||
|
>,
|
||||||
) -> io::Result<Child> {
|
) -> io::Result<Child> {
|
||||||
#[allow(clippy::disallowed_methods)]
|
#[allow(clippy::disallowed_methods)]
|
||||||
let mut cmd = Command::new(path);
|
let mut cmd = Command::new(path);
|
||||||
cmd.envs(env)
|
for env in extra_env {
|
||||||
.env("RUST_ANALYZER_INTERNALS_DO_NOT_USE", "this is unstable")
|
match env {
|
||||||
|
(key, Some(val)) => cmd.env(key, val),
|
||||||
|
(key, None) => cmd.env_remove(key),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
cmd.env("RUST_ANALYZER_INTERNALS_DO_NOT_USE", "this is unstable")
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.stderr(Stdio::inherit());
|
.stderr(Stdio::inherit());
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ impl WorkspaceBuildScripts {
|
||||||
pub(crate) fn rustc_crates(
|
pub(crate) fn rustc_crates(
|
||||||
rustc: &CargoWorkspace,
|
rustc: &CargoWorkspace,
|
||||||
current_dir: &AbsPath,
|
current_dir: &AbsPath,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
sysroot: &Sysroot,
|
sysroot: &Sysroot,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut bs = WorkspaceBuildScripts::default();
|
let mut bs = WorkspaceBuildScripts::default();
|
||||||
|
|
@ -172,16 +172,14 @@ impl WorkspaceBuildScripts {
|
||||||
}
|
}
|
||||||
let res = (|| {
|
let res = (|| {
|
||||||
let target_libdir = (|| {
|
let target_libdir = (|| {
|
||||||
let mut cargo_config = sysroot.tool(Tool::Cargo, current_dir);
|
let mut cargo_config = sysroot.tool(Tool::Cargo, current_dir, extra_env);
|
||||||
cargo_config.envs(extra_env);
|
|
||||||
cargo_config
|
cargo_config
|
||||||
.args(["rustc", "-Z", "unstable-options", "--print", "target-libdir"])
|
.args(["rustc", "-Z", "unstable-options", "--print", "target-libdir"])
|
||||||
.env("RUSTC_BOOTSTRAP", "1");
|
.env("RUSTC_BOOTSTRAP", "1");
|
||||||
if let Ok(it) = utf8_stdout(&mut cargo_config) {
|
if let Ok(it) = utf8_stdout(&mut cargo_config) {
|
||||||
return Ok(it);
|
return Ok(it);
|
||||||
}
|
}
|
||||||
let mut cmd = sysroot.tool(Tool::Rustc, current_dir);
|
let mut cmd = sysroot.tool(Tool::Rustc, current_dir, extra_env);
|
||||||
cmd.envs(extra_env);
|
|
||||||
cmd.args(["--print", "target-libdir"]);
|
cmd.args(["--print", "target-libdir"]);
|
||||||
utf8_stdout(&mut cmd)
|
utf8_stdout(&mut cmd)
|
||||||
})()?;
|
})()?;
|
||||||
|
|
@ -390,12 +388,12 @@ impl WorkspaceBuildScripts {
|
||||||
) -> io::Result<Command> {
|
) -> io::Result<Command> {
|
||||||
let mut cmd = match config.run_build_script_command.as_deref() {
|
let mut cmd = match config.run_build_script_command.as_deref() {
|
||||||
Some([program, args @ ..]) => {
|
Some([program, args @ ..]) => {
|
||||||
let mut cmd = toolchain::command(program, current_dir);
|
let mut cmd = toolchain::command(program, current_dir, &config.extra_env);
|
||||||
cmd.args(args);
|
cmd.args(args);
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let mut cmd = sysroot.tool(Tool::Cargo, current_dir);
|
let mut cmd = sysroot.tool(Tool::Cargo, current_dir, &config.extra_env);
|
||||||
|
|
||||||
cmd.args(["check", "--quiet", "--workspace", "--message-format=json"]);
|
cmd.args(["check", "--quiet", "--workspace", "--message-format=json"]);
|
||||||
cmd.args(&config.extra_args);
|
cmd.args(&config.extra_args);
|
||||||
|
|
@ -448,7 +446,6 @@ impl WorkspaceBuildScripts {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
cmd.envs(&config.extra_env);
|
|
||||||
if config.wrap_rustc_in_build_scripts {
|
if config.wrap_rustc_in_build_scripts {
|
||||||
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
|
// Setup RUSTC_WRAPPER to point to `rust-analyzer` binary itself. We use
|
||||||
// that to compile only proc macros and build scripts during the initial
|
// that to compile only proc macros and build scripts during the initial
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ pub struct CargoConfig {
|
||||||
/// Extra args to pass to the cargo command.
|
/// Extra args to pass to the cargo command.
|
||||||
pub extra_args: Vec<String>,
|
pub extra_args: Vec<String>,
|
||||||
/// Extra env vars to set when invoking the cargo command
|
/// Extra env vars to set when invoking the cargo command
|
||||||
pub extra_env: FxHashMap<String, String>,
|
pub extra_env: FxHashMap<String, Option<String>>,
|
||||||
pub invocation_strategy: InvocationStrategy,
|
pub invocation_strategy: InvocationStrategy,
|
||||||
/// Optional path to use instead of `target` when building
|
/// Optional path to use instead of `target` when building
|
||||||
pub target_dir: Option<Utf8PathBuf>,
|
pub target_dir: Option<Utf8PathBuf>,
|
||||||
|
|
@ -289,7 +289,7 @@ pub struct CargoMetadataConfig {
|
||||||
/// Extra args to pass to the cargo command.
|
/// Extra args to pass to the cargo command.
|
||||||
pub extra_args: Vec<String>,
|
pub extra_args: Vec<String>,
|
||||||
/// Extra env vars to set when invoking the cargo command
|
/// Extra env vars to set when invoking the cargo command
|
||||||
pub extra_env: FxHashMap<String, String>,
|
pub extra_env: FxHashMap<String, Option<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deserialize helper for the cargo metadata
|
// Deserialize helper for the cargo metadata
|
||||||
|
|
@ -343,11 +343,10 @@ impl CargoWorkspace {
|
||||||
locked: bool,
|
locked: bool,
|
||||||
progress: &dyn Fn(String),
|
progress: &dyn Fn(String),
|
||||||
) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> {
|
) -> anyhow::Result<(cargo_metadata::Metadata, Option<anyhow::Error>)> {
|
||||||
let cargo = sysroot.tool(Tool::Cargo, current_dir);
|
let cargo = sysroot.tool(Tool::Cargo, current_dir, &config.extra_env);
|
||||||
let mut meta = MetadataCommand::new();
|
let mut meta = MetadataCommand::new();
|
||||||
meta.cargo_path(cargo.get_program());
|
meta.cargo_path(cargo.get_program());
|
||||||
cargo.get_envs().for_each(|(var, val)| _ = meta.env(var, val.unwrap_or_default()));
|
cargo.get_envs().for_each(|(var, val)| _ = meta.env(var, val.unwrap_or_default()));
|
||||||
config.extra_env.iter().for_each(|(var, val)| _ = meta.env(var, val));
|
|
||||||
meta.manifest_path(cargo_toml.to_path_buf());
|
meta.manifest_path(cargo_toml.to_path_buf());
|
||||||
match &config.features {
|
match &config.features {
|
||||||
CargoFeatures::All => {
|
CargoFeatures::All => {
|
||||||
|
|
|
||||||
|
|
@ -62,11 +62,10 @@ pub(crate) fn inject_rustc_tool_env(env: &mut Env, cargo_name: &str, kind: Targe
|
||||||
|
|
||||||
pub(crate) fn cargo_config_env(
|
pub(crate) fn cargo_config_env(
|
||||||
manifest: &ManifestPath,
|
manifest: &ManifestPath,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
sysroot: &Sysroot,
|
sysroot: &Sysroot,
|
||||||
) -> Env {
|
) -> Env {
|
||||||
let mut cargo_config = sysroot.tool(Tool::Cargo, manifest.parent());
|
let mut cargo_config = sysroot.tool(Tool::Cargo, manifest.parent(), extra_env);
|
||||||
cargo_config.envs(extra_env);
|
|
||||||
cargo_config
|
cargo_config
|
||||||
.args(["-Z", "unstable-options", "config", "get", "env"])
|
.args(["-Z", "unstable-options", "config", "get", "env"])
|
||||||
.env("RUSTC_BOOTSTRAP", "1");
|
.env("RUSTC_BOOTSTRAP", "1");
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ impl Sysroot {
|
||||||
|
|
||||||
impl Sysroot {
|
impl Sysroot {
|
||||||
/// Attempts to discover the toolchain's sysroot from the given `dir`.
|
/// Attempts to discover the toolchain's sysroot from the given `dir`.
|
||||||
pub fn discover(dir: &AbsPath, extra_env: &FxHashMap<String, String>) -> Sysroot {
|
pub fn discover(dir: &AbsPath, extra_env: &FxHashMap<String, Option<String>>) -> Sysroot {
|
||||||
let sysroot_dir = discover_sysroot_dir(dir, extra_env);
|
let sysroot_dir = discover_sysroot_dir(dir, extra_env);
|
||||||
let rust_lib_src_dir = sysroot_dir.as_ref().ok().map(|sysroot_dir| {
|
let rust_lib_src_dir = sysroot_dir.as_ref().ok().map(|sysroot_dir| {
|
||||||
discover_rust_lib_src_dir_or_add_component(sysroot_dir, dir, extra_env)
|
discover_rust_lib_src_dir_or_add_component(sysroot_dir, dir, extra_env)
|
||||||
|
|
@ -96,7 +96,7 @@ impl Sysroot {
|
||||||
|
|
||||||
pub fn discover_with_src_override(
|
pub fn discover_with_src_override(
|
||||||
current_dir: &AbsPath,
|
current_dir: &AbsPath,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
rust_lib_src_dir: AbsPathBuf,
|
rust_lib_src_dir: AbsPathBuf,
|
||||||
) -> Sysroot {
|
) -> Sysroot {
|
||||||
let sysroot_dir = discover_sysroot_dir(current_dir, extra_env);
|
let sysroot_dir = discover_sysroot_dir(current_dir, extra_env);
|
||||||
|
|
@ -118,7 +118,12 @@ impl Sysroot {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a command to run a tool preferring the cargo proxies if the sysroot exists.
|
/// Returns a command to run a tool preferring the cargo proxies if the sysroot exists.
|
||||||
pub fn tool(&self, tool: Tool, current_dir: impl AsRef<Path>) -> Command {
|
pub fn tool(
|
||||||
|
&self,
|
||||||
|
tool: Tool,
|
||||||
|
current_dir: impl AsRef<Path>,
|
||||||
|
envs: &FxHashMap<String, Option<String>>,
|
||||||
|
) -> Command {
|
||||||
match self.root() {
|
match self.root() {
|
||||||
Some(root) => {
|
Some(root) => {
|
||||||
// special case rustc, we can look that up directly in the sysroot's bin folder
|
// special case rustc, we can look that up directly in the sysroot's bin folder
|
||||||
|
|
@ -127,15 +132,15 @@ impl Sysroot {
|
||||||
if let Some(path) =
|
if let Some(path) =
|
||||||
probe_for_binary(root.join("bin").join(Tool::Rustc.name()).into())
|
probe_for_binary(root.join("bin").join(Tool::Rustc.name()).into())
|
||||||
{
|
{
|
||||||
return toolchain::command(path, current_dir);
|
return toolchain::command(path, current_dir, envs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cmd = toolchain::command(tool.prefer_proxy(), current_dir);
|
let mut cmd = toolchain::command(tool.prefer_proxy(), current_dir, envs);
|
||||||
cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(root));
|
cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(root));
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
_ => toolchain::command(tool.path(), current_dir),
|
_ => toolchain::command(tool.path(), current_dir, envs),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -292,7 +297,7 @@ impl Sysroot {
|
||||||
// the sysroot uses `public-dependency`, so we make cargo think it's a nightly
|
// the sysroot uses `public-dependency`, so we make cargo think it's a nightly
|
||||||
cargo_config.extra_env.insert(
|
cargo_config.extra_env.insert(
|
||||||
"__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS".to_owned(),
|
"__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS".to_owned(),
|
||||||
"nightly".to_owned(),
|
Some("nightly".to_owned()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let (mut res, _) = match CargoWorkspace::fetch_metadata(
|
let (mut res, _) = match CargoWorkspace::fetch_metadata(
|
||||||
|
|
@ -368,10 +373,9 @@ impl Sysroot {
|
||||||
|
|
||||||
fn discover_sysroot_dir(
|
fn discover_sysroot_dir(
|
||||||
current_dir: &AbsPath,
|
current_dir: &AbsPath,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
) -> Result<AbsPathBuf> {
|
) -> Result<AbsPathBuf> {
|
||||||
let mut rustc = toolchain::command(Tool::Rustc.path(), current_dir);
|
let mut rustc = toolchain::command(Tool::Rustc.path(), current_dir, extra_env);
|
||||||
rustc.envs(extra_env);
|
|
||||||
rustc.current_dir(current_dir).args(["--print", "sysroot"]);
|
rustc.current_dir(current_dir).args(["--print", "sysroot"]);
|
||||||
tracing::debug!("Discovering sysroot by {:?}", rustc);
|
tracing::debug!("Discovering sysroot by {:?}", rustc);
|
||||||
let stdout = utf8_stdout(&mut rustc)?;
|
let stdout = utf8_stdout(&mut rustc)?;
|
||||||
|
|
@ -398,12 +402,11 @@ fn discover_rust_lib_src_dir(sysroot_path: &AbsPathBuf) -> Option<AbsPathBuf> {
|
||||||
fn discover_rust_lib_src_dir_or_add_component(
|
fn discover_rust_lib_src_dir_or_add_component(
|
||||||
sysroot_path: &AbsPathBuf,
|
sysroot_path: &AbsPathBuf,
|
||||||
current_dir: &AbsPath,
|
current_dir: &AbsPath,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
) -> Result<AbsPathBuf> {
|
) -> Result<AbsPathBuf> {
|
||||||
discover_rust_lib_src_dir(sysroot_path)
|
discover_rust_lib_src_dir(sysroot_path)
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
let mut rustup = toolchain::command(Tool::Rustup.prefer_proxy(), current_dir);
|
let mut rustup = toolchain::command(Tool::Rustup.prefer_proxy(), current_dir, extra_env);
|
||||||
rustup.envs(extra_env);
|
|
||||||
rustup.args(["component", "add", "rust-src"]);
|
rustup.args(["component", "add", "rust-src"]);
|
||||||
tracing::info!("adding rust-src component by {:?}", rustup);
|
tracing::info!("adding rust-src component by {:?}", rustup);
|
||||||
utf8_stdout(&mut rustup).ok()?;
|
utf8_stdout(&mut rustup).ok()?;
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use crate::{toolchain_info::QueryConfig, utf8_stdout};
|
||||||
pub fn get(
|
pub fn get(
|
||||||
config: QueryConfig<'_>,
|
config: QueryConfig<'_>,
|
||||||
target: Option<&str>,
|
target: Option<&str>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
) -> Vec<CfgAtom> {
|
) -> Vec<CfgAtom> {
|
||||||
let _p = tracing::info_span!("rustc_cfg::get").entered();
|
let _p = tracing::info_span!("rustc_cfg::get").entered();
|
||||||
|
|
||||||
|
|
@ -58,14 +58,13 @@ pub fn get(
|
||||||
|
|
||||||
fn rustc_print_cfg(
|
fn rustc_print_cfg(
|
||||||
target: Option<&str>,
|
target: Option<&str>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
config: QueryConfig<'_>,
|
config: QueryConfig<'_>,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
const RUSTC_ARGS: [&str; 2] = ["--print", "cfg"];
|
const RUSTC_ARGS: [&str; 2] = ["--print", "cfg"];
|
||||||
let (sysroot, current_dir) = match config {
|
let (sysroot, current_dir) = match config {
|
||||||
QueryConfig::Cargo(sysroot, cargo_toml) => {
|
QueryConfig::Cargo(sysroot, cargo_toml) => {
|
||||||
let mut cmd = sysroot.tool(Tool::Cargo, cargo_toml.parent());
|
let mut cmd = sysroot.tool(Tool::Cargo, cargo_toml.parent(), extra_env);
|
||||||
cmd.envs(extra_env);
|
|
||||||
cmd.args(["rustc", "-Z", "unstable-options"]).args(RUSTC_ARGS);
|
cmd.args(["rustc", "-Z", "unstable-options"]).args(RUSTC_ARGS);
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
cmd.args(["--target", target]);
|
cmd.args(["--target", target]);
|
||||||
|
|
@ -86,8 +85,7 @@ fn rustc_print_cfg(
|
||||||
QueryConfig::Rustc(sysroot, current_dir) => (sysroot, current_dir),
|
QueryConfig::Rustc(sysroot, current_dir) => (sysroot, current_dir),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut cmd = sysroot.tool(Tool::Rustc, current_dir);
|
let mut cmd = sysroot.tool(Tool::Rustc, current_dir, extra_env);
|
||||||
cmd.envs(extra_env);
|
|
||||||
cmd.args(RUSTC_ARGS);
|
cmd.args(RUSTC_ARGS);
|
||||||
cmd.arg("-O");
|
cmd.arg("-O");
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use crate::{Sysroot, toolchain_info::QueryConfig, utf8_stdout};
|
||||||
pub fn get(
|
pub fn get(
|
||||||
config: QueryConfig<'_>,
|
config: QueryConfig<'_>,
|
||||||
target: Option<&str>,
|
target: Option<&str>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
const RUSTC_ARGS: [&str; 2] = ["--print", "target-spec-json"];
|
const RUSTC_ARGS: [&str; 2] = ["--print", "target-spec-json"];
|
||||||
let process = |output: String| {
|
let process = |output: String| {
|
||||||
|
|
@ -21,8 +21,7 @@ pub fn get(
|
||||||
};
|
};
|
||||||
let (sysroot, current_dir) = match config {
|
let (sysroot, current_dir) = match config {
|
||||||
QueryConfig::Cargo(sysroot, cargo_toml) => {
|
QueryConfig::Cargo(sysroot, cargo_toml) => {
|
||||||
let mut cmd = sysroot.tool(Tool::Cargo, cargo_toml.parent());
|
let mut cmd = sysroot.tool(Tool::Cargo, cargo_toml.parent(), extra_env);
|
||||||
cmd.envs(extra_env);
|
|
||||||
cmd.env("RUSTC_BOOTSTRAP", "1");
|
cmd.env("RUSTC_BOOTSTRAP", "1");
|
||||||
cmd.args(["rustc", "-Z", "unstable-options"]).args(RUSTC_ARGS).args([
|
cmd.args(["rustc", "-Z", "unstable-options"]).args(RUSTC_ARGS).args([
|
||||||
"--",
|
"--",
|
||||||
|
|
@ -43,11 +42,8 @@ pub fn get(
|
||||||
QueryConfig::Rustc(sysroot, current_dir) => (sysroot, current_dir),
|
QueryConfig::Rustc(sysroot, current_dir) => (sysroot, current_dir),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut cmd = Sysroot::tool(sysroot, Tool::Rustc, current_dir);
|
let mut cmd = Sysroot::tool(sysroot, Tool::Rustc, current_dir, extra_env);
|
||||||
cmd.envs(extra_env)
|
cmd.env("RUSTC_BOOTSTRAP", "1").args(["-Z", "unstable-options"]).args(RUSTC_ARGS);
|
||||||
.env("RUSTC_BOOTSTRAP", "1")
|
|
||||||
.args(["-Z", "unstable-options"])
|
|
||||||
.args(RUSTC_ARGS);
|
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
cmd.args(["--target", target]);
|
cmd.args(["--target", target]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use crate::{ManifestPath, Sysroot, toolchain_info::QueryConfig, utf8_stdout};
|
||||||
pub fn get(
|
pub fn get(
|
||||||
config: QueryConfig<'_>,
|
config: QueryConfig<'_>,
|
||||||
target: Option<&str>,
|
target: Option<&str>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
) -> anyhow::Result<Vec<String>> {
|
) -> anyhow::Result<Vec<String>> {
|
||||||
let _p = tracing::info_span!("target_tuple::get").entered();
|
let _p = tracing::info_span!("target_tuple::get").entered();
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
|
|
@ -32,12 +32,11 @@ pub fn get(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rustc_discover_host_tuple(
|
fn rustc_discover_host_tuple(
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
sysroot: &Sysroot,
|
sysroot: &Sysroot,
|
||||||
current_dir: &Path,
|
current_dir: &Path,
|
||||||
) -> anyhow::Result<String> {
|
) -> anyhow::Result<String> {
|
||||||
let mut cmd = sysroot.tool(Tool::Rustc, current_dir);
|
let mut cmd = sysroot.tool(Tool::Rustc, current_dir, extra_env);
|
||||||
cmd.envs(extra_env);
|
|
||||||
cmd.arg("-vV");
|
cmd.arg("-vV");
|
||||||
let stdout = utf8_stdout(&mut cmd)
|
let stdout = utf8_stdout(&mut cmd)
|
||||||
.with_context(|| format!("unable to discover host platform via `{cmd:?}`"))?;
|
.with_context(|| format!("unable to discover host platform via `{cmd:?}`"))?;
|
||||||
|
|
@ -53,11 +52,10 @@ fn rustc_discover_host_tuple(
|
||||||
|
|
||||||
fn cargo_config_build_target(
|
fn cargo_config_build_target(
|
||||||
cargo_toml: &ManifestPath,
|
cargo_toml: &ManifestPath,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
sysroot: &Sysroot,
|
sysroot: &Sysroot,
|
||||||
) -> Option<Vec<String>> {
|
) -> Option<Vec<String>> {
|
||||||
let mut cmd = sysroot.tool(Tool::Cargo, cargo_toml.parent());
|
let mut cmd = sysroot.tool(Tool::Cargo, cargo_toml.parent(), extra_env);
|
||||||
cmd.envs(extra_env);
|
|
||||||
cmd.current_dir(cargo_toml.parent()).env("RUSTC_BOOTSTRAP", "1");
|
cmd.current_dir(cargo_toml.parent()).env("RUSTC_BOOTSTRAP", "1");
|
||||||
cmd.args(["-Z", "unstable-options", "config", "get", "build.target"]);
|
cmd.args(["-Z", "unstable-options", "config", "get", "build.target"]);
|
||||||
// if successful we receive `build.target = "target-tuple"`
|
// if successful we receive `build.target = "target-tuple"`
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,16 @@ use crate::{toolchain_info::QueryConfig, utf8_stdout};
|
||||||
|
|
||||||
pub(crate) fn get(
|
pub(crate) fn get(
|
||||||
config: QueryConfig<'_>,
|
config: QueryConfig<'_>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
) -> Result<Option<Version>, anyhow::Error> {
|
) -> Result<Option<Version>, anyhow::Error> {
|
||||||
let (mut cmd, prefix) = match config {
|
let (mut cmd, prefix) = match config {
|
||||||
QueryConfig::Cargo(sysroot, cargo_toml) => {
|
QueryConfig::Cargo(sysroot, cargo_toml) => {
|
||||||
(sysroot.tool(Tool::Cargo, cargo_toml.parent()), "cargo ")
|
(sysroot.tool(Tool::Cargo, cargo_toml.parent(), extra_env), "cargo ")
|
||||||
}
|
}
|
||||||
QueryConfig::Rustc(sysroot, current_dir) => {
|
QueryConfig::Rustc(sysroot, current_dir) => {
|
||||||
(sysroot.tool(Tool::Rustc, current_dir), "rustc ")
|
(sysroot.tool(Tool::Rustc, current_dir, extra_env), "rustc ")
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
cmd.envs(extra_env);
|
|
||||||
cmd.arg("--version");
|
cmd.arg("--version");
|
||||||
let out = utf8_stdout(&mut cmd).with_context(|| format!("Failed to query rust toolchain version via `{cmd:?}`, is your toolchain setup correctly?"))?;
|
let out = utf8_stdout(&mut cmd).with_context(|| format!("Failed to query rust toolchain version via `{cmd:?}`, is your toolchain setup correctly?"))?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -856,7 +856,7 @@ impl ProjectWorkspace {
|
||||||
pub fn to_crate_graph(
|
pub fn to_crate_graph(
|
||||||
&self,
|
&self,
|
||||||
load: FileLoader<'_>,
|
load: FileLoader<'_>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
) -> (CrateGraphBuilder, ProcMacroPaths) {
|
) -> (CrateGraphBuilder, ProcMacroPaths) {
|
||||||
let _p = tracing::info_span!("ProjectWorkspace::to_crate_graph").entered();
|
let _p = tracing::info_span!("ProjectWorkspace::to_crate_graph").entered();
|
||||||
|
|
||||||
|
|
@ -974,7 +974,7 @@ fn project_json_to_crate_graph(
|
||||||
load: FileLoader<'_>,
|
load: FileLoader<'_>,
|
||||||
project: &ProjectJson,
|
project: &ProjectJson,
|
||||||
sysroot: &Sysroot,
|
sysroot: &Sysroot,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
override_cfg: &CfgOverrides,
|
override_cfg: &CfgOverrides,
|
||||||
set_test: bool,
|
set_test: bool,
|
||||||
is_sysroot: bool,
|
is_sysroot: bool,
|
||||||
|
|
@ -1806,7 +1806,7 @@ fn add_dep_inner(graph: &mut CrateGraphBuilder, from: CrateBuilderId, dep: Depen
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sysroot_metadata_config(
|
fn sysroot_metadata_config(
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
targets: &[String],
|
targets: &[String],
|
||||||
) -> CargoMetadataConfig {
|
) -> CargoMetadataConfig {
|
||||||
CargoMetadataConfig {
|
CargoMetadataConfig {
|
||||||
|
|
|
||||||
|
|
@ -602,7 +602,7 @@ config_data! {
|
||||||
cargo_extraArgs: Vec<String> = vec![],
|
cargo_extraArgs: Vec<String> = vec![],
|
||||||
/// Extra environment variables that will be set when running cargo, rustc
|
/// Extra environment variables that will be set when running cargo, rustc
|
||||||
/// or other commands within the workspace. Useful for setting RUSTFLAGS.
|
/// or other commands within the workspace. Useful for setting RUSTFLAGS.
|
||||||
cargo_extraEnv: FxHashMap<String, String> = FxHashMap::default(),
|
cargo_extraEnv: FxHashMap<String, Option<String>> = FxHashMap::default(),
|
||||||
/// List of features to activate.
|
/// List of features to activate.
|
||||||
///
|
///
|
||||||
/// Set this to `"all"` to pass `--all-features` to cargo.
|
/// Set this to `"all"` to pass `--all-features` to cargo.
|
||||||
|
|
@ -652,7 +652,7 @@ config_data! {
|
||||||
check_extraArgs | checkOnSave_extraArgs: Vec<String> = vec![],
|
check_extraArgs | checkOnSave_extraArgs: Vec<String> = vec![],
|
||||||
/// Extra environment variables that will be set when running `cargo check`.
|
/// Extra environment variables that will be set when running `cargo check`.
|
||||||
/// Extends `#rust-analyzer.cargo.extraEnv#`.
|
/// Extends `#rust-analyzer.cargo.extraEnv#`.
|
||||||
check_extraEnv | checkOnSave_extraEnv: FxHashMap<String, String> = FxHashMap::default(),
|
check_extraEnv | checkOnSave_extraEnv: FxHashMap<String, Option<String>> = FxHashMap::default(),
|
||||||
/// List of features to activate. Defaults to
|
/// List of features to activate. Defaults to
|
||||||
/// `#rust-analyzer.cargo.features#`.
|
/// `#rust-analyzer.cargo.features#`.
|
||||||
///
|
///
|
||||||
|
|
@ -1879,7 +1879,10 @@ impl Config {
|
||||||
self.cargo_extraArgs(source_root)
|
self.cargo_extraArgs(source_root)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn extra_env(&self, source_root: Option<SourceRootId>) -> &FxHashMap<String, String> {
|
pub fn extra_env(
|
||||||
|
&self,
|
||||||
|
source_root: Option<SourceRootId>,
|
||||||
|
) -> &FxHashMap<String, Option<String>> {
|
||||||
self.cargo_extraEnv(source_root)
|
self.cargo_extraEnv(source_root)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1889,7 +1892,10 @@ impl Config {
|
||||||
extra_args
|
extra_args
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_extra_env(&self, source_root: Option<SourceRootId>) -> FxHashMap<String, String> {
|
pub fn check_extra_env(
|
||||||
|
&self,
|
||||||
|
source_root: Option<SourceRootId>,
|
||||||
|
) -> FxHashMap<String, Option<String>> {
|
||||||
let mut extra_env = self.cargo_extraEnv(source_root).clone();
|
let mut extra_env = self.cargo_extraEnv(source_root).clone();
|
||||||
extra_env.extend(self.check_extraEnv(source_root).clone());
|
extra_env.extend(self.check_extraEnv(source_root).clone());
|
||||||
extra_env
|
extra_env
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
use std::{io, path::Path};
|
use std::{io, path::Path};
|
||||||
|
|
||||||
use crossbeam_channel::Sender;
|
use crossbeam_channel::Sender;
|
||||||
|
use ide_db::FxHashMap;
|
||||||
use paths::{AbsPathBuf, Utf8Path, Utf8PathBuf};
|
use paths::{AbsPathBuf, Utf8Path, Utf8PathBuf};
|
||||||
use project_model::ProjectJsonData;
|
use project_model::ProjectJsonData;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -62,7 +63,8 @@ impl DiscoverCommand {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut cmd = toolchain::command(command, current_dir);
|
// TODO: are we sure the extra env should be empty?
|
||||||
|
let mut cmd = toolchain::command(command, current_dir, &FxHashMap::default());
|
||||||
cmd.args(args);
|
cmd.args(args);
|
||||||
|
|
||||||
Ok(DiscoverHandle {
|
Ok(DiscoverHandle {
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ pub(crate) struct CargoOptions {
|
||||||
pub(crate) features: Vec<String>,
|
pub(crate) features: Vec<String>,
|
||||||
pub(crate) extra_args: Vec<String>,
|
pub(crate) extra_args: Vec<String>,
|
||||||
pub(crate) extra_test_bin_args: Vec<String>,
|
pub(crate) extra_test_bin_args: Vec<String>,
|
||||||
pub(crate) extra_env: FxHashMap<String, String>,
|
pub(crate) extra_env: FxHashMap<String, Option<String>>,
|
||||||
pub(crate) target_dir: Option<Utf8PathBuf>,
|
pub(crate) target_dir: Option<Utf8PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +69,6 @@ impl CargoOptions {
|
||||||
if let Some(target_dir) = &self.target_dir {
|
if let Some(target_dir) = &self.target_dir {
|
||||||
cmd.arg("--target-dir").arg(target_dir);
|
cmd.arg("--target-dir").arg(target_dir);
|
||||||
}
|
}
|
||||||
cmd.envs(&self.extra_env);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +82,7 @@ pub(crate) enum FlycheckConfig {
|
||||||
CustomCommand {
|
CustomCommand {
|
||||||
command: String,
|
command: String,
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
extra_env: FxHashMap<String, String>,
|
extra_env: FxHashMap<String, Option<String>>,
|
||||||
invocation_strategy: InvocationStrategy,
|
invocation_strategy: InvocationStrategy,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -468,7 +467,8 @@ impl FlycheckActor {
|
||||||
) -> Option<Command> {
|
) -> Option<Command> {
|
||||||
match &self.config {
|
match &self.config {
|
||||||
FlycheckConfig::CargoCommand { command, options, ansi_color_output } => {
|
FlycheckConfig::CargoCommand { command, options, ansi_color_output } => {
|
||||||
let mut cmd = toolchain::command(Tool::Cargo.path(), &*self.root);
|
let mut cmd =
|
||||||
|
toolchain::command(Tool::Cargo.path(), &*self.root, &options.extra_env);
|
||||||
if let Some(sysroot_root) = &self.sysroot_root {
|
if let Some(sysroot_root) = &self.sysroot_root {
|
||||||
cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(sysroot_root));
|
cmd.env("RUSTUP_TOOLCHAIN", AsRef::<std::path::Path>::as_ref(sysroot_root));
|
||||||
}
|
}
|
||||||
|
|
@ -516,8 +516,7 @@ impl FlycheckActor {
|
||||||
&*self.root
|
&*self.root
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut cmd = toolchain::command(command, root);
|
let mut cmd = toolchain::command(command, root, extra_env);
|
||||||
cmd.envs(extra_env);
|
|
||||||
|
|
||||||
// If the custom command has a $saved_file placeholder, and
|
// If the custom command has a $saved_file placeholder, and
|
||||||
// we're saving a file, replace the placeholder in the arguments.
|
// we're saving a file, replace the placeholder in the arguments.
|
||||||
|
|
|
||||||
|
|
@ -2315,8 +2315,11 @@ fn run_rustfmt(
|
||||||
let mut command = match snap.config.rustfmt(source_root_id) {
|
let mut command = match snap.config.rustfmt(source_root_id) {
|
||||||
RustfmtConfig::Rustfmt { extra_args, enable_range_formatting } => {
|
RustfmtConfig::Rustfmt { extra_args, enable_range_formatting } => {
|
||||||
// FIXME: Set RUSTUP_TOOLCHAIN
|
// FIXME: Set RUSTUP_TOOLCHAIN
|
||||||
let mut cmd = toolchain::command(toolchain::Tool::Rustfmt.path(), current_dir);
|
let mut cmd = toolchain::command(
|
||||||
cmd.envs(snap.config.extra_env(source_root_id));
|
toolchain::Tool::Rustfmt.path(),
|
||||||
|
current_dir,
|
||||||
|
snap.config.extra_env(source_root_id),
|
||||||
|
);
|
||||||
cmd.args(extra_args);
|
cmd.args(extra_args);
|
||||||
|
|
||||||
if let Some(edition) = edition {
|
if let Some(edition) = edition {
|
||||||
|
|
@ -2358,6 +2361,7 @@ fn run_rustfmt(
|
||||||
RustfmtConfig::CustomCommand { command, args } => {
|
RustfmtConfig::CustomCommand { command, args } => {
|
||||||
let cmd = Utf8PathBuf::from(&command);
|
let cmd = Utf8PathBuf::from(&command);
|
||||||
let target_spec = TargetSpec::for_file(snap, file_id)?;
|
let target_spec = TargetSpec::for_file(snap, file_id)?;
|
||||||
|
let extra_env = snap.config.extra_env(source_root_id);
|
||||||
let mut cmd = match target_spec {
|
let mut cmd = match target_spec {
|
||||||
Some(TargetSpec::Cargo(_)) => {
|
Some(TargetSpec::Cargo(_)) => {
|
||||||
// approach: if the command name contains a path separator, join it with the project root.
|
// approach: if the command name contains a path separator, join it with the project root.
|
||||||
|
|
@ -2370,12 +2374,11 @@ fn run_rustfmt(
|
||||||
} else {
|
} else {
|
||||||
cmd
|
cmd
|
||||||
};
|
};
|
||||||
toolchain::command(cmd_path, current_dir)
|
toolchain::command(cmd_path, current_dir, extra_env)
|
||||||
}
|
}
|
||||||
_ => toolchain::command(cmd, current_dir),
|
_ => toolchain::command(cmd, current_dir, extra_env),
|
||||||
};
|
};
|
||||||
|
|
||||||
cmd.envs(snap.config.extra_env(source_root_id));
|
|
||||||
cmd.args(args);
|
cmd.args(args);
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -652,12 +652,14 @@ impl GlobalState {
|
||||||
| ProjectWorkspaceKind::DetachedFile { cargo: Some((cargo, ..)), .. } => cargo
|
| ProjectWorkspaceKind::DetachedFile { cargo: Some((cargo, ..)), .. } => cargo
|
||||||
.env()
|
.env()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(self.config.extra_env(None))
|
.map(|(k, v)| (k.clone(), Some(v.clone())))
|
||||||
.map(|(a, b)| (a.clone(), b.clone()))
|
.chain(
|
||||||
|
self.config.extra_env(None).iter().map(|(k, v)| (k.clone(), v.clone())),
|
||||||
|
)
|
||||||
.chain(
|
.chain(
|
||||||
ws.sysroot
|
ws.sysroot
|
||||||
.root()
|
.root()
|
||||||
.map(|it| ("RUSTUP_TOOLCHAIN".to_owned(), it.to_string())),
|
.map(|it| ("RUSTUP_TOOLCHAIN".to_owned(), Some(it.to_string()))),
|
||||||
)
|
)
|
||||||
.collect(),
|
.collect(),
|
||||||
|
|
||||||
|
|
@ -893,7 +895,7 @@ impl GlobalState {
|
||||||
// FIXME: Move this into load-cargo?
|
// FIXME: Move this into load-cargo?
|
||||||
pub fn ws_to_crate_graph(
|
pub fn ws_to_crate_graph(
|
||||||
workspaces: &[ProjectWorkspace],
|
workspaces: &[ProjectWorkspace],
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, Option<String>>,
|
||||||
mut load: impl FnMut(&AbsPath) -> Option<vfs::FileId>,
|
mut load: impl FnMut(&AbsPath) -> Option<vfs::FileId>,
|
||||||
) -> (CrateGraphBuilder, Vec<ProcMacroPaths>) {
|
) -> (CrateGraphBuilder, Vec<ProcMacroPaths>) {
|
||||||
let mut crate_graph = CrateGraphBuilder::default();
|
let mut crate_graph = CrateGraphBuilder::default();
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ impl CargoTestHandle {
|
||||||
test_target: TestTarget,
|
test_target: TestTarget,
|
||||||
sender: Sender<CargoTestMessage>,
|
sender: Sender<CargoTestMessage>,
|
||||||
) -> std::io::Result<Self> {
|
) -> std::io::Result<Self> {
|
||||||
let mut cmd = toolchain::command(Tool::Cargo.path(), root);
|
let mut cmd = toolchain::command(Tool::Cargo.path(), root, &options.extra_env);
|
||||||
cmd.env("RUSTC_BOOTSTRAP", "1");
|
cmd.env("RUSTC_BOOTSTRAP", "1");
|
||||||
cmd.arg("test");
|
cmd.arg("test");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,11 +71,22 @@ impl Tool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn command(cmd: impl AsRef<OsStr>, working_directory: impl AsRef<Path>) -> Command {
|
#[allow(clippy::disallowed_types)] /* generic parameter allows for FxHashMap */
|
||||||
|
pub fn command<H>(
|
||||||
|
cmd: impl AsRef<OsStr>,
|
||||||
|
working_directory: impl AsRef<Path>,
|
||||||
|
extra_env: &std::collections::HashMap<String, Option<String>, H>,
|
||||||
|
) -> Command {
|
||||||
// we are `toolchain::command``
|
// we are `toolchain::command``
|
||||||
#[allow(clippy::disallowed_methods)]
|
#[allow(clippy::disallowed_methods)]
|
||||||
let mut cmd = Command::new(cmd);
|
let mut cmd = Command::new(cmd);
|
||||||
cmd.current_dir(working_directory);
|
cmd.current_dir(working_directory);
|
||||||
|
for env in extra_env {
|
||||||
|
match env {
|
||||||
|
(key, Some(val)) => cmd.env(key, val),
|
||||||
|
(key, None) => cmd.env_remove(key),
|
||||||
|
};
|
||||||
|
}
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue