Skip to content

Commit 67cb4a5

Browse files
committed
Do not crash on duplicated product names
Instead we need to raise an error if we end up in that situation. rdar://106432785
1 parent 50f7b54 commit 67cb4a5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,16 @@ private func createResolvedPackages(
435435
let explicitIdsOrNames = Set(explicitProducts.lazy.map({ lookupByProductIDs ? $0.identity : $0.name }))
436436
return dependency.products.filter({ lookupByProductIDs ? explicitIdsOrNames.contains($0.product.identity) : explicitIdsOrNames.contains($0.product.name) })
437437
})
438-
let productDependencyMap = lookupByProductIDs ? productDependencies.spm_createDictionary({ ($0.product.identity, $0) }) : productDependencies.spm_createDictionary({ ($0.product.name, $0) })
438+
439+
let productDependencyMap: [String: ResolvedProductBuilder]
440+
if lookupByProductIDs {
441+
productDependencyMap = productDependencies.spm_createDictionary({ ($0.product.identity, $0) })
442+
} else {
443+
productDependencyMap = try Dictionary(productDependencies.map({ ($0.product.name, $0) }), uniquingKeysWith: { lhs, rhs in
444+
let duplicates = productDependencies.filter { $0.product.name == lhs.product.name }
445+
throw PackageGraphError.duplicateProduct(product: lhs.product.name, packages: duplicates.map { $0.packageBuilder.package.identity.description })
446+
})
447+
}
439448

440449
// Establish dependencies in each target.
441450
for targetBuilder in packageBuilder.targets {

0 commit comments

Comments
 (0)