Skip to content

Commit 3812ddd

Browse files
author
David Ungar
authored
Merge pull request #412 from davidungar/buildrec-match2
[Incremental] Mimic legacy for testing, can omit argsHash from build record and it still matches.
2 parents aa97a35 + 8a3d972 commit 3812ddd

File tree

5 files changed

+48
-4
lines changed

5 files changed

+48
-4
lines changed

Sources/SwiftDriver/Incremental Compilation/BuildRecord.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ public struct BuildRecord {
7777

7878
// MARK: - Reading the old map and deciding whether to use it
7979
public extension BuildRecord {
80-
init(contents: String) throws {
80+
init(contents: String, defaultArgsHash: String? = nil) throws {
8181
guard let sections = try Parser(yaml: contents, resolver: .basic, encoding: .utf8)
8282
.singleRoot()?.mapping
8383
else { throw SimpleErrors.couldNotDecodeBuildRecord }
84-
var argsHash, swiftVersion: String?
85-
var buildTime: Date?
84+
var argsHash: String? = defaultArgsHash
85+
var swiftVersion: String?
86+
// Legacy driver does not disable incremental if no buildTime field.
87+
var buildTime: Date = .distantPast
8688
var inputInfos: [VirtualPath: InputInfo]?
8789
for (key, value) in sections {
8890
guard let k = key.string else { throw SimpleErrors.sectionNameNotString }

Sources/SwiftDriver/Incremental Compilation/BuildRecordInfo.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,14 @@ struct JobResult {
152152
// TODO: Incremental too many names, buildRecord BuildRecord outofdatemap
153153
func populateOutOfDateBuildRecord(
154154
inputFiles: [TypedVirtualPath],
155+
defaultArgsHash: String?,
155156
failed: (String) -> Void
156157
) -> BuildRecord? {
157158
let outOfDateBuildRecord: BuildRecord
158159
do {
159160
let contents = try fileSystem.readFileContents(buildRecordPath).cString
160-
outOfDateBuildRecord = try BuildRecord(contents: contents)
161+
outOfDateBuildRecord = try BuildRecord(contents: contents,
162+
defaultArgsHash: defaultArgsHash)
161163
}
162164
catch {
163165
failed("could not read build record at \(buildRecordPath): \(error.localizedDescription).")

Sources/SwiftDriver/Incremental Compilation/IncrementalCompilationState.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,15 @@ public class IncrementalCompilationState {
7474
return nil
7575
}
7676

77+
// Mimic the legacy driver for testing ease: If no `argsHash` section,
78+
// record still matches.
79+
let defaultArgsHash = buildRecordInfo.argsHash
80+
7781
// FIXME: This should work without an output file map. We should have
7882
// another way to specify a build record and where to put intermediates.
7983
guard let outOfDateBuildRecord = buildRecordInfo.populateOutOfDateBuildRecord(
8084
inputFiles: inputFiles,
85+
defaultArgsHash: defaultArgsHash,
8186
failed: {
8287
diagnosticEngine.emit(
8388
.remark_incremental_compilation_disabled(because: $0))

Tests/SwiftDriverTests/IncrementalCompilationTests.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ final class NonincrementalCompilationTests: XCTestCase {
3737
])
3838
}
3939

40+
func testBuildRecordWithoutOptionsReading() throws {
41+
let hash = "abbbfbcaf36b93e58efaadd8271ff142"
42+
let buildRecord = try! BuildRecord(
43+
contents: Inputs.buildRecordWithoutOptions,
44+
defaultArgsHash: hash)
45+
XCTAssertEqual(buildRecord.swiftVersion,
46+
"Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)")
47+
XCTAssertEqual(buildRecord.argsHash, hash)
48+
49+
try XCTAssertEqual(buildRecord.buildTime,
50+
Date(legacyDriverSecsAndNanos: [1570318779, 32358000]))
51+
try XCTAssertEqual(buildRecord.inputInfos,
52+
[
53+
VirtualPath(path: "/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/file2.swift"):
54+
InputInfo(status: .needsCascadingBuild,
55+
previousModTime: Date(legacyDriverSecsAndNanos: [1570318778, 0])),
56+
VirtualPath(path: "/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/main.swift"):
57+
InputInfo(status: .upToDate,
58+
previousModTime: Date(legacyDriverSecsAndNanos: [1570083660, 0])),
59+
VirtualPath(path: "/Volumes/gazorp.swift"):
60+
InputInfo(status: .needsNonCascadingBuild,
61+
previousModTime: Date(legacyDriverSecsAndNanos: [0, 0]))
62+
])
63+
}
64+
4065
func testReadBinarySourceFileDependencyGraph() throws {
4166
let packageRootPath = URL(fileURLWithPath: #file).pathComponents
4267
.prefix(while: { $0 != "Tests" }).joined(separator: "/").dropFirst()

Tests/SwiftDriverTests/Inputs/IncrementalCompilationInputs.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ enum Inputs {
2424
"/Volumes/gazorp.swift": !private [0,0]
2525
"""
2626
}
27+
static var buildRecordWithoutOptions: String {
28+
"""
29+
version: "Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)"
30+
build_time: [1570318779, 32358000]
31+
inputs:
32+
"/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/file2.swift": !dirty [1570318778, 0]
33+
"/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/main.swift": [1570083660, 0]
34+
"/Volumes/gazorp.swift": !private [0,0]
35+
"""
36+
}
2737
static var fineGrainedSourceFileDependencyGraph: String {
2838
"""
2939
# Fine-grained v0

0 commit comments

Comments
 (0)