Skip to content

[Incremental] Mimic legacy for testing, can omit argsHash from build record and it still matches. #412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Sources/SwiftDriver/Incremental Compilation/BuildRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ public struct BuildRecord {

// MARK: - Reading the old map and deciding whether to use it
public extension BuildRecord {
init(contents: String) throws {
init(contents: String, defaultArgsHash: String? = nil) throws {
guard let sections = try Parser(yaml: contents, resolver: .basic, encoding: .utf8)
.singleRoot()?.mapping
else { throw SimpleErrors.couldNotDecodeBuildRecord }
var argsHash, swiftVersion: String?
var buildTime: Date?
var argsHash: String? = defaultArgsHash
var swiftVersion: String?
// Legacy driver does not disable incremental if no buildTime field.
var buildTime: Date = .distantPast
var inputInfos: [VirtualPath: InputInfo]?
for (key, value) in sections {
guard let k = key.string else { throw SimpleErrors.sectionNameNotString }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ struct JobResult {
// TODO: Incremental too many names, buildRecord BuildRecord outofdatemap
func populateOutOfDateBuildRecord(
inputFiles: [TypedVirtualPath],
defaultArgsHash: String?,
failed: (String) -> Void
) -> BuildRecord? {
let outOfDateBuildRecord: BuildRecord
do {
let contents = try fileSystem.readFileContents(buildRecordPath).cString
outOfDateBuildRecord = try BuildRecord(contents: contents)
outOfDateBuildRecord = try BuildRecord(contents: contents,
defaultArgsHash: defaultArgsHash)
}
catch {
failed("could not read build record at \(buildRecordPath): \(error.localizedDescription).")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ public class IncrementalCompilationState {
return nil
}

// Mimic the legacy driver for testing ease: If no `argsHash` section,
// record still matches.
let defaultArgsHash = buildRecordInfo.argsHash

// FIXME: This should work without an output file map. We should have
// another way to specify a build record and where to put intermediates.
guard let outOfDateBuildRecord = buildRecordInfo.populateOutOfDateBuildRecord(
inputFiles: inputFiles,
defaultArgsHash: defaultArgsHash,
failed: {
diagnosticEngine.emit(
.remark_incremental_compilation_disabled(because: $0))
Expand Down
25 changes: 25 additions & 0 deletions Tests/SwiftDriverTests/IncrementalCompilationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ final class NonincrementalCompilationTests: XCTestCase {
])
}

func testBuildRecordWithoutOptionsReading() throws {
let hash = "abbbfbcaf36b93e58efaadd8271ff142"
let buildRecord = try! BuildRecord(
contents: Inputs.buildRecordWithoutOptions,
defaultArgsHash: hash)
XCTAssertEqual(buildRecord.swiftVersion,
"Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)")
XCTAssertEqual(buildRecord.argsHash, hash)

try XCTAssertEqual(buildRecord.buildTime,
Date(legacyDriverSecsAndNanos: [1570318779, 32358000]))
try XCTAssertEqual(buildRecord.inputInfos,
[
VirtualPath(path: "/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/file2.swift"):
InputInfo(status: .needsCascadingBuild,
previousModTime: Date(legacyDriverSecsAndNanos: [1570318778, 0])),
VirtualPath(path: "/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/main.swift"):
InputInfo(status: .upToDate,
previousModTime: Date(legacyDriverSecsAndNanos: [1570083660, 0])),
VirtualPath(path: "/Volumes/gazorp.swift"):
InputInfo(status: .needsNonCascadingBuild,
previousModTime: Date(legacyDriverSecsAndNanos: [0, 0]))
])
}

func testReadBinarySourceFileDependencyGraph() throws {
let packageRootPath = URL(fileURLWithPath: #file).pathComponents
.prefix(while: { $0 != "Tests" }).joined(separator: "/").dropFirst()
Expand Down
10 changes: 10 additions & 0 deletions Tests/SwiftDriverTests/Inputs/IncrementalCompilationInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ enum Inputs {
"/Volumes/gazorp.swift": !private [0,0]
"""
}
static var buildRecordWithoutOptions: String {
"""
version: "Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)"
build_time: [1570318779, 32358000]
inputs:
"/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/file2.swift": !dirty [1570318778, 0]
"/Volumes/AS/repos/swift-driver/sandbox/sandbox/sandbox/main.swift": [1570083660, 0]
"/Volumes/gazorp.swift": !private [0,0]
"""
}
static var fineGrainedSourceFileDependencyGraph: String {
"""
# Fine-grained v0
Expand Down