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 {
77
77
public let product : Product
78
78
}
79
79
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
+
80
94
struct SystemPackageDeprecatedDiagnostic : DiagnosticData {
81
95
static let id = DiagnosticID (
82
96
type: SystemPackageDeprecatedDiagnostic . self,
Original file line number Diff line number Diff line change @@ -595,6 +595,12 @@ public final class PackageBuilder {
595
595
providers: manifestTarget? . providers
596
596
)
597
597
}
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
+ }
598
604
599
605
// Compute the path to public headers directory.
600
606
let publicHeaderComponent = manifestTarget? . publicHeadersPath ?? ClangTarget . defaultPublicHeadersComponent
Original file line number Diff line number Diff line change @@ -1576,6 +1576,40 @@ class PackageBuilderTests: XCTestCase {
1576
1576
result. checkDiagnostic ( " invalid header search path '../../..'; header search path should not be outside the package root " )
1577
1577
}
1578
1578
}
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
+ }
1579
1613
}
1580
1614
1581
1615
extension PackageModel . Product : ObjectIdentifierProtocol { }
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ extension PackageBuilderTests {
33
33
( " testDeclaredExecutableProducts " , testDeclaredExecutableProducts) ,
34
34
( " testDotFilesAreIgnored " , testDotFilesAreIgnored) ,
35
35
( " testDuplicateProducts " , testDuplicateProducts) ,
36
+ ( " testDuplicateTargetDependencies " , testDuplicateTargetDependencies) ,
36
37
( " testDuplicateTargets " , testDuplicateTargets) ,
37
38
( " testExcludes " , testExcludes) ,
38
39
( " testExecutableAsADep " , testExecutableAsADep) ,
You can’t perform that action at this time.
0 commit comments