make cargo install ignore .cargo/config

closes #5850
This commit is contained in:
Jorge Aparicio 2018-08-08 10:09:54 -05:00
parent aecaef3e23
commit e620865633
5 changed files with 46 additions and 5 deletions

View file

@ -74,7 +74,7 @@ continuous integration systems.",
}
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
let mut compile_opts = args.compile_options(config, CompileMode::Build)?;
let mut compile_opts = args.compile_options(config, CompileMode::Install)?;
compile_opts.build_config.release = !args.is_present("debug");
let krates = args.values_of("crate")

View file

@ -60,8 +60,13 @@ impl BuildConfig {
bail!("target was empty")
}
}
let cfg_target = config.get_string("build.target")?.map(|s| s.val);
let target = requested_target.clone().or(cfg_target);
let target = if mode == CompileMode::Install {
// ignore `.cargo/config` when compiling for `cargo install`
requested_target
} else {
let cfg_target = config.get_string("build.target")?.map(|s| s.val);
requested_target.clone().or(cfg_target)
};
if jobs == Some(0) {
bail!("jobs must be at least 1")
@ -131,6 +136,8 @@ pub enum CompileMode {
Doc { deps: bool },
/// A target that will be tested with `rustdoc`.
Doctest,
// Like `Build` but we are compiling something that will be installed
Install,
/// A marker for Units that represent the execution of a `build.rs`
/// script.
RunCustomBuild,

View file

@ -84,6 +84,7 @@ impl Profiles {
CompileMode::Build
| CompileMode::Check { .. }
| CompileMode::Doctest
| CompileMode::Install
| CompileMode::RunCustomBuild => {
// Note: RunCustomBuild doesn't normally use this code path.
// `build_unit_profiles` normally ensures that it selects the

View file

@ -386,7 +386,10 @@ impl CompileFilter {
pub fn need_dev_deps(&self, mode: CompileMode) -> bool {
match mode {
CompileMode::Test | CompileMode::Doctest | CompileMode::Bench => true,
CompileMode::Build | CompileMode::Doc { .. } | CompileMode::Check { .. } => match *self
CompileMode::Build
| CompileMode::Doc { .. }
| CompileMode::Check { .. }
| CompileMode::Install => match *self
{
CompileFilter::Default { .. } => false,
CompileFilter::Only {
@ -707,7 +710,7 @@ fn filter_default_targets(targets: &[Target], mode: CompileMode) -> Vec<&Target>
.iter()
.filter(|t| t.tested() || t.is_example())
.collect(),
CompileMode::Build | CompileMode::Check { .. } => targets
CompileMode::Build | CompileMode::Check { .. } | CompileMode::Install => targets
.iter()
.filter(|t| t.is_bin() || t.is_lib())
.collect(),

View file

@ -1237,3 +1237,33 @@ warning: be sure to add `[..]` to your PATH to be able to run the installed bina
",
).run();
}
fn install_ignores_cargo_config() {
pkg("bar", "0.0.1");
let p = project("foo")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
"#,
)
.file(
".cargo/config",
r#"
[build]
target = "non-existing-target"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
assert_that(
cargo_process("install").arg("bar").cwd(p.root()),
execs().with_status(0),
);
assert_that(cargo_home(), has_installed_exe("bar"));
}