Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(package): Fix lookups to capitalized workspace member's index entry #15216

Merged
merged 3 commits into from
Feb 21, 2025
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
6 changes: 6 additions & 0 deletions crates/cargo-util/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
/// - [index from of Cargo's index on filesystem][1], and
/// - [index from Crates.io][2].
///
/// <div class="warning">
///
/// Note: For index files, `dep_name` must have had `to_lowercase` called on it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be frank, I don't know why we have chosen to lower the case for index file queries. Apart from that, this looks good.

///
/// </div>
///
/// [1]: https://docs.rs/cargo/latest/cargo/sources/registry/index.html#the-format-of-the-index
/// [2]: https://github.com/rust-lang/crates.io-index
pub fn make_dep_path(dep_name: &str, prefix_only: bool) -> String {
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,8 @@ impl<'a> TmpRegistry<'a> {
v: Some(2),
})?;

let file = cargo_util::registry::make_dep_path(package.name().as_str(), false);
let file =
cargo_util::registry::make_dep_path(&package.name().as_str().to_lowercase(), false);
let mut dst = self.index_path().open_rw_exclusive_create(
file,
self.gctx,
Expand Down
12 changes: 6 additions & 6 deletions src/cargo/sources/registry/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,19 +584,19 @@ impl Summaries {
) -> Poll<CargoResult<Option<Summaries>>> {
// This is the file we're loading from cache or the index data.
// See module comment in `registry/mod.rs` for why this is structured the way it is.
let name = &name.to_lowercase();
let relative = make_dep_path(&name, false);
let lowered_name = &name.to_lowercase();
let relative = make_dep_path(&lowered_name, false);

let mut cached_summaries = None;
let mut index_version = None;
if let Some(contents) = cache_manager.get(name) {
if let Some(contents) = cache_manager.get(lowered_name) {
match Summaries::parse_cache(contents) {
Ok((s, v)) => {
cached_summaries = Some(s);
index_version = Some(v);
}
Err(e) => {
tracing::debug!("failed to parse {name:?} cache: {e}");
tracing::debug!("failed to parse {lowered_name:?} cache: {e}");
}
}
}
Expand All @@ -609,7 +609,7 @@ impl Summaries {
return Poll::Ready(Ok(cached_summaries));
}
LoadResponse::NotFound => {
cache_manager.invalidate(name);
cache_manager.invalidate(lowered_name);
return Poll::Ready(Ok(None));
}
LoadResponse::Data {
Expand Down Expand Up @@ -658,7 +658,7 @@ impl Summaries {
// Once we have our `cache_bytes` which represents the `Summaries` we're
// about to return, write that back out to disk so future Cargo
// invocations can use it.
cache_manager.put(name, &cache_bytes);
cache_manager.put(lowered_name, &cache_bytes);

// If we've got debug assertions enabled read back in the cached values
// and assert they match the expected result.
Expand Down
62 changes: 62 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6430,6 +6430,68 @@ fn workspace_with_local_and_remote_deps() {
.run();
}

#[cargo_test]
fn workspace_with_capitalized_member() {
let reg = registry::init();

let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["dep", "main"]
"#,
)
.file(
"main/Cargo.toml",
r#"
[package]
name = "main"
version = "0.0.1"
edition = "2015"
authors = []
license = "MIT"
description = "main"
repository = "bar"

[dependencies]
DEP = { path = "../dep", version = "0.1.0" }
"#,
)
.file("main/src/main.rs", "fn main() {}")
.file(
"dep/Cargo.toml",
r#"
[package]
name = "DEP"
version = "0.1.0"
edition = "2015"
authors = []
license = "MIT"
description = "dep"
repository = "bar"
"#,
)
.file("dep/src/lib.rs", "")
.build();

p.cargo("package -Zpackage-workspace --no-verify")
.masquerade_as_nightly_cargo(&["package-workspace"])
.replace_crates_io(reg.index_url())
.with_stderr_data(
str![[r#"
[PACKAGING] main v0.0.1 ([ROOT]/foo/main)
[UPDATING] crates.io index
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
[PACKAGING] DEP v0.1.0 ([ROOT]/foo/dep)
[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)

"#]]
.unordered(),
)
.run();
}

#[cargo_test]
fn registry_not_in_publish_list() {
let p = project()
Expand Down
Loading