Repository navigation
fix(install): filter out binaries not included by selected features #17544
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -986,3 +986,146 @@ fn partially_already_installed_does_one_update() { | |
| "#]]) | ||
| .run(); | ||
| } | ||
|
|
||
| #[cargo_test] | ||
| fn check_upgrade_respects_features() { | ||
|
bcully marked this conversation as resolved.
|
||
| // Issue #8703: an installed package should not consider binaries to be missing if they | ||
| // depend on unselected features | ||
| Package::new("foo", "1.0.0") | ||
| .file( | ||
| "Cargo.toml", | ||
| r#" | ||
| [package] | ||
| name = "foo" | ||
| version = "1.0.0" | ||
|
|
||
| [features] | ||
| default = ["feat"] | ||
| e1 = [] | ||
| e2 = [] | ||
| extra = ["e1", "e2"] | ||
| feat = [] | ||
|
|
||
| [[bin]] | ||
| name = "foo" | ||
| path = "src/main.rs" | ||
|
|
||
| [[bin]] | ||
| name = "foo-feat" | ||
| path = "src/bin/foo-feat.rs" | ||
| required-features = ["feat"] | ||
|
|
||
| [[bin]] | ||
| name = "foo-e1" | ||
| path = "src/bin/foo-e1.rs" | ||
| required-features = ["e1"] | ||
|
|
||
| [[bin]] | ||
| name = "foo-e2" | ||
| path = "src/bin/foo-e2.rs" | ||
| required-features = ["e2"] | ||
|
Comment on lines
+1023
to
+1026
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably have a test case for
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try to get one going. My first attempt produced confusing errors, where the features I defined in "dep" didn't seem to be visible in "foo".
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just missed that you have to separately declare features with |
||
|
|
||
| [[bin]] | ||
| name = "foo-dep" | ||
| path = "src/bin/foo-dep.rs" | ||
| required-features = ["dep"] | ||
|
|
||
| [dependencies] | ||
| dep = { version = "1.0.0", optional = true } | ||
| "#, | ||
| ) | ||
| .file("src/main.rs", "fn main() {}") | ||
| .file("src/bin/foo-feat.rs", "fn main() {}") | ||
| .file("src/bin/foo-e1.rs", "fn main() {}") | ||
| .file("src/bin/foo-e2.rs", "fn main() {}") | ||
| .file("src/bin/foo-dep.rs", "fn main() {}") | ||
| .publish(); | ||
|
|
||
| Package::new("dep", "1.0.0") | ||
| .file( | ||
| "Cargo.toml", | ||
| r#" | ||
| [package] | ||
| name = "dep" | ||
| version = "1.0.0" | ||
|
|
||
| [features] | ||
| feat = [] | ||
| "#, | ||
| ) | ||
| .feature("feat", &[]) | ||
| .file("src/lib.rs", "pub fn dep() {}") | ||
| .publish(); | ||
|
|
||
| // install, check binaries are expected, expect reinstall to take no action | ||
| let check_install = |arg_line, expected_bins, expected_output| { | ||
| cargo_process(arg_line).run(); | ||
| validate_trackers("foo", "1.0.0", expected_bins); | ||
|
|
||
| cargo_process(arg_line) | ||
| .with_stderr_data(expected_output) | ||
| .run(); | ||
| }; | ||
|
|
||
| check_install( | ||
| "install --no-default-features foo", | ||
| &["foo"], | ||
| str![[r#" | ||
| ... | ||
| [IGNORED] package `foo v1.0.0` is already installed, use --force to override | ||
| ... | ||
| "#]], | ||
| ); | ||
| // leave installed, default feature should trigger adding extra binary | ||
| check_install( | ||
| "install foo", | ||
| &["foo", "foo-feat"], | ||
| str![[r#" | ||
| ... | ||
| [IGNORED] package `foo v1.0.0` is already installed, use --force to override | ||
| ... | ||
| "#]], | ||
| ); | ||
| // weak dependency feature should not add foo-dep | ||
| check_install( | ||
| "install -F dep?/feat foo", | ||
| &["foo", "foo-feat"], | ||
| str![[r#" | ||
| ... | ||
| [IGNORED] package `foo v1.0.0` is already installed, use --force to override | ||
| ... | ||
| "#]], | ||
| ); | ||
| // implicit feature should add foo-dep | ||
| check_install( | ||
| "install -F dep/feat foo", | ||
| &["foo", "foo-feat", "foo-dep"], | ||
| str![[r#" | ||
| ... | ||
| [IGNORED] package `foo v1.0.0` is already installed, use --force to override | ||
| ... | ||
| "#]], | ||
| ); | ||
|
|
||
| cargo_process("uninstall foo").run(); | ||
|
|
||
| check_install( | ||
| "install -F extra foo", | ||
| &["foo", "foo-e1", "foo-e2", "foo-feat"], | ||
| str![[r#" | ||
| ... | ||
| [IGNORED] package `foo v1.0.0` is already installed, use --force to override | ||
| ... | ||
| "#]], | ||
| ); | ||
|
|
||
| check_install( | ||
| "install --all-features foo", | ||
| &["foo", "foo-dep", "foo-e1", "foo-e2", "foo-feat"], | ||
| str![[r#" | ||
| ... | ||
| [IGNORED] package `foo v1.0.0` is already installed, use --force to override | ||
| ... | ||
| "#]], | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using only
dep_namehere throws away the feature portion ofdep/feature(/feature)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned below, I'm afraid I don't understand the problem. It seemed to me that only the "dep" part would potentially trigger a new binary in the install target.