Skip to content

Commit f163de5

Browse files
committed
Add tests
1 parent a75096b commit f163de5

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,45 @@ extension IncrementalCompilationTests {
266266
try checkPropagationOfTopLevelChange(checkDiagnostics: checkDiagnostics)
267267
}
268268

269+
func testFileMapMissingMainEntry() throws {
270+
try buildInitialState(checkDiagnostics: true)
271+
OutputFileMapCreator.write(
272+
module: module, inputPaths: inputPathsAndContents.map {$0.0},
273+
derivedData: derivedDataPath, to: OFM, excludeMainEntry: true)
274+
try doABuild("output file map missing main entry", checkDiagnostics: true, extraArguments: [], whenAutolinking: []) {
275+
missingMainDependencyEntry
276+
disablingIncremental
277+
foundBatchableJobs(2)
278+
formingOneBatch
279+
addingToBatchThenForming("main", "other")
280+
compiling("main", "other")
281+
startingLinking
282+
finishedLinking
283+
}
284+
}
285+
286+
func testFileMapMissingMainEntryWMO() throws {
287+
try buildInitialState(checkDiagnostics: true)
288+
guard let sdkArgumentsForTesting = try Driver.sdkArgumentsForTesting()
289+
else {
290+
throw XCTSkip("Cannot perform this test on this host")
291+
}
292+
293+
OutputFileMapCreator.write(
294+
module: module, inputPaths: inputPathsAndContents.map {$0.0},
295+
derivedData: derivedDataPath, to: OFM, excludeMainEntry: true)
296+
297+
let args = [
298+
"swiftc",
299+
"-module-name", module,
300+
"-o", derivedDataPath.appending(component: module + ".o").pathString,
301+
"-output-file-map", OFM.pathString,
302+
"-whole-module-optimization",
303+
"-no-color-diagnostics",
304+
] + inputPathsAndContents.map {$0.0.pathString}.sorted() + sdkArgumentsForTesting
305+
_ = try doABuild(whenAutolinking: [], expecting: [], arguments: args)
306+
}
307+
269308
// FIXME: Expect failure in Linux in CI just as testIncrementalDiagnostics
270309
func testAlwaysRebuildDependents() throws {
271310
#if !os(Linux)
@@ -1257,6 +1296,12 @@ extension DiagVerifiable {
12571296
@DiagsBuilder var disablingIncrementalCannotReadBuildRecord: [Diagnostic.Message] {
12581297
"Incremental compilation: Disabling incremental build: could not read build record"
12591298
}
1299+
@DiagsBuilder var missingMainDependencyEntry: [Diagnostic.Message] {
1300+
.warning("ignoring -incremental; output file map has no master dependencies entry (\"swift-dependencies\" under \"\")")
1301+
}
1302+
@DiagsBuilder var disablingIncremental: [Diagnostic.Message] {
1303+
"Incremental compilation: Disabling incremental build: no build record path"
1304+
}
12601305
// MARK: - graph
12611306
@DiagsBuilder var createdGraphFromSwiftdeps: [Diagnostic.Message] {
12621307
"Incremental compilation: Created dependency graph from swiftdeps files"

Tests/TestUtilities/OutputFileMapCreator.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,27 @@ public struct OutputFileMapCreator {
1818
private let module: String
1919
private let inputPaths: [AbsolutePath]
2020
private let derivedData: AbsolutePath
21+
private let excludeMainEntry: Bool
2122

22-
private init(module: String, inputPaths: [AbsolutePath], derivedData: AbsolutePath) {
23+
private init(module: String, inputPaths: [AbsolutePath], derivedData: AbsolutePath, excludeMainEntry: Bool) {
2324
self.module = module
2425
self.inputPaths = inputPaths
2526
self.derivedData = derivedData
27+
self.excludeMainEntry = excludeMainEntry
2628
}
2729

2830
public static func write(module: String,
2931
inputPaths: [AbsolutePath],
3032
derivedData: AbsolutePath,
31-
to dst: AbsolutePath) {
32-
let creator = Self(module: module, inputPaths: inputPaths, derivedData: derivedData)
33+
to dst: AbsolutePath,
34+
excludeMainEntry: Bool = false) {
35+
let creator = Self(module: module, inputPaths: inputPaths, derivedData: derivedData, excludeMainEntry: excludeMainEntry)
3336
try! localFileSystem.writeIfChanged(path: dst, bytes: ByteString(creator.generateData()))
3437
}
3538

3639
private func generateDict() -> [String: [String: String]] {
3740
let master = ["swift-dependencies": "\(derivedData.pathString)/\(module)-master.swiftdeps"]
41+
let mainEntryDict = self.excludeMainEntry ? [:] : ["": master]
3842
func baseNameEntry(_ s: AbsolutePath) -> [String: String] {
3943
[
4044
"dependencies": ".d",
@@ -46,10 +50,11 @@ public struct OutputFileMapCreator {
4650
]
4751
.mapValues {"\(derivedData.appending(component: s.basenameWithoutExt))\($0)"}
4852
}
53+
4954
return Dictionary(uniqueKeysWithValues:
5055
inputPaths.map { ("\($0)", baseNameEntry($0)) }
5156
)
52-
.merging(["": master]) {_, _ in fatalError()}
57+
.merging(mainEntryDict) {_, _ in fatalError()}
5358
}
5459

5560
private func generateData() -> Data {

0 commit comments

Comments
 (0)