Skip to content

Commit

Permalink
Improved errors (mac-cain13#470)
Browse files Browse the repository at this point in the history
* Collect all commandline argument errors, and show them at once

* Only touch file when running generate command. To prevent warnings when using --help or --version

* Move Rswift environment validation to separate file

* Cleanup
  • Loading branch information
tomlokhorst authored and mac-cain13 committed Dec 13, 2018
1 parent 66ef687 commit 5c2c54f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Sources/RswiftCore/EnvironmentValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ public func validateRswiftEnvironment(
commandLineArguments: [String]) -> [String]
{
var errors: [String] = []
var outputIsDirectory = false
var outputFileForError = outputURL.path

if outputURL.pathExtension != "swift" {
outputIsDirectory = true

var error = "Output path must specify a file, it should not be a directory."
if FileManager.default.directoryExists(atPath: outputURL.path) {
Expand All @@ -30,7 +29,10 @@ public func validateRswiftEnvironment(
.map { $0.replacingOccurrences(of: outputURL.path, with: rswiftGeneratedFile) }
.map { $0.replacingOccurrences(of: sourceRootPath, with: "$SRCROOT") }
.map { $0.contains(" ") ? "\"\($0)\"" : $0 }

error += "\nExample: " + commandParts.joined(separator: " ")

outputFileForError = rswiftGeneratedFile
}

errors.append(error)
Expand All @@ -41,11 +43,8 @@ public func validateRswiftEnvironment(
}

if !scriptOutputFiles.contains(outputURL.path) {
var prettyPath = outputURL.path.replacingOccurrences(of: sourceRootPath, with: "$SRCROOT")
if outputIsDirectory {
prettyPath += "/R.generated.swift"
}
errors.append("Build phase Output Files do not contain '\(prettyPath)'.")
let path = outputFileForError.replacingOccurrences(of: sourceRootPath, with: "$SRCROOT")
errors.append("Build phase Output Files do not contain '\(path)'.")
}

return errors
Expand Down

0 comments on commit 5c2c54f

Please sign in to comment.