Skip to content

Commit 3bafae9

Browse files
committed
Merge pull request #12 from iosdevzone/0.7.0-development
0.7.0 -- Adds support for OS X, tvOS, and watchOS
2 parents 086888a + bd7f6d4 commit 3bafae9

34 files changed

+1256
-280
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ prepate_command.txt
22
CommonCrypto
33
# Xcode
44
#
5+
Frameworks/
56
build/
67
*.pbxuser
78
!default.pbxuser

DemoPlayground.playground/contents.xcplayground

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<playground version='3.0' sdk='iphonesimulator' runInFullSimulator='YES'>
2+
<playground version='3.0' sdk='macosx'>
33
<sections>
44
<code source-file-name='section-1.swift'/>
55
</sections>

DemoPlayground.playground/section-1.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

2-
import UIKit
2+
import Foundation
3+
//
4+
// If you get an error on the line below you need to run:
5+
// sudo xcrun -sdk macosx swift GenerateCommonCryptoModule.swift macosx
6+
//
37
import CommonCrypto
48
import IDZSwiftCommonCrypto
59

GenerateCommonCryptoModule.swift

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import Foundation
2+
3+
let verbose = true
4+
5+
// MARK: - Exception Handling
6+
let handler: @convention(c) (NSException) -> Void = {
7+
exception in
8+
print("FATAL EXCEPTION: \(exception)")
9+
exit(1)
10+
}
11+
NSSetUncaughtExceptionHandler(handler)
12+
13+
// MARK: - Task Utilities
14+
func runShellCommand(command: String) -> String? {
15+
let args: [String] = command.characters.split { $0 == " " }.map(String.init)
16+
let other = args[1..<args.count]
17+
let outputPipe = NSPipe()
18+
let task = NSTask()
19+
task.launchPath = args[0]
20+
task.arguments = other.map { $0 }
21+
task.standardOutput = outputPipe
22+
task.launch()
23+
task.waitUntilExit()
24+
25+
guard task.terminationStatus == 0 else { return nil }
26+
27+
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
28+
return String(data:outputData, encoding: NSUTF8StringEncoding)
29+
}
30+
31+
// MARK: - File System Utilities
32+
func fileExists(filePath: String) -> Bool {
33+
return NSFileManager.defaultManager().fileExistsAtPath(filePath)
34+
}
35+
36+
func mkdir(path: String) -> Bool {
37+
do {
38+
try NSFileManager.defaultManager().createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil)
39+
return true
40+
}
41+
catch {
42+
return false
43+
}
44+
}
45+
46+
// MARK: - String Utilities
47+
func trim(s: String) -> String {
48+
return ((s as NSString).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) as String)
49+
}
50+
51+
func trim(s: String?) -> String? {
52+
return (s == nil) ? nil : (trim(s!) as String)
53+
}
54+
55+
@noreturn func reportError(message: String) {
56+
print("ERROR: \(message)")
57+
exit(1)
58+
}
59+
60+
// MARK: GenerateCommonCryptoModule
61+
enum SDK: String {
62+
case iOS = "iphoneos",
63+
iOSSimulator = "iphonesimulator",
64+
watchOS = "watchos",
65+
watchSimulator = "watchsimulator",
66+
tvOS = "appletvos",
67+
tvOSSimulator = "appletvsimulator",
68+
MacOSX = "macosx"
69+
static let all = [iOS, iOSSimulator, watchOS, watchSimulator, tvOS, tvOSSimulator, MacOSX]
70+
71+
}
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)")
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)")
79+
}
80+
81+
if verbose {
82+
print("SDK: \(sdk)")
83+
print("SDK Version: \(sdkVersion)")
84+
print("SDK Path: \(sdkPath)")
85+
}
86+
87+
let moduleDirectory: String
88+
let moduleFileName: String
89+
if Process.arguments.count > 2 {
90+
moduleDirectory = "\(Process.arguments[2])/Frameworks/\(sdk)/CommonCrypto.framework"
91+
moduleFileName = "module.map"
92+
}
93+
else {
94+
moduleDirectory = "\(sdkPath)/System/Library/Frameworks/CommonCrypto.framework"
95+
moduleFileName = "module.map"
96+
97+
if fileExists(moduleDirectory) {
98+
reportError("Module directory already exists at \(moduleDirectory).")
99+
}
100+
}
101+
102+
if !mkdir(moduleDirectory) {
103+
reportError("Failed to create module directory \(moduleDirectory)")
104+
}
105+
106+
let headerDir = "\(sdkPath)/usr/include/CommonCrypto/"
107+
let headerFile1 = "\(headerDir)/CommonCrypto.h"
108+
let headerFile2 = "\(headerDir)/CommonRandom.h"
109+
110+
let moduleMapFile =
111+
"module CommonCrypto [system] {\n" +
112+
" header \"\(headerFile1)\"\n" +
113+
" header \"\(headerFile2)\"\n" +
114+
" export *\n" +
115+
"}\n"
116+
117+
let moduleMapPath = "\(moduleDirectory)/\(moduleFileName)"
118+
do {
119+
try moduleMapFile.writeToFile(moduleMapPath, atomically: true, encoding:NSUTF8StringEncoding)
120+
print("Successfully created module \(moduleMapPath)")
121+
exit(0)
122+
}
123+
catch {
124+
reportError("Failed to write module map file to \(moduleMapPath)")
125+
}
126+

IDZSwiftCommonCrypto.podspec

Lines changed: 24 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,48 @@
1-
#
2-
# Be sure to run `pod spec lint IDZSwiftCommonCrypto.podspec' to ensure this is a
3-
# valid spec and to remove all comments including this before submitting the spec.
4-
#
5-
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
6-
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7-
#
8-
91
Pod::Spec.new do |s|
102

11-
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
12-
#
13-
# These will help people to find your library, and whilst it
14-
# can feel like a chore to fill in it's definitely to your advantage. The
15-
# summary should be tweet-length, and the description more in depth.
16-
#
17-
183
s.name = "IDZSwiftCommonCrypto"
19-
s.version = "0.6.8"
4+
s.version = "0.7.0"
205
s.summary = "A wrapper for Apple's Common Crypto library written in Swift."
216

227
s.homepage = "https://github.com/iosdevzone/IDZSwiftCommonCrypto"
23-
24-
25-
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
26-
#
27-
# Licensing your code is important. See http://choosealicense.com for more info.
28-
# CocoaPods will detect a license file if there is a named LICENSE*
29-
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
30-
#
31-
328
s.license = "MIT"
33-
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
34-
35-
36-
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
37-
#
38-
# Specify the authors of the library, with email addresses. Email addresses
39-
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
40-
# accepts just a name if you'd rather not provide an email address.
41-
#
42-
# Specify a social_media_url where others can refer to, for example a twitter
43-
# profile URL.
44-
#
45-
469
s.author = { "iOSDevZone" => "[email protected]" }
4710
s.social_media_url = "http://twitter.com/iOSDevZone"
48-
s.platform = :ios, "8.0"
49-
#
50-
# Specify the location from where the source should be retrieved.
51-
# Supports git, hg, bzr, svn and HTTP.
52-
#
11+
12+
s.osx.deployment_target = '10.10'
13+
s.ios.deployment_target = '8.0'
14+
s.tvos.deployment_target = '9.0'
15+
s.watchos.deployment_target = '2.0'
5316

5417
s.source = { :git => "https://github.com/iosdevzone/IDZSwiftCommonCrypto.git", :tag => s.version.to_s }
5518

56-
57-
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
5819
#
59-
# CocoaPods is smart about how it includes source code. For source files
60-
# giving a folder will include any swift, h, m, mm, c & cpp files.
61-
# For header files it will include any header in the folder.
62-
# Not including the public_header_files will make all headers public.
20+
# Create the dummy CommonCrypto.framework structures
6321
#
6422
s.prepare_command = <<-CMD
65-
6623
touch prepare_command.txt
6724
echo 'Running prepare_command'
68-
if [ ! -e CommonCrypto ]; then
69-
pwd
70-
echo Running GenerateCommonCryptoModule
71-
./GenerateCommonCryptoModule iphonesimulator .
72-
else
73-
echo Skipped GenerateCommonCryptoModule
74-
fi
25+
pwd
26+
echo Running GenerateCommonCryptoModule
27+
swift ./GenerateCommonCryptoModule.swift macosx .
28+
swift ./GenerateCommonCryptoModule.swift iphonesimulator .
29+
swift ./GenerateCommonCryptoModule.swift iphoneos .
30+
swift ./GenerateCommonCryptoModule.swift appletvsimulator .
31+
swift ./GenerateCommonCryptoModule.swift appletvos .
32+
swift ./GenerateCommonCryptoModule.swift watchsimulator .
33+
swift ./GenerateCommonCryptoModule.swift watchos .
7534
7635
CMD
77-
s.source_files = "IDZSwiftCommonCrypto"
78-
79-
# s.public_header_files = "Classes/**/*.h"
80-
81-
82-
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
83-
#
84-
# A list of resources included with the Pod. These are copied into the
85-
# target bundle with a build phase script. Anything else will be cleaned.
86-
# You can preserve files from being cleaned, please don't preserve
87-
# non-essential files like tests, examples and documentation.
88-
#
89-
90-
# s.resource = "icon.png"
91-
# s.resources = "Resources/*.png"
92-
93-
s.preserve_paths = "CommonCrypto"
94-
9536

96-
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
97-
#
98-
# Link your library with frameworks, or libraries. Libraries do not include
99-
# the lib prefix of their name.
100-
#
101-
102-
# s.framework = "SomeFramework"
103-
# s.frameworks = "SomeFramework", "AnotherFramework"
104-
105-
# s.library = "iconv"
106-
# s.libraries = "iconv", "xml2"
107-
108-
109-
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
110-
#
111-
# If your library depends on compiler flags you can set them in the xcconfig hash
112-
# where they will only apply to your library. If you depend on other Podspecs
113-
# you can include multiple dependencies to ensure it works.
37+
s.source_files = "IDZSwiftCommonCrypto"
11438

115-
# s.requires_arc = true
39+
# Stop CocoaPods from deleting dummy frameworks
40+
s.preserve_paths = "Frameworks"
11641

117-
s.xcconfig = { "SWIFT_INCLUDE_PATHS" => "$(PROJECT_DIR)/IDZSwiftCommonCrypto" }
118-
# s.dependency "JSONKit", "~> 1.4"
42+
# Make sure we can find the dummy frameworks
43+
s.xcconfig = {
44+
"SWIFT_INCLUDE_PATHS" => "$(PROJECT_DIR)/IDZSwiftCommonCrypto/Frameworks/$(PLATFORM_NAME)",
45+
"FRAMEWORK_SEARCH_PATHS" => "$(PROJECT_DIR)/IDZSwiftCommonCrypto/Frameworks/$(PLATFORM_NAME)"
46+
}
11947

12048
end

0 commit comments

Comments
 (0)