diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index 58056aa8375..3ebef651d12 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -163,11 +163,7 @@ fn execute_external_subcommand(config: &Config, cmd: &str, args: &[&str]) -> Cli } }; - let cargo_exe = config.cargo_exe()?; - let err = match ProcessBuilder::new(&command) - .env(cargo::CARGO_ENV, cargo_exe) - .args(args) - .exec_replace() + let err = match cargo::ops::execute_external_subcommand(&config, &command, args) { Ok(()) => return Ok(()), Err(e) => e, diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index 50143978f22..f4d1b0b486b 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -85,3 +85,26 @@ fn check_dep_has_version(dep: &crate::core::Dependency, publish: bool) -> crate: } Ok(true) } + +// Temporary - should this be in a subcommand.rs file? +use crate::Config; +use crate::util::important_paths::find_root_manifest_for_wd; +use crate::core::Workspace; +use cargo_util::ProcessBuilder; +use std::ffi::OsStr; + +pub fn execute_external_subcommand>(config: &Config, command: T, args: &[&str]) + -> crate::CargoResult<()> +{ + let cargo_exe = config.cargo_exe()?; + let manifest_path = find_root_manifest_for_wd(config.cwd())?; + let ws = Workspace::new(&manifest_path, config)?; + + let cargo_target_dir = ws.target_dir().into_path_unlocked(); + + ProcessBuilder::new(&command) + .env(crate::CARGO_ENV, cargo_exe) + .env("CARGO_TARGET_DIR", &cargo_target_dir) + .args(args) + .exec_replace() +}