You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix resolve failing when package from registry is referenced by name (#8166)
### Motivation:
When running `swift package --replace-scm-with-registry
--default-registry-url {our-registry-url} resolve`, the command fails
when depending on packages that reference their transitive dependencies
by name.
I created a
[demo](https://github.com/fortmarek/spm-registry-by-name-references)
where you can reproduce the issue by running `swift package
--replace-scm-with-registry --default-registry-url {our-registry-url}
resolve`. You should see the following error:
```
error: 'cpisciotta.xcbeautify': unknown dependency 'Colorizer' in target 'XcbeautifyLib'; valid dependencies are: 'swift-argument-parser' (from 'https://github.com/apple/swift-argument-parser.git'), 'getGuaka.Colorizer', 'MaxDesiatov.XMLCoder'
error: 'cpisciotta.xcbeautify': unknown dependency 'XMLCoder' in target 'XcbeautifyLib'; valid dependencies are: 'swift-argument-parser' (from 'https://github.com/apple/swift-argument-parser.git'), 'getGuaka.Colorizer', 'MaxDesiatov.XMLCoder'
```
The issue boils down to:
```swift
// Root Package.swift
import PackageDescription
let package = Package(
name: "package-test",
dependencies: [
// We're depending on `xcbeautify` from our root `Package.swift`
.package(url: "https://github.com/cpisciotta/xcbeautify", exact: "2.13.0")
],
targets: [
.target(name: "package-test"),
]
)
// Package.swift at https://github.com/cpisciotta/xcbeautify/blob/main/Package.swift
import PackageDescription
let package = Package(
name: "xcbeautify",
products: [
.library(name: "XcbeautifyLib", targets: ["XcbeautifyLib"]),
],
dependencies: [
.package(
url: "https://github.com/getGuaka/Colorizer.git",
.upToNextMinor(from: "0.2.1")
),
.package(
url: "https://github.com/MaxDesiatov/XMLCoder.git",
.upToNextMinor(from: "0.17.1")
),
],
targets: [
.target(
name: "XcbeautifyLib",
dependencies: [
// Transitive package products referenced by name
"Colorizer",
"XMLCoder",
]
),
]
)
```
The issue is that when swizzling the package product names to their
identity counterparts, only dependencies referenced via `.product(...)`
are swizzled. Indeed, when we change the `XcbeautifyLib`'s dependencies
to:
```swift
.product(name: "Colorizer", package: "Colorizer"),
.product(name: "XMLCoder", package: "XMLCoder"),
```
the resolution succeeds.
### Modifications:
To fix the above issue, we swizzle also dependencies referenced by name
_iff_ the product name is the same as the package name the root depends
on. This aligns with how `byName` is treated in other parts of the
codebase, such as
[here](https://github.com/swiftlang/swift-package-manager/blob/main/Sources/PackageModel/Manifest/Manifest.swift#L407).
### Result:
`swift package --replace-scm-with-registry --default-registry-url
{our-registry-url} resolve` succeeds when run in the [repro
sample](https://github.com/fortmarek/spm-registry-by-name-references).
---------
Co-authored-by: Max Desiatov <[email protected]>
0 commit comments