Skip to content

Commit

Permalink
Auto merge of #8681 - weihanglo:fix/redundant-messsage-local-crate-in…
Browse files Browse the repository at this point in the history
…stall, r=ehuss

Sweep unrelated message from unnecessary workspace infromation

Resolves #8619

Only pass workspace information when the source is from a local crate installation.
  • Loading branch information
bors committed Sep 10, 2020
2 parents 738f461 + a527caa commit f110fd9
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/bin/cargo/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
config.reload_rooted_at(config.home().clone().into_path_unlocked())?;
}

let workspace = args.workspace(config).ok();
let mut compile_opts = args.compile_options(
config,
CompileMode::Build,
workspace.as_ref(),
ProfileChecking::Checked,
)?;

compile_opts.build_config.requested_profile =
args.get_profile_name(config, "release", ProfileChecking::Checked)?;

let krates = args
.values_of("crate")
.unwrap_or_default()
Expand Down Expand Up @@ -127,6 +116,26 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
let version = args.value_of("version");
let root = args.value_of("root");

// We only provide worksapce information for local crate installation from
// one of the following sources:
// - From current working directory (only work for edition 2015).
// - From a specific local file path.
let workspace = if from_cwd || args.is_present("path") {
args.workspace(config).ok()
} else {
None
};

let mut compile_opts = args.compile_options(
config,
CompileMode::Build,
workspace.as_ref(),
ProfileChecking::Checked,
)?;

compile_opts.build_config.requested_profile =
args.get_profile_name(config, "release", ProfileChecking::Checked)?;

if args.is_present("list") {
ops::install_list(root, config)?;
} else {
Expand Down
65 changes: 65 additions & 0 deletions tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,3 +1587,68 @@ fn install_yanked_cargo_package() {
)
.run();
}

#[cargo_test]
fn install_cargo_package_in_a_patched_workspace() {
pkg("foo", "0.1.0");
pkg("fizz", "1.0.0");

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "bar"
version = "0.1.0"
authors = []
[workspace]
members = ["baz"]
"#,
)
.file("src/main.rs", "fn main() {}")
.file(
"baz/Cargo.toml",
r#"
[package]
name = "baz"
version = "0.1.0"
authors = []
[dependencies]
fizz = "1"
[patch.crates-io]
fizz = { version = "=1.0.0" }
"#,
)
.file("baz/src/lib.rs", "")
.build();

let stderr = "\
[WARNING] patch for the non root package will be ignored, specify patch at the workspace root:
package: [..]/foo/baz/Cargo.toml
workspace: [..]/foo/Cargo.toml
";
p.cargo("check").with_stderr_contains(&stderr).run();

// A crate installation must not emit any message from a workspace under
// current working directory.
// See https://github.com/rust-lang/cargo/issues/8619
p.cargo("install foo")
.with_stderr(
"\
[UPDATING] `[..]` index
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.1.0 (registry [..])
[INSTALLING] foo v0.1.0
[COMPILING] foo v0.1.0
[FINISHED] release [optimized] target(s) in [..]
[INSTALLING] [..]foo[EXE]
[INSTALLED] package `foo v0.1.0` (executable `foo[EXE]`)
[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
",
)
.run();
assert_has_installed_exe(cargo_home(), "foo");
}

0 comments on commit f110fd9

Please sign in to comment.