Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target_dir for 3rd party subcommands #9805

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 23 additions & 0 deletions src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AsRef<OsStr>>(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()
}