From 45e2c83d3be754758b2dd45f581f107adcb5e461 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 28 Aug 2016 11:29:37 -0400 Subject: [PATCH 1/7] Set SWIFT_VERSION for all targets --- XCode/Swifter.xcodeproj/project.pbxproj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/XCode/Swifter.xcodeproj/project.pbxproj b/XCode/Swifter.xcodeproj/project.pbxproj index 2ca35e7..8eb35f0 100644 --- a/XCode/Swifter.xcodeproj/project.pbxproj +++ b/XCode/Swifter.xcodeproj/project.pbxproj @@ -1236,6 +1236,7 @@ PRODUCT_NAME = Swifter; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1263,6 +1264,7 @@ PRODUCT_NAME = Swifter; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1442,6 +1444,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -1457,6 +1460,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -1512,6 +1516,7 @@ PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifterSampletvOS; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.1; }; @@ -1533,6 +1538,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.1; }; @@ -1559,6 +1565,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1586,6 +1593,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1603,6 +1611,7 @@ MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifteriOSTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -1620,6 +1629,7 @@ PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifteriOSTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; }; name = Release; }; From 79911162777db496d09a1ea4b7cc2ee08b6a0b16 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 28 Aug 2016 11:56:27 -0400 Subject: [PATCH 2/7] Fix SUPPORTED_PLATFORMS --- XCode/Swifter.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/XCode/Swifter.xcodeproj/project.pbxproj b/XCode/Swifter.xcodeproj/project.pbxproj index 8eb35f0..f3c1dc4 100644 --- a/XCode/Swifter.xcodeproj/project.pbxproj +++ b/XCode/Swifter.xcodeproj/project.pbxproj @@ -1235,6 +1235,7 @@ PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifteriOS; PRODUCT_NAME = Swifter; SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; @@ -1263,6 +1264,7 @@ PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifteriOS; PRODUCT_NAME = Swifter; SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; @@ -1564,6 +1566,7 @@ PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwiftertvOS; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "appletvsimulator appletvos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; @@ -1592,6 +1595,7 @@ PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwiftertvOS; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "appletvsimulator appletvos"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; From d285c405e565c9218e934ccbbd4b3cb2f87f0d54 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 28 Aug 2016 13:10:54 -0400 Subject: [PATCH 3/7] Set automatic code signing for Mac target --- XCode/Swifter.xcodeproj/project.pbxproj | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/XCode/Swifter.xcodeproj/project.pbxproj b/XCode/Swifter.xcodeproj/project.pbxproj index f3c1dc4..6052c96 100644 --- a/XCode/Swifter.xcodeproj/project.pbxproj +++ b/XCode/Swifter.xcodeproj/project.pbxproj @@ -814,7 +814,7 @@ 7AE893FA1C0512C400A29F63 = { CreatedOnToolsVersion = 7.1; LastSwiftMigration = 0800; - ProvisioningStyle = Manual; + ProvisioningStyle = Automatic; }; 7C839B6D19422CFF003A6950 = { CreatedOnToolsVersion = 6.0; @@ -1281,6 +1281,7 @@ CURRENT_PROJECT_VERSION = 1.1.3; DEBUG_INFORMATION_FORMAT = dwarf; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1293,7 +1294,7 @@ MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifterMac; PRODUCT_NAME = Swifter; - PROVISIONING_PROFILE_SPECIFIER = JHSX9UH35H/; + PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -1313,6 +1314,7 @@ CURRENT_PROJECT_VERSION = 1.1.3; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1325,7 +1327,7 @@ MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifterMac; PRODUCT_NAME = Swifter; - PROVISIONING_PROFILE_SPECIFIER = JHSX9UH35H/; + PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; From 13836f629d09f75bfeaedbe604a0a5caac388ebe Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 28 Aug 2016 13:11:15 -0400 Subject: [PATCH 4/7] Build fixes for iOS and Linux targets --- Sources/Swifter/Socket+File.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/Swifter/Socket+File.swift b/Sources/Swifter/Socket+File.swift index 439abee..d2f74ea 100644 --- a/Sources/Swifter/Socket+File.swift +++ b/Sources/Swifter/Socket+File.swift @@ -16,8 +16,8 @@ struct sf_hdtr { } - private func sendfileImpl(source: Int32, _ target: Int32, _: off_t, _: UnsafeMutablePointer, _: UnsafeMutablePointer, _: Int32) -> Int32 { - var buffer = [UInt8](count: 1024, repeatedValue: 0) + private func sendfileImpl(source: Int32, _ target: Int32, _: off_t, _: UnsafeMutablePointer, _: UnsafeMutablePointer?, _: Int32) -> Int32 { + var buffer = [UInt8](repeating: 0, count: 1024) while true { let readResult = read(source, &buffer, buffer.count) guard readResult > 0 else { @@ -40,14 +40,19 @@ #endif +#if os(iOS) || os (Linux) + extension Socket { public func writeFile(file: String.File) throws -> Void { var offset: off_t = 0 - let result = sendfileImpl(fileno(file.pointer), self.socketFileDescriptor, 0, &offset, nil, 0) + let result = sendfileImpl(source: fileno(file.pointer), self.socketFileDescriptor, 0, &offset, nil, 0) if result == -1 { throw SocketError.writeFailed("sendfile: " + Process.lastErrno) } } } + +#endif + From bb9a670d07ac912fabdaaab0ed14a6f86935aacd Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 28 Aug 2016 13:48:21 -0400 Subject: [PATCH 5/7] Make tvOS scheme shared so Carthage builds it --- .../xcschemes/SwiftertvOS.xcscheme | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwiftertvOS.xcscheme diff --git a/XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwiftertvOS.xcscheme b/XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwiftertvOS.xcscheme new file mode 100644 index 0000000..0fb1603 --- /dev/null +++ b/XCode/Swifter.xcodeproj/xcshareddata/xcschemes/SwiftertvOS.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 192d04f0e03b48a92482f6ac8fae3f25764f2c1b Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 28 Aug 2016 13:57:55 -0400 Subject: [PATCH 6/7] Set tvOS TARGETED_DEVICE_FAMILY --- XCode/Swifter.xcodeproj/project.pbxproj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/XCode/Swifter.xcodeproj/project.pbxproj b/XCode/Swifter.xcodeproj/project.pbxproj index 6052c96..d392dc6 100644 --- a/XCode/Swifter.xcodeproj/project.pbxproj +++ b/XCode/Swifter.xcodeproj/project.pbxproj @@ -1234,6 +1234,7 @@ MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifteriOS; PRODUCT_NAME = Swifter; + SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -1263,6 +1264,7 @@ MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwifteriOS; PRODUCT_NAME = Swifter; + SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -1567,10 +1569,12 @@ MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwiftertvOS; PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = appletvos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "appletvsimulator appletvos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; + TARGETED_DEVICE_FAMILY = 3; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -1596,10 +1600,12 @@ MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = pl.kolakowski.SwiftertvOS; PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = appletvos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "appletvsimulator appletvos"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 3.0; + TARGETED_DEVICE_FAMILY = 3; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; From 0b4fadaca0011da031730f225357f2b87f6e68fa Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Tue, 13 Sep 2016 00:32:26 -0400 Subject: [PATCH 7/7] Escaping closures --- .gitignore | 1 + Sources/Swifter/HttpServer.swift | 12 ++++++------ Sources/Swifter/Scopes.swift | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 5803dbf..2453ca7 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ DerivedData *.hmap *.ipa *.xcuserstate +*.DS_Store # CocoaPods # diff --git a/Sources/Swifter/HttpServer.swift b/Sources/Swifter/HttpServer.swift index 999f1eb..d4c5b62 100644 --- a/Sources/Swifter/HttpServer.swift +++ b/Sources/Swifter/HttpServer.swift @@ -32,27 +32,27 @@ public class HttpServer: HttpServerIO { public var DELETE, UPDATE, HEAD, POST, GET, PUT : MethodRoute public var delete, update, head, post, get, put : MethodRoute - public func get(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) { + public func get(_ path: String, _ handler: @escaping ((HttpRequest) -> HttpResponse)) { router.register("GET", path: path, handler: handler) } - public func post(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) { + public func post(_ path: String, _ handler: @escaping ((HttpRequest) -> HttpResponse)) { router.register("POST", path: path, handler: handler) } - public func put(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) { + public func put(_ path: String, _ handler: @escaping ((HttpRequest) -> HttpResponse)) { router.register("PUT", path: path, handler: handler) } - public func head(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) { + public func head(_ path: String, _ handler: @escaping ((HttpRequest) -> HttpResponse)) { router.register("HEAD", path: path, handler: handler) } - public func delete(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) { + public func delete(_ path: String, _ handler: @escaping ((HttpRequest) -> HttpResponse)) { router.register("DELETE", path: path, handler: handler) } - public func update(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) { + public func update(_ path: String, _ handler: @escaping ((HttpRequest) -> HttpResponse)) { router.register("UPDATE", path: path, handler: handler) } diff --git a/Sources/Swifter/Scopes.swift b/Sources/Swifter/Scopes.swift index 761759a..fdeba06 100644 --- a/Sources/Swifter/Scopes.swift +++ b/Sources/Swifter/Scopes.swift @@ -11,7 +11,7 @@ import Foundation #endif -public func scopes(_ scope: Closure) -> ((HttpRequest) -> HttpResponse) { +public func scopes(_ scope: @escaping Closure) -> ((HttpRequest) -> HttpResponse) { return { r in ScopesBuffer[Process.tid] = "" scope()