Dashes in product name breaks dependency resolving
philprime opened this issue · comments
Philip Niedertscheider commented
When importing a package which contains dash in the library name, they are automatically replaced by the Xcode build system to underscores, which breaks the dependency resolving and makes them unusable.
Example: the package AppStoreConnect-Swift-SDK by @AvdLee
The product name is defined in the Package.swift as the following:
...
products: [
.library(name: "AppStoreConnect-Swift-SDK", targets: ["AppStoreConnect-Swift-SDK"])
],
...
which requires the import to be the following:
import AppStoreConnect_Swift_SDK // AvdLee/appstoreconnect-swift-sdk
// instead of
import AppStoreConnect-Swift-SDK // AvdLee/appstoreconnect-swift-sdk
as dashes are automatically replaced with _
.
This results in the following error:
'test' /Users/Philip/Library/Developer/swift-sh.cache/1f801762d2aba590bc4b77b62e521b02: error: product 'AppStoreConnect_Swift_SDK' not found in package 'appstoreconnect-swift-sdk'. it is required by package 'test' target 'test'.
warning: dependency 'AppStoreConnect-Swift-SDK' is not used by any target
error: 1 <(/usr/bin/swift build -Xswiftc -suppress-warnings)
Minimal Example to reproduce:
#!/usr/bin/swift sh
import AppStoreConnect_Swift_SDK // AvdLee/appstoreconnect-swift-sdk
Ideas to fix the issue:
- add option to define the product name, e.g.
#!/usr/bin/swift sh
import AppStoreConnect_Swift_SDK // AvdLee/appstoreconnect-swift-sdk#appstoreconnect-swift-sdk
- inform package authors about the name-convention breaking and provide a duplicated target, e.g.
products: [
// original:
.library(name: "AppStoreConnect-Swift-SDK", targets: ["AppStoreConnect-Swift-SDK"]),
// new:
.library(name: "AppStoreConnect_Swift_SDK", targets: ["AppStoreConnect-Swift-SDK"])
],
Max Howell commented
We parse the output from dump-package to try and get these things, probs needs updating since we switched to swift-package-tools version 5.1