Skip to content

Perform Input Modification Checks At the End of the Build #563

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 1 commit into from
Mar 23, 2021
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
2 changes: 1 addition & 1 deletion Sources/SwiftDriver/Utilities/VirtualPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ extension TSCBasic.FileSystem {
try resolvingVirtualPath(path, apply: exists)
}

func lastModificationTime(for file: VirtualPath) throws -> Date {
public func lastModificationTime(for file: VirtualPath) throws -> Date {
try resolvingVirtualPath(file) { path in
#if os(macOS)
var s = Darwin.stat()
Expand Down
12 changes: 10 additions & 2 deletions Sources/SwiftDriverExecution/MultiJobExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ public final class MultiJobExecutor {

context.reportSkippedJobs()

// Check for any inputs that were modified during the build. Report these
// as errors so we don't e.g. reuse corrupted incremental build state.
for (input, recordedModTime) in context.recordedInputModificationDates {
guard try fileSystem.lastModificationTime(for: input.file) == recordedModTime else {
let err = Job.InputError.inputUnexpectedlyModified(input)
context.diagnosticsEngine.emit(err)
throw err
}
}

// Throw the stub error the build didn't finish successfully.
if !result.success {
throw Diagnostics.fatalError
Expand Down Expand Up @@ -535,8 +545,6 @@ class ExecuteJobRule: LLBuildRule {
let arguments: [String] = try resolver.resolveArgumentList(for: job,
forceResponseFiles: context.forceResponseFiles)

try job.verifyInputsNotModified(since: context.recordedInputModificationDates, fileSystem: engine.fileSystem)

let process = try context.processType.launchProcess(
arguments: arguments, env: env
)
Expand Down
7 changes: 5 additions & 2 deletions Tests/SwiftDriverTests/JobExecutorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,12 @@ final class JobExecutorTests: XCTestCase {
$0 <<< "let bar = 3"
}

// FIXME: It's unfortunate we diagnose this twice, once for each job which uses the input.
verifier.expect(.error("input file '\(other.description)' was modified during the build"))
verifier.expect(.error("input file '\(other.description)' was modified during the build"))
// There's a tool-specific linker error that usually happens here from
// whatever job runs last - probably the linker.
// It's no use testing for a particular error message, let's just make
// sure we emit the diagnostic we need.
verifier.permitUnexpected(.error)
XCTAssertThrowsError(try driver.run(jobs: jobs))
}
}
Expand Down