Skip to content

Commit 2350b97

Browse files
authored
Merge pull request #2574 from aciidb0mb3r/break-will-break-your-bones-5.2
[PackageLoading] Handle duplicated declared sources
2 parents cb170f4 + 99cfe5f commit 2350b97

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Sources/PackageLoading/TargetSourcesBuilder.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ public struct TargetSourcesBuilder {
158158
} else {
159159
matchedRule = .compile
160160
}
161+
// The source file might have been declared twice so
162+
// exit on first match.
163+
// FIXME: We should emitting warnings for duplicate// declarations.
164+
break
161165
}
162166
}
163167
}

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,32 @@ class PackageBuilderTests: XCTestCase {
290290
}
291291
}
292292

293+
func testOverlappingDeclaredSources() throws {
294+
let fs = InMemoryFileSystem(emptyFiles:
295+
"/Sources/clib/subfolder/foo.h",
296+
"/Sources/clib/subfolder/foo.c",
297+
"/Sources/clib/bar.h",
298+
"/Sources/clib/bar.c",
299+
"/done"
300+
)
301+
302+
let manifest = Manifest.createV4Manifest(
303+
name: "MyPackage",
304+
targets: [
305+
TargetDescription(
306+
name: "clib",
307+
path: "Sources",
308+
sources: ["clib", "clib/subfolder"]
309+
),
310+
]
311+
)
312+
PackageBuilderTester(manifest, in: fs) { result in
313+
result.checkModule("clib") { module in
314+
module.checkSources(sources: ["clib/bar.c", "clib/subfolder/foo.c"])
315+
}
316+
}
317+
}
318+
293319
func testDeclaredExecutableProducts() {
294320
// Check that declaring executable product doesn't collide with the
295321
// inferred products.

Tests/PackageLoadingTests/XCTestManifests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extension PackageBuilderTests {
3131
("testCustomTargetPaths", testCustomTargetPaths),
3232
("testCustomTargetPathsOverlap", testCustomTargetPathsOverlap),
3333
("testDeclaredExecutableProducts", testDeclaredExecutableProducts),
34+
("testDeclaredSourcesWithDot", testDeclaredSourcesWithDot),
3435
("testDotFilesAreIgnored", testDotFilesAreIgnored),
3536
("testDuplicateProducts", testDuplicateProducts),
3637
("testDuplicateTargetDependencies", testDuplicateTargetDependencies),
@@ -46,6 +47,7 @@ extension PackageBuilderTests {
4647
("testMixedSources", testMixedSources),
4748
("testModuleMapLayout", testModuleMapLayout),
4849
("testMultipleTestProducts", testMultipleTestProducts),
50+
("testOverlappingDeclaredSources", testOverlappingDeclaredSources),
4951
("testPlatforms", testPlatforms),
5052
("testPredefinedTargetSearchError", testPredefinedTargetSearchError),
5153
("testPublicHeadersPath", testPublicHeadersPath),

0 commit comments

Comments
 (0)