Skip to content
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 disagreement about lockfile ordering on stable/nightly #9384

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ struct SourceIdInner {
/// source.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum SourceKind {
/// A git repository.
Git(GitReference),
// Note that the ordering here is important for how it affects the `Ord`
// implementation, notably how this affects the ordering of serialized
// packages into lock files.
/// A local path..
Path,
/// A remote registry.
Expand All @@ -54,6 +55,8 @@ enum SourceKind {
LocalRegistry,
/// A directory-based registry.
Directory,
/// A git repository.
Git(GitReference),
}

/// Information to find a specific commit in a Git repository.
Expand Down
72 changes: 72 additions & 0 deletions tests/testsuite/lockfile_compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,3 +771,75 @@ dependencies = [

p.cargo("build --locked").run();
}

#[cargo_test]
fn same_name_version_different_sources() {
let cksum = Package::new("foo", "0.1.0").publish();
let (git_project, repo) = git::new_repo("dep1", |project| {
project
.file(
"Cargo.toml",
r#"
[project]
name = "foo"
version = "0.1.0"
"#,
)
.file("src/lib.rs", "")
});
let head_id = repo.head().unwrap().target().unwrap();

// Lockfile was generated with Rust 1.51
let lockfile = format!(
r#"# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "foo"
version = "0.1.0"
dependencies = [
"foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"foo 0.1.0 (git+{url})",
]

[[package]]
name = "foo"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "{cksum}"

[[package]]
name = "foo"
version = "0.1.0"
source = "git+{url}#{sha}"
"#,
sha = head_id,
url = git_project.url(),
cksum = cksum
);

let p = project()
.file(
"Cargo.toml",
&format!(
r#"
[project]
name = "foo"
version = "0.1.0"

[dependencies]
foo = "0.1.0"
foo2 = {{ git = '{}', package = 'foo' }}
"#,
git_project.url(),
),
)
.file("src/lib.rs", "")
.file("Cargo.lock", &lockfile)
.build();

p.cargo("build").run();

assert_eq!(p.read_file("Cargo.lock"), lockfile);
}