Skip to content

Commit 5d61ea5

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 8df5ba8 commit 5d61ea5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,22 @@ private func createResolvedPackages(
438438
let explicitIdsOrNames = Set(explicitProducts.lazy.map({ lookupByProductIDs ? $0.identity : $0.name }))
439439
return dependency.products.filter({ lookupByProductIDs ? explicitIdsOrNames.contains($0.product.identity) : explicitIdsOrNames.contains($0.product.name) })
440440
})
441-
let productDependencyMap = lookupByProductIDs ? productDependencies.spm_createDictionary({ ($0.product.identity, $0) }) : productDependencies.spm_createDictionary({ ($0.product.name, $0) })
441+
442+
let productDependencyMap: [String: ResolvedProductBuilder]
443+
if lookupByProductIDs {
444+
productDependencyMap = productDependencies.spm_createDictionary { ($0.product.identity, $0) }
445+
} else {
446+
productDependencyMap = try Dictionary(
447+
productDependencies.map { ($0.product.name, $0) },
448+
uniquingKeysWith: { lhs, _ in
449+
let duplicates = productDependencies.filter { $0.product.name == lhs.product.name }
450+
throw PackageGraphError.duplicateProduct(
451+
product: lhs.product.name,
452+
packages: duplicates.map(\.packageBuilder.package.identity.description)
453+
)
454+
}
455+
)
456+
}
442457

443458
// Establish dependencies in each target.
444459
for targetBuilder in packageBuilder.targets {

0 commit comments

Comments
 (0)