Skip to content

Commit 273a4ef

Browse files
committed
SwiftPM 5.2 introduced a regression that caused a semantic change in how package manifests declaring a tools version earlier than 5.3 were parsed. Specifically, files with an unknown source type are not ignored, as they were in SwiftPM 5.1.x and earlier. This leads to issues such as the one reported here: https://swiftpm.slack.com/archives/C14QU6CUU/p1587442104122300
1 parent 031a0f4 commit 273a4ef

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Sources/PackageLoading/TargetSourcesBuilder.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ public struct TargetSourcesBuilder {
175175
if let ext = path.extension,
176176
FileRuleDescription.header.fileTypes.contains(ext) {
177177
matchedRule = Rule(rule: .header, localization: nil)
178-
} else {
178+
} else if toolsVersion >= .v5_3 {
179+
matchedRule = Rule(rule: .compile, localization: nil)
180+
} else if let ext = path.extension,
181+
SupportedLanguageExtension.validExtensions(toolsVersion: toolsVersion).contains(ext) {
179182
matchedRule = Rule(rule: .compile, localization: nil)
180183
}
181184
// The source file might have been declared twice so

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,30 @@ class PackageBuilderTests: XCTestCase {
16591659
}
16601660
}
16611661

1662+
func testUnknownSourceFilesUnderDeclaredSourcesIgnoredInV5_2Manifest() throws {
1663+
// Files with unknown suffixes under declared sources are not considered valid sources in 5.2 manifest.
1664+
let fs = InMemoryFileSystem(emptyFiles:
1665+
"/Sources/lib/movie.mkv",
1666+
"/Sources/lib/lib.c",
1667+
"/Sources/lib/include/lib.h"
1668+
)
1669+
1670+
let manifest = Manifest.createManifest(
1671+
name: "pkg",
1672+
v: .v5_2,
1673+
targets: [
1674+
TargetDescription(name: "lib", dependencies: [], path: "./Sources/lib", sources: ["."]),
1675+
]
1676+
)
1677+
1678+
PackageBuilderTester(manifest, in: fs) { package, _ in
1679+
package.checkModule("lib") { module in
1680+
module.checkSources(root: "/Sources/lib", paths: "lib.c")
1681+
module.check(includeDir: "/Sources/lib/include")
1682+
}
1683+
}
1684+
}
1685+
16621686
func testBuildSettings() {
16631687
let fs = InMemoryFileSystem(emptyFiles:
16641688
"/Sources/exe/main.swift",

0 commit comments

Comments
 (0)