Skip to content

Commit 1dd130d

Browse files
committed
Merge branch 'JonB-master'
2 parents af20cf9 + 768c933 commit 1dd130d

File tree

15 files changed

+563
-605
lines changed

15 files changed

+563
-605
lines changed

GenerateCommonCryptoModule.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ NSSetUncaughtExceptionHandler(handler)
1414
func runShellCommand(command: String) -> String? {
1515
let args: [String] = command.characters.split { $0 == " " }.map(String.init)
1616
let other = args[1..<args.count]
17-
let outputPipe = NSPipe()
18-
let task = NSTask()
17+
let outputPipe = Pipe()
18+
let task = Process()
1919
task.launchPath = args[0]
2020
task.arguments = other.map { $0 }
2121
task.standardOutput = outputPipe
2222
task.launch()
2323
task.waitUntilExit()
2424

2525
guard task.terminationStatus == 0 else { return nil }
26-
26+
2727
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
28-
return String(data:outputData, encoding: NSUTF8StringEncoding)
28+
return String(data:outputData, encoding: String.Encoding.utf8)
2929
}
3030

3131
// MARK: - File System Utilities
3232
func fileExists(filePath: String) -> Bool {
33-
return NSFileManager.defaultManager().fileExistsAtPath(filePath)
33+
return FileManager.default.fileExists(atPath: filePath)
3434
}
3535

3636
func mkdir(path: String) -> Bool {
3737
do {
38-
try NSFileManager.defaultManager().createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil)
38+
try FileManager.default.createDirectory(atPath: path, withIntermediateDirectories: true, attributes: nil)
3939
return true
4040
}
4141
catch {
@@ -44,38 +44,38 @@ func mkdir(path: String) -> Bool {
4444
}
4545

4646
// MARK: - String Utilities
47-
func trim(s: String) -> String {
48-
return ((s as NSString).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) as String)
47+
func trim(_ s: String) -> String {
48+
return ((s as NSString).trimmingCharacters(in: NSCharacterSet.whitespacesAndNewlines) as String)
4949
}
5050

51-
func trim(s: String?) -> String? {
51+
func trim(_ s: String?) -> String? {
5252
return (s == nil) ? nil : (trim(s!) as String)
5353
}
5454

55-
@noreturn func reportError(message: String) {
55+
func reportError(message: String) -> Never {
5656
print("ERROR: \(message)")
5757
exit(1)
5858
}
5959

6060
// MARK: GenerateCommonCryptoModule
6161
enum SDK: String {
6262
case iOS = "iphoneos",
63-
iOSSimulator = "iphonesimulator",
64-
watchOS = "watchos",
65-
watchSimulator = "watchsimulator",
66-
tvOS = "appletvos",
67-
tvOSSimulator = "appletvsimulator",
68-
MacOSX = "macosx"
63+
iOSSimulator = "iphonesimulator",
64+
watchOS = "watchos",
65+
watchSimulator = "watchsimulator",
66+
tvOS = "appletvos",
67+
tvOSSimulator = "appletvsimulator",
68+
MacOSX = "macosx"
6969
static let all = [iOS, iOSSimulator, watchOS, watchSimulator, tvOS, tvOSSimulator, MacOSX]
7070

7171
}
7272

73-
guard let sdk = SDK(rawValue: Process.arguments[1])?.rawValue else { reportError("SDK must be one of \(SDK.all.map { $0.rawValue })") }
74-
guard let sdkVersion = trim(runShellCommand("/usr/bin/xcrun --sdk \(sdk) --show-sdk-version")) else {
75-
reportError("ERROR: Failed to determine SDK version for \(sdk)")
73+
guard let sdk = SDK(rawValue: CommandLine.arguments[1])?.rawValue else { reportError(message: "SDK must be one of \(SDK.all.map { $0.rawValue })") }
74+
guard let sdkVersion = trim(runShellCommand(command: "/usr/bin/xcrun --sdk \(sdk) --show-sdk-version")) else {
75+
reportError(message: "ERROR: Failed to determine SDK version for \(sdk)")
7676
}
77-
guard let sdkPath = trim(runShellCommand("/usr/bin/xcrun --sdk \(sdk) --show-sdk-path")) else {
78-
reportError("ERROR: Failed to determine SDK path for \(sdk)")
77+
guard let sdkPath = trim(runShellCommand(command: "/usr/bin/xcrun --sdk \(sdk) --show-sdk-path")) else {
78+
reportError(message: "ERROR: Failed to determine SDK path for \(sdk)")
7979
}
8080

8181
if verbose {
@@ -86,41 +86,41 @@ if verbose {
8686

8787
let moduleDirectory: String
8888
let moduleFileName: String
89-
if Process.arguments.count > 2 {
90-
moduleDirectory = "\(Process.arguments[2])/Frameworks/\(sdk)/CommonCrypto.framework"
89+
if CommandLine.arguments.count > 2 {
90+
moduleDirectory = "\(CommandLine.arguments[2])/Frameworks/\(sdk)/CommonCrypto.framework"
9191
moduleFileName = "module.map"
9292
}
9393
else {
9494
moduleDirectory = "\(sdkPath)/System/Library/Frameworks/CommonCrypto.framework"
9595
moduleFileName = "module.map"
9696

97-
if fileExists(moduleDirectory) {
98-
reportError("Module directory already exists at \(moduleDirectory).")
97+
if fileExists(filePath: moduleDirectory) {
98+
reportError(message: "Module directory already exists at \(moduleDirectory).")
9999
}
100100
}
101101

102-
if !mkdir(moduleDirectory) {
103-
reportError("Failed to create module directory \(moduleDirectory)")
102+
if !mkdir(path: moduleDirectory) {
103+
reportError(message: "Failed to create module directory \(moduleDirectory)")
104104
}
105105

106106
let headerDir = "\(sdkPath)/usr/include/CommonCrypto/"
107107
let headerFile1 = "\(headerDir)/CommonCrypto.h"
108108
let headerFile2 = "\(headerDir)/CommonRandom.h"
109109

110110
let moduleMapFile =
111-
"module CommonCrypto [system] {\n" +
112-
" header \"\(headerFile1)\"\n" +
113-
" header \"\(headerFile2)\"\n" +
114-
" export *\n" +
111+
"module CommonCrypto [system] {\n" +
112+
" header \"\(headerFile1)\"\n" +
113+
" header \"\(headerFile2)\"\n" +
114+
" export *\n" +
115115
"}\n"
116116

117117
let moduleMapPath = "\(moduleDirectory)/\(moduleFileName)"
118118
do {
119-
try moduleMapFile.writeToFile(moduleMapPath, atomically: true, encoding:NSUTF8StringEncoding)
119+
try moduleMapFile.write(toFile: moduleMapPath, atomically: true, encoding:String.Encoding.utf8)
120120
print("Successfully created module \(moduleMapPath)")
121121
exit(0)
122122
}
123123
catch {
124-
reportError("Failed to write module map file to \(moduleMapPath)")
124+
reportError(message: "Failed to write module map file to \(moduleMapPath)")
125125
}
126126

0 commit comments

Comments
 (0)