Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Collect all commandline argument errors, and show them at once
  • Loading branch information
tomlokhorst committed Dec 12, 2018
commit 9e177011d9d989844b4594d32bfa0782e2070f1d
10 changes: 5 additions & 5 deletions Sources/RswiftCore/CallInformation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public struct CallInformation {
let scriptOutputFiles: [String]
let lastRunURL: URL

private let buildProductsDirURL: URL
private let developerDirURL: URL
private let sourceRootURL: URL
private let sdkRootURL: URL
private let platformURL: URL
let buildProductsDirURL: URL
let developerDirURL: URL
let sourceRootURL: URL
let sdkRootURL: URL
let platformURL: URL

public init(
outputURL: URL,
Expand Down
59 changes: 49 additions & 10 deletions Sources/RswiftCore/RswiftCore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@ import XcodeEdit
public struct RswiftCore {

static public func run(_ callInformation: CallInformation) throws {
guard callInformation.scriptInputFiles.contains(callInformation.lastRunURL.path) else {
fail("Missing '$(TEMP_DIR)/\(callInformation.lastRunURL.lastPathComponent)' from Input Files. See upgrading to R.swift 5.0: http://bit.ly/2PsO9IF")
exit(EXIT_FAILURE)
}
let errors = callInformation.inputOutputFilesErrors()

guard callInformation.outputURL.pathExtension == "swift" else {
fail("Output path must be a specific Swift file, folders are not allowed anymore. See upgrading to R.swift 5.0: http://bit.ly/2PsO9IF")
exit(EXIT_FAILURE)
}
guard errors.isEmpty else {
for error in errors {
fail(error)
}

warn("For updating to R.swift 5.0, read our migration guide: https://github.com/mac-cain13/R.swift/blob/master/Documentation/Migration.md")

guard callInformation.scriptOutputFiles.contains(callInformation.outputURL.path) else {
fail("Build phase output files do not contain '\(callInformation.outputURL.path)'. See upgrading to R.swift 5.0: http://bit.ly/2PsO9IF")
exit(EXIT_FAILURE)
}

Expand Down Expand Up @@ -99,3 +96,45 @@ public struct RswiftCore {
}
}
}

extension CallInformation {
func inputOutputFilesErrors() -> [String] {
var errors: [String] = []
var outputIsDirectory = false

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) {
let prettyPath = outputURL.path.replacingOccurrences(of: sourceRootURL.path, with: "$SRCROOT")
error += " Example: rswift generate \(prettyPath)/R.generated.swift"
}

errors.append(error)
}

if !scriptInputFiles.contains(lastRunURL.path) {
errors.append("Build phase Intput Files does not contain '$TEMP_DIR/\(lastRunURL.lastPathComponent)'.")
}

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

return errors
}
}

extension FileManager {
func directoryExists(atPath path: String) -> Bool {
var isDir: ObjCBool = false
let exists = fileExists(atPath: path, isDirectory: &isDir)

return exists && isDir.boolValue
}
}