Skip to content

Commit 4f70d17

Browse files
committed
Auto merge of #13213 - stupendoussuperpowers:mulpack-features-git, r=epage
`cargo add` - fix for adding features from repository with multiple packages. Fixes #13121 As discussed in the issue, when using `cargo add` to add a package with features from a git repository from one of it's members, the command might fail due to improper target for querying for said features. This PR adds a test for this edge-case where we expect it to fail with current code. It also adds a fix for this, and updates the test to expect success. While populating available features, the current code does a `Fuzzy` search which might lead to searching for features in a wrong member package. If we change it to an `Exact` query, we get back the proper member to search within.
2 parents 04b6aed + e46d80e commit 4f70d17

File tree

7 files changed

+79
-1
lines changed

7 files changed

+79
-1
lines changed

src/cargo/ops/cargo_add/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ fn populate_available_features(
934934
}
935935

936936
let possibilities = loop {
937-
match registry.query_vec(&query, QueryKind::Fuzzy) {
937+
match registry.query_vec(&query, QueryKind::Exact) {
938938
std::task::Poll::Ready(res) => {
939939
break res?;
940940
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../add-basic.in
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use cargo_test_support::compare::assert_ui;
2+
use cargo_test_support::prelude::*;
3+
use cargo_test_support::Project;
4+
5+
use cargo_test_support::curr_dir;
6+
7+
#[cargo_test]
8+
fn case() {
9+
cargo_test_support::registry::init();
10+
11+
let main_manifest = r#"
12+
[package]
13+
name = "main-package"
14+
version = "0.1.1+main-package"
15+
authors = []
16+
17+
[workspace]
18+
members = ["package-wo-feature", "package-with-feature"]
19+
"#;
20+
21+
let manifest_feature = r#"
22+
[package]
23+
name = "package-with-feature"
24+
version = "0.1.3+package-with-feature"
25+
[features]
26+
target_feature = []
27+
"#;
28+
29+
let project = Project::from_template(curr_dir!().join("in"));
30+
let project_root = project.root();
31+
let cwd = &project_root;
32+
let git_dep = cargo_test_support::git::new("git-package", |project| {
33+
project
34+
.file("Cargo.toml", &main_manifest)
35+
.file(
36+
"package-wo-feature/Cargo.toml",
37+
&cargo_test_support::basic_manifest(
38+
"package-wo-feature",
39+
"0.1.1+package-wo-feature",
40+
),
41+
)
42+
.file("package-wo-feature/src/lib.rs", "")
43+
.file("package-with-feature/Cargo.toml", &manifest_feature)
44+
.file("package-with-feature/src/lib.rs", "")
45+
});
46+
let git_url = git_dep.url().to_string();
47+
48+
snapbox::cmd::Command::cargo_ui()
49+
.arg("add")
50+
.args([
51+
"--git",
52+
&git_url,
53+
"package-with-feature",
54+
"--features=target_feature",
55+
])
56+
.current_dir(cwd)
57+
.assert()
58+
.success()
59+
.stdout_matches_path(curr_dir!().join("stdout.log"))
60+
.stderr_matches_path(curr_dir!().join("stderr.log"));
61+
62+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
63+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[workspace]
2+
3+
[package]
4+
name = "cargo-list-test-fixture"
5+
version = "0.0.0"
6+
7+
[dependencies]
8+
package-with-feature = { git = "[ROOTURL]/git-package", version = "0.1.3", features = ["target_feature"] }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Updating git repository `[ROOTURL]/git-package`
2+
Adding package-with-feature (git) to dependencies.
3+
Features:
4+
+ target_feature
5+
Updating git repository `[ROOTURL]/git-package`

tests/testsuite/cargo_add/git_multiple_packages_features/stdout.log

Whitespace-only changes.

tests/testsuite/cargo_add/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ mod git_dev;
3535
mod git_inferred_name;
3636
mod git_inferred_name_multiple;
3737
mod git_multiple_names;
38+
mod git_multiple_packages_features;
3839
mod git_normalized_name;
3940
mod git_registry;
4041
mod git_rev;

0 commit comments

Comments
 (0)