From f92961923b35d726e96c14d2dba88ffc4a0c36d4 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sun, 6 Sep 2020 13:29:52 +0800 Subject: [PATCH 1/5] Sweep unrelated message from unnecessary workspace infromation --- src/bin/cargo/commands/install.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 9b06fc2cf80..7960c154f03 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -75,13 +75,16 @@ pub fn cli() -> App { } pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { + let workspace; if let Some(path) = args.value_of_path("path", config) { config.reload_rooted_at(path)?; + // Only provide worksapce information for local crate installation + workspace = args.workspace(config).ok(); } else { config.reload_rooted_at(config.home().clone().into_path_unlocked())?; + workspace = None; } - let workspace = args.workspace(config).ok(); let mut compile_opts = args.compile_options( config, CompileMode::Build, From 392b902f06dedaa4a8f514e7ad64c0bcefe1c7b3 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Sun, 6 Sep 2020 19:24:15 +0800 Subject: [PATCH 2/5] Only `--path` and cwd crate installation need workspace info --- src/bin/cargo/commands/install.rs | 34 ++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index 7960c154f03..34ce25b563c 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -75,26 +75,12 @@ pub fn cli() -> App { } pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { - let workspace; if let Some(path) = args.value_of_path("path", config) { config.reload_rooted_at(path)?; - // Only provide worksapce information for local crate installation - workspace = args.workspace(config).ok(); } else { config.reload_rooted_at(config.home().clone().into_path_unlocked())?; - workspace = 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)?; - let krates = args .values_of("crate") .unwrap_or_default() @@ -130,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 { From 71cae39de00c39e0a903faf070d55675f3d792a0 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 10 Sep 2020 00:20:00 +0800 Subject: [PATCH 3/5] Test for crate installation without emitting messages from cwd --- tests/testsuite/install.rs | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 875a7a636cf..80cd1f3146c 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1587,3 +1587,57 @@ 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_does_not_contain(&stderr) + .run(); +} From 45cfd0cd126d08a3adbf8aa78e91bf6d122d5445 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 10 Sep 2020 00:26:06 +0800 Subject: [PATCH 4/5] Fix formatting --- tests/testsuite/install.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 80cd1f3146c..053f5603380 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1630,9 +1630,7 @@ fn install_cargo_package_in_a_patched_workspace() { package: [..]/foo/baz/Cargo.toml workspace: [..]/foo/Cargo.toml "; - p.cargo("check") - .with_stderr_contains(&stderr) - .run(); + p.cargo("check").with_stderr_contains(&stderr).run(); // A crate installation must not emit any message from a workspace under // current working directory. From a527caa24855ec3551281e91c8e1d7909e533254 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 10 Sep 2020 07:57:57 +0800 Subject: [PATCH 5/5] test: check stderr containment explicitly --- tests/testsuite/install.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/testsuite/install.rs b/tests/testsuite/install.rs index 053f5603380..8e8ba337f5b 100644 --- a/tests/testsuite/install.rs +++ b/tests/testsuite/install.rs @@ -1636,6 +1636,19 @@ workspace: [..]/foo/Cargo.toml // current working directory. // See https://github.com/rust-lang/cargo/issues/8619 p.cargo("install foo") - .with_stderr_does_not_contain(&stderr) + .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"); }