Skip to content

Revert TSCUtility changes #1280

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

Closed
wants to merge 2 commits into from
Closed
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
84 changes: 26 additions & 58 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,7 @@ import struct TSCBasic.RelativePath
import var TSCBasic.localFileSystem
import var TSCBasic.stderrStream
import var TSCBasic.stdoutStream

extension Driver {
/// Stub Error for terminating the process.
public enum ErrorDiagnostics: Swift.Error {
case emitted
}
}

extension Driver.ErrorDiagnostics: CustomStringConvertible {
public var description: String {
switch self {
case .emitted:
return "errors were encountered"
}
}
}

import enum TSCUtility.Diagnostics

/// The Swift driver.
public struct Driver {
Expand Down Expand Up @@ -611,8 +595,7 @@ public struct Driver {
if let digesterMode = DigesterMode(rawValue: modeArg) {
mode = digesterMode
} else {
diagnosticsEngine.emit(.error(Error.invalidArgumentValue(Option.digesterMode.spelling, modeArg)),
location: nil)
diagnosticsEngine.emit(Error.invalidArgumentValue(Option.digesterMode.spelling, modeArg))
}
}
self.digesterMode = mode
Expand Down Expand Up @@ -679,8 +662,7 @@ public struct Driver {
Driver.isOptionFound($0, allOpts: supportedFrontendFlagsLocal)
}
self.savedUnknownDriverFlagsForSwiftFrontend.forEach {
diagnosticsEngine.emit(.warning("save unknown driver flag \($0) as additional swift-frontend flag"),
location: nil)
diagnosticsEngine.emit(warning: "save unknown driver flag \($0) as additional swift-frontend flag")
}
self.supportedFrontendFeatures = try Self.computeSupportedCompilerFeatures(of: self.toolchain, env: env)

Expand Down Expand Up @@ -969,8 +951,7 @@ extension Driver {
shouldComplain = self.inputFiles.filter { $0.type.isPartOfSwiftCompilation }.count > 1 && .singleCompile != compilerMode
}
if shouldComplain {
diagnosticEngine.emit(.error(Error.cannotSpecify_OForMultipleOutputs),
location: nil)
diagnosticEngine.emit(Error.cannotSpecify_OForMultipleOutputs)
}
}
}
Expand Down Expand Up @@ -1858,7 +1839,7 @@ extension Driver {
if let originalPath = swiftFiles[basename] {
diagnosticsEngine.emit(.error_two_files_same_name(basename: basename, firstPath: originalPath, secondPath: input))
diagnosticsEngine.emit(.note_explain_two_files_same_name)
throw ErrorDiagnostics.emitted
throw Diagnostics.fatalError
} else {
swiftFiles[basename] = input
}
Expand All @@ -1871,7 +1852,7 @@ extension Driver {
if let mainPath = swiftFiles["main.swift"] {
diagnosticsEngine.emit(.error_two_files_same_name(basename: "main.swift", firstPath: mainPath, secondPath: "-e"))
diagnosticsEngine.emit(.note_explain_two_files_same_name)
throw ErrorDiagnostics.emitted
throw Diagnostics.fatalError
}

try withTemporaryDirectory(dir: fileSystem.tempDirectory, removeTreeOnDeinit: false) { absPath in
Expand Down Expand Up @@ -2679,8 +2660,7 @@ extension Driver {
diagnosticEngine: DiagnosticsEngine) {
if parsedOptions.hasArgument(.suppressWarnings) &&
parsedOptions.hasFlag(positive: .warningsAsErrors, negative: .noWarningsAsErrors, default: false) {
diagnosticEngine.emit(.error(Error.conflictingOptions(.warningsAsErrors, .suppressWarnings)),
location: nil)
diagnosticEngine.emit(Error.conflictingOptions(.warningsAsErrors, .suppressWarnings))
}
}

Expand All @@ -2691,30 +2671,25 @@ extension Driver {
diagnosticEngine: DiagnosticsEngine) {
if moduleOutputInfo.output?.isTopLevel != true {
for arg in parsedOptions.arguments(for: .emitDigesterBaseline, .emitDigesterBaselinePath, .compareToBaselinePath) {
diagnosticEngine.emit(.error(Error.baselineGenerationRequiresTopLevelModule(arg.option.spelling)),
location: nil)
diagnosticEngine.emit(Error.baselineGenerationRequiresTopLevelModule(arg.option.spelling))
}
}

if parsedOptions.hasArgument(.serializeBreakingChangesPath) && !parsedOptions.hasArgument(.compareToBaselinePath) {
diagnosticEngine.emit(.error(Error.optionRequiresAnother(Option.serializeBreakingChangesPath.spelling,
Option.compareToBaselinePath.spelling)),
location: nil)
diagnosticEngine.emit(Error.optionRequiresAnother(Option.serializeBreakingChangesPath.spelling,
Option.compareToBaselinePath.spelling))
}
if parsedOptions.hasArgument(.digesterBreakageAllowlistPath) && !parsedOptions.hasArgument(.compareToBaselinePath) {
diagnosticEngine.emit(.error(Error.optionRequiresAnother(Option.digesterBreakageAllowlistPath.spelling,
Option.compareToBaselinePath.spelling)),
location: nil)
diagnosticEngine.emit(Error.optionRequiresAnother(Option.digesterBreakageAllowlistPath.spelling,
Option.compareToBaselinePath.spelling))
}
if digesterMode == .abi && !parsedOptions.hasArgument(.enableLibraryEvolution) {
diagnosticEngine.emit(.error(Error.optionRequiresAnother("\(Option.digesterMode.spelling) abi",
Option.enableLibraryEvolution.spelling)),
location: nil)
diagnosticEngine.emit(Error.optionRequiresAnother("\(Option.digesterMode.spelling) abi",
Option.enableLibraryEvolution.spelling))
}
if digesterMode == .abi && swiftInterfacePath == nil {
diagnosticEngine.emit(.error(Error.optionRequiresAnother("\(Option.digesterMode.spelling) abi",
Option.emitModuleInterface.spelling)),
location: nil)
diagnosticEngine.emit(Error.optionRequiresAnother("\(Option.digesterMode.spelling) abi",
Option.emitModuleInterface.spelling))
}
}

Expand All @@ -2723,16 +2698,14 @@ extension Driver {
// '-print-explicit-dependency-graph' requires '-explicit-module-build'
if parsedOptions.hasArgument(.printExplicitDependencyGraph) &&
!parsedOptions.hasArgument(.driverExplicitModuleBuild) {
diagnosticEngine.emit(.error(Error.optionRequiresAnother(Option.printExplicitDependencyGraph.spelling,
Option.driverExplicitModuleBuild.spelling)),
location: nil)
diagnosticEngine.emit(Error.optionRequiresAnother(Option.printExplicitDependencyGraph.spelling,
Option.driverExplicitModuleBuild.spelling))
}
// '-explicit-dependency-graph-format=' requires '-print-explicit-dependency-graph'
if parsedOptions.hasArgument(.explicitDependencyGraphFormat) &&
!parsedOptions.hasArgument(.printExplicitDependencyGraph) {
diagnosticEngine.emit(.error(Error.optionRequiresAnother(Option.explicitDependencyGraphFormat.spelling,
Option.printExplicitDependencyGraph.spelling)),
location: nil)
diagnosticEngine.emit(Error.optionRequiresAnother(Option.explicitDependencyGraphFormat.spelling,
Option.printExplicitDependencyGraph.spelling))
}
// '-explicit-dependency-graph-format=' only supports values 'json' and 'dot'
if let formatArg = parsedOptions.getLastArgument(.explicitDependencyGraphFormat)?.asSingle {
Expand All @@ -2749,8 +2722,7 @@ extension Driver {
diagnosticEngine: DiagnosticsEngine) {
if parsedOptions.hasArgument(.profileGenerate) &&
parsedOptions.hasArgument(.profileUse) {
diagnosticEngine.emit(.error(Error.conflictingOptions(.profileGenerate, .profileUse)),
location: nil)
diagnosticEngine.emit(Error.conflictingOptions(.profileGenerate, .profileUse))
}

if let profileArgs = parsedOptions.getLastArgument(.profileUse)?.asMultiple,
Expand All @@ -2759,8 +2731,7 @@ extension Driver {
if let path = try? AbsolutePath(validating: profilingData,
relativeTo: workingDirectory) {
if !fileSystem.exists(path) {
diagnosticEngine.emit(.error(Error.missingProfilingData(profilingData)),
location: nil)
diagnosticEngine.emit(Error.missingProfilingData(profilingData))
}
}
}
Expand All @@ -2771,8 +2742,7 @@ extension Driver {
diagnosticEngine: DiagnosticsEngine) {
if parsedOptions.contains(.parseableOutput) &&
parsedOptions.contains(.useFrontendParseableOutput) {
diagnosticEngine.emit(.error(Error.conflictingOptions(.parseableOutput, .useFrontendParseableOutput)),
location: nil)
diagnosticEngine.emit(Error.conflictingOptions(.parseableOutput, .useFrontendParseableOutput))
}
}

Expand All @@ -2782,11 +2752,9 @@ extension Driver {
if arg.contains("=") {
diagnosticEngine.emit(.warning_cannot_assign_to_compilation_condition(name: arg))
} else if arg.hasPrefix("-D") {
diagnosticEngine.emit(.error(Error.conditionalCompilationFlagHasRedundantPrefix(arg)),
location: nil)
diagnosticEngine.emit(Error.conditionalCompilationFlagHasRedundantPrefix(arg))
} else if !arg.sd_isSwiftIdentifier {
diagnosticEngine.emit(.error(Error.conditionalCompilationFlagIsNotValidIdentifier(arg)),
location: nil)
diagnosticEngine.emit(Error.conditionalCompilationFlagIsNotValidIdentifier(arg))
}
}
}
Expand Down Expand Up @@ -2910,7 +2878,7 @@ extension Triple {
return WindowsToolchain.self
default:
diagnosticsEngine.emit(.error_unknown_target(triple))
throw Driver.ErrorDiagnostics.emitted
throw Diagnostics.fatalError
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,13 @@ extension IncrementalCompilationState.IncrementalDependencyAndInputSetup {
graphIfPresent = try ModuleDependencyGraph.read(from: dependencyGraphPath, info: self)
}
catch let ModuleDependencyGraph.ReadError.mismatchedSerializedGraphVersion(expected, read) {
diagnosticEngine.emit(.warning("Will not do cross-module incremental builds, wrong version of priors; expected \(expected) but read \(read) at '\(dependencyGraphPath)'"),
location: nil)
diagnosticEngine.emit(
warning: "Will not do cross-module incremental builds, wrong version of priors; expected \(expected) but read \(read) at '\(dependencyGraphPath)'")
graphIfPresent = nil
}
catch {
diagnosticEngine.emit(.warning("Could not read priors, will not do cross-module incremental builds: \(error.localizedDescription), at \(dependencyGraphPath)"),
location: nil)
diagnosticEngine.emit(
warning: "Could not read priors, will not do cross-module incremental builds: \(error.localizedDescription), at \(dependencyGraphPath)")
graphIfPresent = nil
}
guard let graph = graphIfPresent, self.validateBuildRecord(graph.buildRecord) != nil else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ extension ModuleDependencyGraph {
for invalidatedInput in collectInputsUsingInvalidated(nodes: directlyInvalidatedNodes) {
guard info.isPartOfBuild(invalidatedInput)
else {
info.diagnosticEngine.emit(.warning("Failed to find source file '\(invalidatedInput.typedFile.file.basename)' in command line, recovering with a full rebuild. Next build will be incremental."),
location: nil)
info.diagnosticEngine.emit(
warning: "Failed to find source file '\(invalidatedInput.typedFile.file.basename)' in command line, recovering with a full rebuild. Next build will be incremental.")
return nil
}
invalidatedInputs.insert(invalidatedInput)
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import class TSCBasic.LocalFileOutputByteStream
import class TSCBasic.TerminalController
import struct TSCBasic.RelativePath
import var TSCBasic.stderrStream
import enum TSCUtility.Diagnostics

/// Whether we should produce color diagnostics by default.
fileprivate func shouldColorDiagnostics() -> Bool {
Expand Down Expand Up @@ -473,7 +474,7 @@ extension Driver {
if parsedOptions.hasArgument(.updateCode) {
guard compilerMode == .standardCompile else {
diagnosticEngine.emit(.error_update_code_not_supported(in: compilerMode))
throw ErrorDiagnostics.emitted
throw Diagnostics.fatalError
}
assert(primaryInputs.count == 1, "Standard compile job had more than one primary input")
let input = primaryInputs[0]
Expand Down
14 changes: 5 additions & 9 deletions Sources/SwiftDriver/Jobs/PrebuiltModulesJob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ public struct SDKPrebuiltModuleInputsCollector {
return map.filter {
// Remove modules without associated .swiftinterface files and diagnose.
if $0.value.isEmpty {
diagEngine.emit(.warning("\($0.key) has no associated .swiftinterface files"),
location: nil)
diagEngine.emit(warning: "\($0.key) has no associated .swiftinterface files")
return false
}
return true
Expand Down Expand Up @@ -458,7 +457,7 @@ public struct SDKPrebuiltModuleInputsCollector {
hasInterface.append(currentFile)
}
if currentFile.extension == "swiftmodule" {
diagEngine.emit(.warning("found \(currentFile)"), location: nil)
diagEngine.emit(warning: "found \(currentFile)")
hasModule.append(currentFile)
}
}
Expand Down Expand Up @@ -722,8 +721,7 @@ extension Driver {
var results: [TypedVirtualPath] = []
modules.forEach { module in
guard let allOutputs = outputMap[module] else {
diagnosticEngine.emit(.error("cannot find output paths for \(module)"),
location: nil)
diagnosticEngine.emit(error: "cannot find output paths for \(module)")
return
}
let allPaths = allOutputs.filter { output in
Expand Down Expand Up @@ -774,8 +772,7 @@ extension Driver {
// contain this dependency.
dependencies.forEach({ newModule in
if !openModules.contains(newModule) {
diagnosticEngine.emit(.note("\(newModule) is discovered."),
location: nil)
diagnosticEngine.emit(note: "\(newModule) is discovered.")
openModules.append(newModule)
}
})
Expand All @@ -795,8 +792,7 @@ extension Driver {
// of mac native so those macabi-only modules cannot be found by the scanner.
// We have to handle those modules separately without any dependency info.
try unhandledModules.forEach { moduleName in
diagnosticEngine.emit(.warning("handle \(moduleName) has dangling jobs"),
location: nil)
diagnosticEngine.emit(warning: "handle \(moduleName) has dangling jobs")
try forEachInputOutputPair(moduleName) { input, output in
danglingJobs.append(contentsOf: try generateSingleModuleBuildingJob(moduleName,
prebuiltModuleDir, input, output, [], currentABIDir, baselineABIDir))
Expand Down
10 changes: 4 additions & 6 deletions Sources/swift-driver/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import class TSCBasic.Process
import class TSCBasic.ProcessSet
import protocol TSCBasic.DiagnosticData
import var TSCBasic.localFileSystem
import enum TSCUtility.Diagnostics

let interruptSignalSource = DispatchSource.makeSignalSource(signal: SIGINT)
let diagnosticsEngine = DiagnosticsEngine(handlers: [Driver.stderrDiagnosticsHandler])
Expand Down Expand Up @@ -99,23 +100,20 @@ do {

// FIXME: The following check should be at the end of Driver.init, but current
// usage of the DiagnosticVerifier in tests makes this difficult.
guard !driver.diagnosticEngine.hasErrors else {
throw Driver.ErrorDiagnostics.emitted
}
guard !driver.diagnosticEngine.hasErrors else { throw Diagnostics.fatalError }

let jobs = try driver.planBuild()
try driver.run(jobs: jobs)

if driver.diagnosticEngine.hasErrors {
exit(getExitCode(EXIT_FAILURE))
}

exit(getExitCode(0))
} catch Diagnostics.fatalError {
exit(getExitCode(EXIT_FAILURE))
} catch let diagnosticData as DiagnosticData {
diagnosticsEngine.emit(.error(diagnosticData))
exit(getExitCode(EXIT_FAILURE))
} catch Driver.ErrorDiagnostics.emitted {
exit(getExitCode(EXIT_FAILURE))
} catch {
print("error: \(error)")
exit(getExitCode(EXIT_FAILURE))
Expand Down