mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Improve error message on duplicate packages in lockfile.
This commit is contained in:
parent
b04c79a0e5
commit
cedc0ca97e
@ -140,7 +140,7 @@ pub fn resolve(
|
|||||||
);
|
);
|
||||||
|
|
||||||
check_cycles(&resolve, &cx.activations)?;
|
check_cycles(&resolve, &cx.activations)?;
|
||||||
check_duplicate_pkgs(&resolve)?;
|
check_duplicate_pkgs_in_lockfile(&resolve)?;
|
||||||
trace!("resolved: {:?}", resolve);
|
trace!("resolved: {:?}", resolve);
|
||||||
|
|
||||||
// If we have a shell, emit warnings about required deps used as feature.
|
// If we have a shell, emit warnings about required deps used as feature.
|
||||||
@ -1100,27 +1100,23 @@ fn check_cycles(resolve: &Resolve, activations: &Activations) -> CargoResult<()>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_duplicate_pkgs(resolve: &Resolve) -> Vec<&'static str> {
|
/// Checks that packages are unique when written to lockfile.
|
||||||
let mut unique_pkg_ids = HashSet::new();
|
///
|
||||||
let mut result = HashSet::new();
|
/// When writing package id's to lockfile, we apply lossy encoding. In
|
||||||
|
/// particular, we don't store paths of path dependencies. That means that
|
||||||
|
/// *different* packages may collide in the lockfile, hence this check.
|
||||||
|
fn check_duplicate_pkgs_in_lockfile(resolve: &Resolve) -> CargoResult<()> {
|
||||||
|
let mut unique_pkg_ids = HashMap::new();
|
||||||
for pkg_id in resolve.iter() {
|
for pkg_id in resolve.iter() {
|
||||||
let mut encodable_pkd_id = encode::encodable_package_id(pkg_id);
|
let encodable_pkd_id = encode::encodable_package_id(pkg_id);
|
||||||
if !unique_pkg_ids.insert(encodable_pkd_id) {
|
if let Some(prev_pkg_id) = unique_pkg_ids.insert(encodable_pkd_id, pkg_id) {
|
||||||
result.insert(pkg_id.name().as_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result.into_iter().collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_duplicate_pkgs(resolve: &Resolve) -> CargoResult<()> {
|
|
||||||
let names = get_duplicate_pkgs(resolve);
|
|
||||||
if names.is_empty() {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
bail!(
|
bail!(
|
||||||
"dependencies contain duplicate package(s) in the \
|
"package collision in the lockfile: packages {} and {} are different, \
|
||||||
same namespace from the same source: {}",
|
but only one can be written to lockfile unambigiously",
|
||||||
names.join(", ")
|
prev_pkg_id,
|
||||||
|
pkg_id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
@ -307,8 +307,9 @@ fn duplicate_entries_in_lockfile() {
|
|||||||
assert_that(
|
assert_that(
|
||||||
b.cargo("build"),
|
b.cargo("build"),
|
||||||
execs().with_status(101).with_stderr_contains(
|
execs().with_status(101).with_stderr_contains(
|
||||||
"[..]dependencies contain duplicate package(s) in the \
|
"[..]package collision in the lockfile: packages common [..] and \
|
||||||
same namespace from the same source: common",
|
common [..] are different, but only one can be written to \
|
||||||
|
lockfile unambigiously",
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user