Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ prepate_command.txt
CommonCrypto
# Xcode
#
Frameworks/
build/
*.pbxuser
!default.pbxuser
Expand Down
2 changes: 1 addition & 1 deletion DemoPlayground.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='3.0' sdk='iphonesimulator' runInFullSimulator='YES'>
<playground version='3.0' sdk='macosx'>
<sections>
<code source-file-name='section-1.swift'/>
</sections>
Expand Down
6 changes: 5 additions & 1 deletion DemoPlayground.playground/section-1.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

import UIKit
import Foundation
//
// If you get an error on the line below you need to run:
// sudo xcrun -sdk macosx swift GenerateCommonCryptoModule.swift macosx
//
import CommonCrypto
import IDZSwiftCommonCrypto

Expand Down
126 changes: 126 additions & 0 deletions GenerateCommonCryptoModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import Foundation

let verbose = true

// MARK: - Exception Handling
let handler: @convention(c) (NSException) -> Void = {
exception in
print("FATAL EXCEPTION: \(exception)")
exit(1)
}
NSSetUncaughtExceptionHandler(handler)

// MARK: - Task Utilities
func runShellCommand(command: String) -> String? {
let args: [String] = command.characters.split { $0 == " " }.map(String.init)
let other = args[1..<args.count]
let outputPipe = NSPipe()
let task = NSTask()
task.launchPath = args[0]
task.arguments = other.map { $0 }
task.standardOutput = outputPipe
task.launch()
task.waitUntilExit()

guard task.terminationStatus == 0 else { return nil }

let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
return String(data:outputData, encoding: NSUTF8StringEncoding)
}

// MARK: - File System Utilities
func fileExists(filePath: String) -> Bool {
return NSFileManager.defaultManager().fileExistsAtPath(filePath)
}

func mkdir(path: String) -> Bool {
do {
try NSFileManager.defaultManager().createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil)
return true
}
catch {
return false
}
}

// MARK: - String Utilities
func trim(s: String) -> String {
return ((s as NSString).stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) as String)
}

func trim(s: String?) -> String? {
return (s == nil) ? nil : (trim(s!) as String)
}

@noreturn func reportError(message: String) {
print("ERROR: \(message)")
exit(1)
}

// MARK: GenerateCommonCryptoModule
enum SDK: String {
case iOS = "iphoneos",
iOSSimulator = "iphonesimulator",
watchOS = "watchos",
watchSimulator = "watchsimulator",
tvOS = "appletvos",
tvOSSimulator = "appletvsimulator",
MacOSX = "macosx"
static let all = [iOS, iOSSimulator, watchOS, watchSimulator, tvOS, tvOSSimulator, MacOSX]

}

guard let sdk = SDK(rawValue: Process.arguments[1])?.rawValue else { reportError("SDK must be one of \(SDK.all.map { $0.rawValue })") }
guard let sdkVersion = trim(runShellCommand("/usr/bin/xcrun --sdk \(sdk) --show-sdk-version")) else {
reportError("ERROR: Failed to determine SDK version for \(sdk)")
}
guard let sdkPath = trim(runShellCommand("/usr/bin/xcrun --sdk \(sdk) --show-sdk-path")) else {
reportError("ERROR: Failed to determine SDK path for \(sdk)")
}

if verbose {
print("SDK: \(sdk)")
print("SDK Version: \(sdkVersion)")
print("SDK Path: \(sdkPath)")
}

let moduleDirectory: String
let moduleFileName: String
if Process.arguments.count > 2 {
moduleDirectory = "\(Process.arguments[2])/Frameworks/\(sdk)/CommonCrypto.framework"
moduleFileName = "module.map"
}
else {
moduleDirectory = "\(sdkPath)/System/Library/Frameworks/CommonCrypto.framework"
moduleFileName = "module.map"

if fileExists(moduleDirectory) {
reportError("Module directory already exists at \(moduleDirectory).")
}
}

if !mkdir(moduleDirectory) {
reportError("Failed to create module directory \(moduleDirectory)")
}

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

let moduleMapFile =
"module CommonCrypto [system] {\n" +
" header \"\(headerFile1)\"\n" +
" header \"\(headerFile2)\"\n" +
" export *\n" +
"}\n"

let moduleMapPath = "\(moduleDirectory)/\(moduleFileName)"
do {
try moduleMapFile.writeToFile(moduleMapPath, atomically: true, encoding:NSUTF8StringEncoding)
print("Successfully created module \(moduleMapPath)")
exit(0)
}
catch {
reportError("Failed to write module map file to \(moduleMapPath)")
}

120 changes: 24 additions & 96 deletions IDZSwiftCommonCrypto.podspec
Original file line number Diff line number Diff line change
@@ -1,120 +1,48 @@
#
# Be sure to run `pod spec lint IDZSwiftCommonCrypto.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#

Pod::Spec.new do |s|

# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#

s.name = "IDZSwiftCommonCrypto"
s.version = "0.6.8"
s.version = "0.7.0"
s.summary = "A wrapper for Apple's Common Crypto library written in Swift."

s.homepage = "https://github.com/iosdevzone/IDZSwiftCommonCrypto"


# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See http://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#

s.license = "MIT"
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }


# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#

s.author = { "iOSDevZone" => "[email protected]" }
s.social_media_url = "http://twitter.com/iOSDevZone"
s.platform = :ios, "8.0"
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#

s.osx.deployment_target = '10.10'
s.ios.deployment_target = '8.0'
s.tvos.deployment_target = '9.0'
s.watchos.deployment_target = '2.0'

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


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
# Create the dummy CommonCrypto.framework structures
#
s.prepare_command = <<-CMD

touch prepare_command.txt
echo 'Running prepare_command'
if [ ! -e CommonCrypto ]; then
pwd
echo Running GenerateCommonCryptoModule
./GenerateCommonCryptoModule iphonesimulator .
else
echo Skipped GenerateCommonCryptoModule
fi
pwd
echo Running GenerateCommonCryptoModule
swift ./GenerateCommonCryptoModule.swift macosx .
swift ./GenerateCommonCryptoModule.swift iphonesimulator .
swift ./GenerateCommonCryptoModule.swift iphoneos .
swift ./GenerateCommonCryptoModule.swift appletvsimulator .
swift ./GenerateCommonCryptoModule.swift appletvos .
swift ./GenerateCommonCryptoModule.swift watchsimulator .
swift ./GenerateCommonCryptoModule.swift watchos .

CMD
s.source_files = "IDZSwiftCommonCrypto"

# s.public_header_files = "Classes/**/*.h"


# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#

# s.resource = "icon.png"
# s.resources = "Resources/*.png"

s.preserve_paths = "CommonCrypto"


# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#

# s.framework = "SomeFramework"
# s.frameworks = "SomeFramework", "AnotherFramework"

# s.library = "iconv"
# s.libraries = "iconv", "xml2"


# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.
s.source_files = "IDZSwiftCommonCrypto"

# s.requires_arc = true
# Stop CocoaPods from deleting dummy frameworks
s.preserve_paths = "Frameworks"

s.xcconfig = { "SWIFT_INCLUDE_PATHS" => "$(PROJECT_DIR)/IDZSwiftCommonCrypto" }
# s.dependency "JSONKit", "~> 1.4"
# Make sure we can find the dummy frameworks
s.xcconfig = {
"SWIFT_INCLUDE_PATHS" => "$(PROJECT_DIR)/IDZSwiftCommonCrypto/Frameworks/$(PLATFORM_NAME)",
"FRAMEWORK_SEARCH_PATHS" => "$(PROJECT_DIR)/IDZSwiftCommonCrypto/Frameworks/$(PLATFORM_NAME)"
}

end
Loading