fix: handle renamed dependency for cargo registery

- When a dependency is renamed, specified via `package="actual-name"` in
Cargo.toml, this should become the name of the depedency when the
package is retrieved from the registery by cargo and the old name should
be available in the `package` field.
- The reference implementation also does this: 490e66a9d6/src/controllers/krate/publish.rs (L702-L705)
- Resolves #5936
- Unit test added.
This commit is contained in:
Gusted 2024-11-13 21:26:49 +01:00
parent 5614719e0a
commit bb93d3e6c8
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 37 additions and 7 deletions

View file

@ -96,7 +96,7 @@ func parsePackage(r io.Reader) (*Package, error) {
Target *string `json:"target"`
Kind string `json:"kind"`
Registry *string `json:"registry"`
ExplicitNameInToml string `json:"explicit_name_in_toml"`
ExplicitNameInToml *string `json:"explicit_name_in_toml"`
} `json:"deps"`
Features map[string][]string `json:"features"`
Authors []string `json:"authors"`
@ -136,8 +136,16 @@ func parsePackage(r io.Reader) (*Package, error) {
dependencies := make([]*Dependency, 0, len(meta.Deps))
for _, dep := range meta.Deps {
name := dep.Name
packageName := dep.ExplicitNameInToml
// If the explicit_name_in_toml field is set, the package is renamed and
// should be set accordingly.
if dep.ExplicitNameInToml != nil {
name = *dep.ExplicitNameInToml
packageName = &dep.Name
}
dependencies = append(dependencies, &Dependency{
Name: dep.Name,
Name: name,
Req: dep.VersionReq,
Features: dep.Features,
Optional: dep.Optional,
@ -145,6 +153,7 @@ func parsePackage(r io.Reader) (*Package, error) {
Target: dep.Target,
Kind: dep.Kind,
Registry: dep.Registry,
Package: packageName,
})
}