Skip to content

Commit c0879ae

Browse files
committed
Handle renamed dependencies coming from Cargo
This commit is intended to be coupled with rust-lang/cargo#5993 where Cargo will start sending the registry more information about locally renamed crates to persist into the index.
1 parent f58ca05 commit c0879ae

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/git.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub struct Dependency {
3434
pub default_features: bool,
3535
pub target: Option<String>,
3636
pub kind: Option<DependencyKind>,
37+
#[serde(skip_serializing_if = "Option::is_none")]
38+
pub package: Option<String>,
3739
}
3840

3941
fn index_file(base: &Path, name: &str) -> PathBuf {

src/models/dependency.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,26 @@ pub fn add_dependencies(
9696
));
9797
}
9898

99+
// If this dependency has an explicit name in `Cargo.toml` that
100+
// means that the `name` we have listed is actually the package name
101+
// that we're depending on. The `name` listed in the index is the
102+
// Cargo.toml-written-name which is what cargo uses for
103+
// `--extern foo=...`
104+
let (name, package) = match &dep.explicit_name_in_toml {
105+
Some(explicit) => (explicit.to_string(), Some(dep.name.to_string())),
106+
None => (dep.name.to_string(), None),
107+
};
108+
99109
Ok((
100110
git::Dependency {
101-
name: dep.name.to_string(),
111+
name,
102112
req: dep.version_req.to_string(),
103113
features: dep.features.iter().map(|s| s.to_string()).collect(),
104114
optional: dep.optional,
105115
default_features: dep.default_features,
106116
target: dep.target.clone(),
107117
kind: dep.kind.or(Some(DependencyKind::Normal)),
118+
package,
108119
},
109120
(
110121
version_id.eq(target_version_id),

src/views/krate_publish.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub struct CrateDependency {
6363
pub version_req: CrateVersionReq,
6464
pub target: Option<String>,
6565
pub kind: Option<DependencyKind>,
66+
pub explicit_name_in_toml: Option<CrateName>,
6667
}
6768

6869
impl<'de> Deserialize<'de> for CrateName {

0 commit comments

Comments
 (0)