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

Sweep unrelated message from unnecessary workspace infromation #8681

Merged
Merged
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
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");
}