@@ -14,28 +14,28 @@ NSSetUncaughtExceptionHandler(handler)
14
14
func runShellCommand( command: String ) -> String ? {
15
15
let args : [ String ] = command. characters. split { $0 == " " } . map ( String . init)
16
16
let other = args [ 1 ..< args. count]
17
- let outputPipe = NSPipe ( )
18
- let task = NSTask ( )
17
+ let outputPipe = Pipe ( )
18
+ let task = Process ( )
19
19
task. launchPath = args [ 0 ]
20
20
task. arguments = other. map { $0 }
21
21
task. standardOutput = outputPipe
22
22
task. launch ( )
23
23
task. waitUntilExit ( )
24
24
25
25
guard task. terminationStatus == 0 else { return nil }
26
-
26
+
27
27
let outputData = outputPipe. fileHandleForReading. readDataToEndOfFile ( )
28
- return String ( data: outputData, encoding: NSUTF8StringEncoding )
28
+ return String ( data: outputData, encoding: String . Encoding . utf8 )
29
29
}
30
30
31
31
// MARK: - File System Utilities
32
32
func fileExists( filePath: String ) -> Bool {
33
- return NSFileManager . defaultManager ( ) . fileExistsAtPath ( filePath)
33
+ return FileManager . default . fileExists ( atPath : filePath)
34
34
}
35
35
36
36
func mkdir( path: String ) -> Bool {
37
37
do {
38
- try NSFileManager . defaultManager ( ) . createDirectoryAtPath ( path, withIntermediateDirectories: true , attributes: nil )
38
+ try FileManager . default . createDirectory ( atPath : path, withIntermediateDirectories: true , attributes: nil )
39
39
return true
40
40
}
41
41
catch {
@@ -44,38 +44,38 @@ func mkdir(path: String) -> Bool {
44
44
}
45
45
46
46
// 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 )
49
49
}
50
50
51
- func trim( s: String ? ) -> String ? {
51
+ func trim( _ s: String ? ) -> String ? {
52
52
return ( s == nil ) ? nil : ( trim ( s!) as String )
53
53
}
54
54
55
- @ noreturn func reportError( message: String ) {
55
+ func reportError( message: String ) -> Never {
56
56
print ( " ERROR: \( message) " )
57
57
exit ( 1 )
58
58
}
59
59
60
60
// MARK: GenerateCommonCryptoModule
61
61
enum SDK : String {
62
62
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 "
69
69
static let all = [ iOS, iOSSimulator, watchOS, watchSimulator, tvOS, tvOSSimulator, MacOSX]
70
70
71
71
}
72
72
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) " )
76
76
}
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) " )
79
79
}
80
80
81
81
if verbose {
@@ -86,41 +86,41 @@ if verbose {
86
86
87
87
let moduleDirectory : String
88
88
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 "
91
91
moduleFileName = " module.map "
92
92
}
93
93
else {
94
94
moduleDirectory = " \( sdkPath) /System/Library/Frameworks/CommonCrypto.framework "
95
95
moduleFileName = " module.map "
96
96
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) . " )
99
99
}
100
100
}
101
101
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) " )
104
104
}
105
105
106
106
let headerDir = " \( sdkPath) /usr/include/CommonCrypto/ "
107
107
let headerFile1 = " \( headerDir) /CommonCrypto.h "
108
108
let headerFile2 = " \( headerDir) /CommonRandom.h "
109
109
110
110
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 " +
115
115
" } \n "
116
116
117
117
let moduleMapPath = " \( moduleDirectory) / \( moduleFileName) "
118
118
do {
119
- try moduleMapFile. writeToFile ( moduleMapPath, atomically: true , encoding: NSUTF8StringEncoding )
119
+ try moduleMapFile. write ( toFile : moduleMapPath, atomically: true , encoding: String . Encoding . utf8 )
120
120
print ( " Successfully created module \( moduleMapPath) " )
121
121
exit ( 0 )
122
122
}
123
123
catch {
124
- reportError ( " Failed to write module map file to \( moduleMapPath) " )
124
+ reportError ( message : " Failed to write module map file to \( moduleMapPath) " )
125
125
}
126
126
0 commit comments