File tree Expand file tree Collapse file tree 4 files changed +55
-0
lines changed
Tests/PackageLoadingTests Expand file tree Collapse file tree 4 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,20 @@ public enum PackageBuilderDiagnostics {
7777 public let product : Product
7878 }
7979
80+ public struct DuplicateTargetDependencyDiagnostic : DiagnosticData {
81+ public static let id = DiagnosticID (
82+ type: DuplicateTargetDependencyDiagnostic . self,
83+ name: " org.swift.diags.pkg-builder.dup-target-dependency " ,
84+ defaultBehavior: . warning,
85+ description: {
86+ $0 <<< " invalid duplicate target dependency declaration " <<< { " ' \( $0. dependency) ' " }
87+ <<< " in target " <<< { " ' \( $0. target) ' " }
88+ } )
89+
90+ public let dependency : String
91+ public let target : String
92+ }
93+
8094 struct SystemPackageDeprecatedDiagnostic : DiagnosticData {
8195 static let id = DiagnosticID (
8296 type: SystemPackageDeprecatedDiagnostic . self,
Original file line number Diff line number Diff line change @@ -595,6 +595,12 @@ public final class PackageBuilder {
595595 providers: manifestTarget? . providers
596596 )
597597 }
598+
599+ // Check for duplicate target dependencies by name
600+ let combinedDependencyNames = moduleDependencies. map { $0. name } + productDeps. map { $0. 0 }
601+ combinedDependencyNames. spm_findDuplicates ( ) . forEach {
602+ diagnostics. emit ( data: PackageBuilderDiagnostics . DuplicateTargetDependencyDiagnostic ( dependency: $0, target: potentialModule. name) )
603+ }
598604
599605 // Compute the path to public headers directory.
600606 let publicHeaderComponent = manifestTarget? . publicHeadersPath ?? ClangTarget . defaultPublicHeadersComponent
Original file line number Diff line number Diff line change @@ -1576,6 +1576,40 @@ class PackageBuilderTests: XCTestCase {
15761576 result. checkDiagnostic ( " invalid header search path '../../..'; header search path should not be outside the package root " )
15771577 }
15781578 }
1579+
1580+ func testDuplicateTargetDependencies( ) throws {
1581+ let fs = InMemoryFileSystem ( emptyFiles:
1582+ " /Foo/Sources/Foo/foo.swift " ,
1583+ " /Foo/Sources/Foo2/foo.swift " ,
1584+ " /Bar/Sources/Bar/bar.swift "
1585+ )
1586+
1587+ let manifest1 = Manifest . createManifest (
1588+ name: " Foo " ,
1589+ v: . v5,
1590+ dependencies: [
1591+ PackageDependencyDescription ( url: " /Bar " , requirement: . upToNextMajor( from: " 1.0.0 " ) ) ,
1592+ ] ,
1593+ targets: [
1594+ TargetDescription (
1595+ name: " Foo " ,
1596+ dependencies: [
1597+ " Bar " ,
1598+ " Bar " ,
1599+ " Foo2 " ,
1600+ " Foo2 " ,
1601+ ] ) ,
1602+ TargetDescription ( name: " Foo2 " ) ,
1603+ ]
1604+ )
1605+
1606+ PackageBuilderTester ( manifest1, path: AbsolutePath ( " /Foo " ) , in: fs) { result in
1607+ result. checkModule ( " Foo " )
1608+ result. checkModule ( " Foo2 " )
1609+ result. checkDiagnostic ( " invalid duplicate target dependency declaration 'Bar' in target 'Foo' " )
1610+ result. checkDiagnostic ( " invalid duplicate target dependency declaration 'Foo2' in target 'Foo' " )
1611+ }
1612+ }
15791613}
15801614
15811615extension PackageModel . Product : ObjectIdentifierProtocol { }
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ extension PackageBuilderTests {
3333 ( " testDeclaredExecutableProducts " , testDeclaredExecutableProducts) ,
3434 ( " testDotFilesAreIgnored " , testDotFilesAreIgnored) ,
3535 ( " testDuplicateProducts " , testDuplicateProducts) ,
36+ ( " testDuplicateTargetDependencies " , testDuplicateTargetDependencies) ,
3637 ( " testDuplicateTargets " , testDuplicateTargets) ,
3738 ( " testExcludes " , testExcludes) ,
3839 ( " testExecutableAsADep " , testExecutableAsADep) ,
You can’t perform that action at this time.
0 commit comments