Skip to content

Disable output file map diagnostic for non-incremental mode #707

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
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
1 change: 1 addition & 0 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ public struct Driver {
fileSystem: fileSystem,
moduleOutputInfo: moduleOutputInfo,
outputFileMap: outputFileMap,
incremental: self.shouldAttemptIncrementalCompilation,
parsedOptions: parsedOptions,
recordedInputModificationDates: recordedInputModificationDates)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ import SwiftOptions
fileSystem: FileSystem,
moduleOutputInfo: ModuleOutputInfo,
outputFileMap: OutputFileMap?,
incremental: Bool,
parsedOptions: ParsedOptions,
recordedInputModificationDates: [TypedVirtualPath: Date]
) {
// Cannot write a buildRecord without a path.
guard let buildRecordPath = Self.computeBuildRecordPath(
outputFileMap: outputFileMap,
incremental: incremental,
compilerOutputType: compilerOutputType,
workingDirectory: workingDirectory,
diagnosticEngine: diagnosticEngine)
Expand Down Expand Up @@ -124,6 +126,7 @@ import SwiftOptions
/// Determine the input and output path for the build record
private static func computeBuildRecordPath(
outputFileMap: OutputFileMap?,
incremental: Bool,
compilerOutputType: FileType?,
workingDirectory: AbsolutePath?,
diagnosticEngine: DiagnosticsEngine
Expand All @@ -136,7 +139,9 @@ import SwiftOptions
guard let partialBuildRecordPath =
ofm.existingOutputForSingleInput(outputType: .swiftDeps)
else {
diagnosticEngine.emit(.warning_incremental_requires_build_record_entry)
if incremental {
diagnosticEngine.emit(.warning_incremental_requires_build_record_entry)
}
return nil
}
return workingDirectory
Expand Down
45 changes: 45 additions & 0 deletions Tests/SwiftDriverTests/IncrementalCompilationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,45 @@ extension IncrementalCompilationTests {
try checkPropagationOfTopLevelChange(checkDiagnostics: checkDiagnostics)
}

func testFileMapMissingMainEntry() throws {
try buildInitialState(checkDiagnostics: true)
OutputFileMapCreator.write(
module: module, inputPaths: inputPathsAndContents.map {$0.0},
derivedData: derivedDataPath, to: OFM, excludeMainEntry: true)
try doABuild("output file map missing main entry", checkDiagnostics: true, extraArguments: [], whenAutolinking: []) {
missingMainDependencyEntry
disablingIncremental
foundBatchableJobs(2)
formingOneBatch
addingToBatchThenForming("main", "other")
compiling("main", "other")
startingLinking
finishedLinking
}
}

func testFileMapMissingMainEntryWMO() throws {
try buildInitialState(checkDiagnostics: true)
guard let sdkArgumentsForTesting = try Driver.sdkArgumentsForTesting()
else {
throw XCTSkip("Cannot perform this test on this host")
}

OutputFileMapCreator.write(
module: module, inputPaths: inputPathsAndContents.map {$0.0},
derivedData: derivedDataPath, to: OFM, excludeMainEntry: true)

let args = [
"swiftc",
"-module-name", module,
"-o", derivedDataPath.appending(component: module + ".o").pathString,
"-output-file-map", OFM.pathString,
"-whole-module-optimization",
"-no-color-diagnostics",
] + inputPathsAndContents.map {$0.0.pathString}.sorted() + sdkArgumentsForTesting
_ = try doABuild(whenAutolinking: [], expecting: [], arguments: args)
}

// FIXME: Expect failure in Linux in CI just as testIncrementalDiagnostics
func testAlwaysRebuildDependents() throws {
#if !os(Linux)
Expand Down Expand Up @@ -1257,6 +1296,12 @@ extension DiagVerifiable {
@DiagsBuilder var disablingIncrementalCannotReadBuildRecord: [Diagnostic.Message] {
"Incremental compilation: Disabling incremental build: could not read build record"
}
@DiagsBuilder var missingMainDependencyEntry: [Diagnostic.Message] {
.warning("ignoring -incremental; output file map has no master dependencies entry (\"swift-dependencies\" under \"\")")
}
@DiagsBuilder var disablingIncremental: [Diagnostic.Message] {
"Incremental compilation: Disabling incremental build: no build record path"
}
// MARK: - graph
@DiagsBuilder var createdGraphFromSwiftdeps: [Diagnostic.Message] {
"Incremental compilation: Created dependency graph from swiftdeps files"
Expand Down
14 changes: 10 additions & 4 deletions Tests/TestUtilities/OutputFileMapCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,28 @@ public struct OutputFileMapCreator {
private let module: String
private let inputPaths: [AbsolutePath]
private let derivedData: AbsolutePath
// The main entry isn't required for some WMO builds
private let excludeMainEntry: Bool

private init(module: String, inputPaths: [AbsolutePath], derivedData: AbsolutePath) {
private init(module: String, inputPaths: [AbsolutePath], derivedData: AbsolutePath, excludeMainEntry: Bool) {
self.module = module
self.inputPaths = inputPaths
self.derivedData = derivedData
self.excludeMainEntry = excludeMainEntry
}

public static func write(module: String,
inputPaths: [AbsolutePath],
derivedData: AbsolutePath,
to dst: AbsolutePath) {
let creator = Self(module: module, inputPaths: inputPaths, derivedData: derivedData)
to dst: AbsolutePath,
excludeMainEntry: Bool = false) {
let creator = Self(module: module, inputPaths: inputPaths, derivedData: derivedData, excludeMainEntry: excludeMainEntry)
try! localFileSystem.writeIfChanged(path: dst, bytes: ByteString(creator.generateData()))
}

private func generateDict() -> [String: [String: String]] {
let master = ["swift-dependencies": "\(derivedData.pathString)/\(module)-master.swiftdeps"]
let mainEntryDict = self.excludeMainEntry ? [:] : ["": master]
func baseNameEntry(_ s: AbsolutePath) -> [String: String] {
[
"dependencies": ".d",
Expand All @@ -46,10 +51,11 @@ public struct OutputFileMapCreator {
]
.mapValues {"\(derivedData.appending(component: s.basenameWithoutExt))\($0)"}
}

return Dictionary(uniqueKeysWithValues:
inputPaths.map { ("\($0)", baseNameEntry($0)) }
)
.merging(["": master]) {_, _ in fatalError()}
.merging(mainEntryDict) {_, _ in fatalError()}
}

private func generateData() -> Data {
Expand Down