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
Fix: Make path dependencies with the same name stays locked #13572
base: master
Are you sure you want to change the base?
Conversation
c52a34e
to
c07cf47
Compare
@rustbot ready |
@ehuss any chance for some feedback? I'm not sure I'm doing the right thing. |
42fbaf5
to
3a580a4
Compare
src/cargo/core/resolver/encode.rs
Outdated
if let Some(source_id) = version_source.get(&pkg_version) { | ||
return Some(source_id); | ||
} | ||
} |
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'm still a little concerned about the behavior here when there are multiple versions, but none of them match. There are two concerns:
- This randomly chooses one of the packages, which is not great for consistency.
- Depending on what changed and which random package it picks, you can end up with two packages with the same SourceId.
I'm still wondering if it is appropriate to return None
here if there are multiple versions, but none of them match. For example, something like:
} | |
} | |
return None; |
Does that make sense?
Here is a test that illustrates the problem with having multiple versions: #[cargo_test]
fn same_name_version_changed() {
// Illustrates having two path packages with the same name, but different versions.
// Verifies it works correctly when one of the versions is changed.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "1.0.0"
edition = "2021"
[dependencies]
foo2 = { path = "foo2", package = "foo" }
"#,
)
.file("src/lib.rs", "")
.file(
"foo2/Cargo.toml",
r#"
[package]
name = "foo"
version = "2.0.0"
edition = "2021"
"#,
)
.file("foo2/src/lib.rs", "")
.build();
p.cargo("tree")
.with_stderr("[LOCKING] 2 packages to latest compatible versions")
.with_stdout(
"\
foo v1.0.0 ([ROOT]/foo)
└── foo v2.0.0 ([ROOT]/foo/foo2)
",
)
.run();
p.change_file(
"foo2/Cargo.toml",
r#"
[package]
name = "foo"
version = "2.0.1"
edition = "2021"
"#,
);
p.cargo("tree")
.with_stderr(
"\
[LOCKING] 1 package to latest compatible version
[ADDING] foo v2.0.1 ([ROOT]/foo/foo2)
",
)
.with_stdout(
"\
foo v1.0.0 ([ROOT]/foo)
└── foo v2.0.1 ([ROOT]/foo/foo2)
",
)
.run();
} With this PR as-is, this test will randomly fail. I'd recommend adding this test to the |
3a580a4
to
82a4a84
Compare
82a4a84
to
a726c53
Compare
Oh on, the ci faild due to
I guess this pr merge can solve this |
What does this PR try to resolve?
Fixes: #13405
This is a workround based on #13405 (comment)
How should we test and review this PR?
first commit will pass, second commit fixed it and update test.
Additional information