Skip to content

SR-12129: Diagnose lack of input files #72

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
Mar 3, 2020
Merged
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
28 changes: 25 additions & 3 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,28 @@ public enum ModuleOutput: Equatable {

/// The Swift driver.
public struct Driver {
enum Error: Swift.Error {
public enum Error: Swift.Error, DiagnosticData {
case invalidDriverName(String)
case invalidInput(String)
case subcommandPassedToDriver
case noJobsPassedToDriverFromEmptyInputFileList
case relativeFrontendPath(String)
case subcommandPassedToDriver

public var description: String {
switch self {
case .invalidDriverName(let driverName):
return "invalid driver name: \(driverName)"
case .invalidInput(let input):
return "invalid input: \(input)"
case .noJobsPassedToDriverFromEmptyInputFileList:
return "no input files"
case .relativeFrontendPath(let path):
// TODO: where is this error thrown
return "relative frontend path: \(path)"
case .subcommandPassedToDriver:
return "subcommand passed to driver"
}
}
}

/// The set of environment variables that are visible to the driver and
Expand Down Expand Up @@ -604,7 +621,12 @@ extension Driver {
try printVersion(outputStream: &stderrStream)
}

if jobs.isEmpty { return }
guard !jobs.isEmpty else {
guard !inputFiles.isEmpty else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check this before trying to plan a build. It can probably go into Planning.swift's Driver.planBuild(), so long as the driver isn't creating a REPL or immediate forwarding job (which don't require inputs).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we'd have to move optionTable.printHelp() and printVersion() out of Driver.run() as well, correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would. Help is handled by this: #66

Version is a bit more interesting, there is technically 3 version flags. -v, --version, and -version. -version and --version are treated the same, they print the version information and ignore everything else (Actually help takes higher precedence over version in the c++ compiler, which isn't the case in #66 @owenv). Now -v prints the version information, but then continues on, with the only difference being that it suppresses the no input files error. You can see that here: https://github.com/apple/swift/blob/master/lib/Driver/Driver.cpp#L2157. We can mimic that logic by adding a shouldSuppressNoInputFilesError Bool that gets set to the value of parsedOptions.hasArgument(.v).

So currently --version and -version are handled in planBuild, so -v should be too, but it needs to be treated differently, not as a immediateForwardingJob.

Here are some examples from the c++ driver, that I think show all the cases I mentioned above.

colton-mac:~ colton$ swiftc -typecheck
<unknown>:0: error: no input files
colton-mac:~ colton$ swiftc --version
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin18.7.0
colton-mac:~ colton$ swiftc --version -typecheck
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin18.7.0
colton-mac:~ colton$ swiftc -v -typecheck
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin18.7.0
colton-mac:~ colton$ swiftc -v
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin18.7.0
colton-mac:~ colton$ swift -version
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin18.7.0
colton-mac:~ colton$ swift -v
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Target: x86_64-apple-darwin18.7.0
/Applications/Xcode.app/Contents/Developer/usr/bin/lldb "--repl=-enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics"
Welcome to Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15).
Type :help for assistance.
  1> :q
colton-mac:~ colton$ 

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, sorry for the confusion, I forgot we hadn't come up with a good solution for -v yet, this is fine to leave as-is.

throw Error.noJobsPassedToDriverFromEmptyInputFileList
}
return
}

let forceResponseFiles = parsedOptions.contains(.driverForceResponseFiles)

Expand Down