Skip to content

Commit f110fd9

Browse files
committed
Auto merge of #8681 - weihanglo:fix/redundant-messsage-local-crate-install, r=ehuss
Sweep unrelated message from unnecessary workspace infromation Resolves #8619 Only pass workspace information when the source is from a local crate installation.
2 parents 738f461 + a527caa commit f110fd9

File tree

2 files changed

+85
-11
lines changed

2 files changed

+85
-11
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,6 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
8181
config.reload_rooted_at(config.home().clone().into_path_unlocked())?;
8282
}
8383

84-
let workspace = args.workspace(config).ok();
85-
let mut compile_opts = args.compile_options(
86-
config,
87-
CompileMode::Build,
88-
workspace.as_ref(),
89-
ProfileChecking::Checked,
90-
)?;
91-
92-
compile_opts.build_config.requested_profile =
93-
args.get_profile_name(config, "release", ProfileChecking::Checked)?;
94-
9584
let krates = args
9685
.values_of("crate")
9786
.unwrap_or_default()
@@ -127,6 +116,26 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
127116
let version = args.value_of("version");
128117
let root = args.value_of("root");
129118

119+
// We only provide worksapce information for local crate installation from
120+
// one of the following sources:
121+
// - From current working directory (only work for edition 2015).
122+
// - From a specific local file path.
123+
let workspace = if from_cwd || args.is_present("path") {
124+
args.workspace(config).ok()
125+
} else {
126+
None
127+
};
128+
129+
let mut compile_opts = args.compile_options(
130+
config,
131+
CompileMode::Build,
132+
workspace.as_ref(),
133+
ProfileChecking::Checked,
134+
)?;
135+
136+
compile_opts.build_config.requested_profile =
137+
args.get_profile_name(config, "release", ProfileChecking::Checked)?;
138+
130139
if args.is_present("list") {
131140
ops::install_list(root, config)?;
132141
} else {

tests/testsuite/install.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,3 +1587,68 @@ fn install_yanked_cargo_package() {
15871587
)
15881588
.run();
15891589
}
1590+
1591+
#[cargo_test]
1592+
fn install_cargo_package_in_a_patched_workspace() {
1593+
pkg("foo", "0.1.0");
1594+
pkg("fizz", "1.0.0");
1595+
1596+
let p = project()
1597+
.file(
1598+
"Cargo.toml",
1599+
r#"
1600+
[package]
1601+
name = "bar"
1602+
version = "0.1.0"
1603+
authors = []
1604+
1605+
[workspace]
1606+
members = ["baz"]
1607+
"#,
1608+
)
1609+
.file("src/main.rs", "fn main() {}")
1610+
.file(
1611+
"baz/Cargo.toml",
1612+
r#"
1613+
[package]
1614+
name = "baz"
1615+
version = "0.1.0"
1616+
authors = []
1617+
1618+
[dependencies]
1619+
fizz = "1"
1620+
1621+
[patch.crates-io]
1622+
fizz = { version = "=1.0.0" }
1623+
"#,
1624+
)
1625+
.file("baz/src/lib.rs", "")
1626+
.build();
1627+
1628+
let stderr = "\
1629+
[WARNING] patch for the non root package will be ignored, specify patch at the workspace root:
1630+
package: [..]/foo/baz/Cargo.toml
1631+
workspace: [..]/foo/Cargo.toml
1632+
";
1633+
p.cargo("check").with_stderr_contains(&stderr).run();
1634+
1635+
// A crate installation must not emit any message from a workspace under
1636+
// current working directory.
1637+
// See https://github.com/rust-lang/cargo/issues/8619
1638+
p.cargo("install foo")
1639+
.with_stderr(
1640+
"\
1641+
[UPDATING] `[..]` index
1642+
[DOWNLOADING] crates ...
1643+
[DOWNLOADED] foo v0.1.0 (registry [..])
1644+
[INSTALLING] foo v0.1.0
1645+
[COMPILING] foo v0.1.0
1646+
[FINISHED] release [optimized] target(s) in [..]
1647+
[INSTALLING] [..]foo[EXE]
1648+
[INSTALLED] package `foo v0.1.0` (executable `foo[EXE]`)
1649+
[WARNING] be sure to add `[..]` to your PATH to be able to run the installed binaries
1650+
",
1651+
)
1652+
.run();
1653+
assert_has_installed_exe(cargo_home(), "foo");
1654+
}

0 commit comments

Comments
 (0)