forked from mac-cain13/R.swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved errors for R.swift 5 (mac-cain13#469)
* 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
- Loading branch information
1 parent
a4bf31e
commit 66ef687
Showing
5 changed files
with
95 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// EnvironmentValidation.swift | ||
// Commander | ||
// | ||
// Created by Tom Lokhorst on 2018-12-12. | ||
// | ||
|
||
import Foundation | ||
|
||
public func validateRswiftEnvironment( | ||
outputURL: URL, | ||
sourceRootPath: String, | ||
scriptInputFiles: [String], | ||
scriptOutputFiles: [String], | ||
lastRunURL: URL, | ||
podsRoot: String?, | ||
commandLineArguments: [String]) -> [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 rswiftGeneratedFile = outputURL.appendingPathComponent("R.generated.swift").path | ||
let commandParts = commandLineArguments | ||
.map { $0.replacingOccurrences(of: podsRoot ?? "", with: "$PODS_ROOT") } | ||
.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: " ") | ||
} | ||
|
||
errors.append(error) | ||
} | ||
|
||
if !scriptInputFiles.contains(lastRunURL.path) { | ||
errors.append("Build phase Intput Files does not contain '$TEMP_DIR/\(lastRunURL.lastPathComponent)'.") | ||
} | ||
|
||
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)'.") | ||
} | ||
|
||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters