Skip to content

Do not crash on duplicated product names #6245

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 20, 2023
Merged
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
17 changes: 16 additions & 1 deletion Sources/PackageGraph/PackageGraph+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,22 @@ private func createResolvedPackages(
let explicitIdsOrNames = Set(explicitProducts.lazy.map({ lookupByProductIDs ? $0.identity : $0.name }))
return dependency.products.filter({ lookupByProductIDs ? explicitIdsOrNames.contains($0.product.identity) : explicitIdsOrNames.contains($0.product.name) })
})
let productDependencyMap = lookupByProductIDs ? productDependencies.spm_createDictionary({ ($0.product.identity, $0) }) : productDependencies.spm_createDictionary({ ($0.product.name, $0) })

let productDependencyMap: [String: ResolvedProductBuilder]
if lookupByProductIDs {
productDependencyMap = productDependencies.spm_createDictionary { ($0.product.identity, $0) }
} else {
productDependencyMap = try Dictionary(
productDependencies.map { ($0.product.name, $0) },
uniquingKeysWith: { lhs, _ in
let duplicates = productDependencies.filter { $0.product.name == lhs.product.name }
throw PackageGraphError.duplicateProduct(
product: lhs.product.name,
packages: duplicates.map(\.packageBuilder.package.identity.description)
)
}
)
}

// Establish dependencies in each target.
for targetBuilder in packageBuilder.targets {
Expand Down