Explorar o código

Merge pull request #47 from norio-nomura/swift-5.0

Swift 5.0
Norio Nomura %!s(int64=6) %!d(string=hai) anos
pai
achega
2ec1fbbcd5

+ 26 - 61
.circleci/config.yml

@@ -1,5 +1,8 @@
-aliases:
-  - &xcode
+version: 2.1
+jobs:
+  xcode_codecov:
+    macos:
+      xcode: "10.0.0"
     shell: /bin/bash --login -eo pipefail
     environment:
       XCODE_FLAGS: -scheme Base32
@@ -14,67 +17,29 @@ aliases:
           path: build/reports/
       - run: bash <(curl -s https://codecov.io/bash)
 
-  - &steps-for-swiftpm
-    - checkout
-    - run: swift test
-
-version: 2
-jobs:
-  xcode_10_swift_4.2:
-    macos:
-      xcode: "10.0.0"
-    <<: *xcode
-
-  linux_swift_4:
-    docker:
-      - image: norionomura/swift:40
-    steps: *steps-for-swiftpm
-
-  linux_swift_4.0.2:
-    docker:
-      - image: norionomura/swift:402
-    steps: *steps-for-swiftpm
-
-  linux_swift_4.0.3:
+  test_with_image:
+    parameters:
+      image:
+        type: string
     docker:
-      - image: norionomura/swift:403
-    steps: *steps-for-swiftpm
-
-  linux_swift_4.1:
-    docker:
-      - image: norionomura/swift:41
-    steps: *steps-for-swiftpm
-
-  linux_swift_4.1.1:
-    docker:
-      - image: norionomura/swift:411
-    steps: *steps-for-swiftpm
-
-  linux_swift_4.1.2:
-    docker:
-      - image: norionomura/swift:412
-    steps: *steps-for-swiftpm
-
-  linux_swift_4.1.3:
-    docker:
-      - image: norionomura/swift:413
-    steps: *steps-for-swiftpm
-
-  linux_swift_4.2:
-    docker:
-      - image: norionomura/swift:42
-    steps: *steps-for-swiftpm
+      - image: << parameters.image >>
+    steps:
+      - checkout
+      - run: swift test
 
 workflows:
-  version: 2
   workflow:
     jobs:
-      - xcode_10_swift_4.2
-      - linux_swift_4
-      - linux_swift_4.0.2
-      - linux_swift_4.0.3
-      - linux_swift_4.1
-      - linux_swift_4.1.1
-      - linux_swift_4.1.2
-      - linux_swift_4.1.3
-      - linux_swift_4.2
+      - xcode_codecov
+      - test_with_image:
+          name: linux_swift_4.0
+          image: norionomura/swift:4.0
+      - test_with_image:
+          name: linux_swift_4.1
+          image: norionomura/swift:4.1
+      - test_with_image:
+          name: linux_swift_4.2
+          image: norionomura/swift:4.2
+      - test_with_image:
+          name: linux_swift_5.0
+          image: norionomura/swift:5.0

+ 1 - 0
Base32.xcodeproj/Configs/Project.xcconfig

@@ -9,6 +9,7 @@ OTHER_SWIFT_FLAGS = -DXcode
 COMBINE_HIDPI_IMAGES = YES
 USE_HEADERMAP = NO
 FRAMEWORK_SEARCH_PATHS = "$(PLATFORM_DIR)/Developer/Library/Frameworks";
+CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
 CLANG_ENABLE_OBJC_WEAK = YES;
 CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
 CLANG_WARN_BOOL_CONVERSION = YES;

+ 17 - 4
Base32.xcodeproj/project.pbxproj

@@ -7,6 +7,7 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		6C5B22F8226029AC00C19E94 /* shim.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C5B22F7226029AC00C19E94 /* shim.swift */; };
 		6CC8D4741D96DF990031ED04 /* Base32.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "_____Product_Base32" /* Base32.framework */; };
 		_LinkFileRef_Base32_via_Base32Tests /* Base32.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "_____Product_Base32" /* Base32.framework */; };
 		__src_cc_ref_Sources/Base32/Base16.swift /* Base16.swift in Sources */ = {isa = PBXBuildFile; fileRef = __PBXFileRef_Sources/Base32/Base16.swift /* Base16.swift */; };
@@ -30,7 +31,7 @@
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
-		6C1C19C51FEEA37600371B6F /* Package@swift-4.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Package@swift-4.swift"; sourceTree = "<group>"; };
+		6C5B22F7226029AC00C19E94 /* shim.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = shim.swift; sourceTree = "<group>"; };
 		6C9233FE1E5307C2003ABE13 /* LinuxMain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LinuxMain.swift; path = Tests/LinuxMain.swift; sourceTree = "<group>"; };
 		6CDCD8721D98BE7800A65866 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
 		6CDCD8731D98BE7800A65866 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
@@ -91,7 +92,6 @@
 				6CDCD8721D98BE7800A65866 /* README.md */,
 				6CDCD8731D98BE7800A65866 /* LICENSE */,
 				__PBXFileRef_Package.swift /* Package.swift */,
-				6C1C19C51FEEA37600371B6F /* Package@swift-4.swift */,
 				"_____Configs_" /* Configs */,
 				"_____Sources_" /* Sources */,
 				"_______Tests_" /* Tests */,
@@ -130,6 +130,7 @@
 				__PBXFileRef_Sources/Base32/Base16.swift /* Base16.swift */,
 				__PBXFileRef_Sources/Base32/Base32.swift /* Base32.swift */,
 				__PBXFileRef_Sources/Base32/StringExtension.swift /* StringExtension.swift */,
+				6C5B22F7226029AC00C19E94 /* shim.swift */,
 			);
 			name = Base32;
 			path = Sources/Base32;
@@ -224,11 +225,22 @@
 		__RootObject_ /* Project object */ = {
 			isa = PBXProject;
 			attributes = {
-				LastUpgradeCheck = 0930;
+				LastUpgradeCheck = 1020;
+				TargetAttributes = {
+					"______Target_Base32" = {
+						LastSwiftMigration = 1020;
+					};
+					"______Target_Base32Tests" = {
+						LastSwiftMigration = 1020;
+					};
+					"______Target_SecEncodeTransformTests" = {
+						LastSwiftMigration = 1020;
+					};
+				};
 			};
 			buildConfigurationList = "___RootConfs_" /* Build configuration list for PBXProject "Base32" */;
 			compatibilityVersion = "Xcode 3.2";
-			developmentRegion = English;
+			developmentRegion = en;
 			hasScannedForEncodings = 0;
 			knownRegions = (
 				en,
@@ -252,6 +264,7 @@
 			files = (
 				__src_cc_ref_Sources/Base32/Base16.swift /* Base16.swift in Sources */,
 				__src_cc_ref_Sources/Base32/Base32.swift /* Base32.swift in Sources */,
+				6C5B22F8226029AC00C19E94 /* shim.swift in Sources */,
 				__src_cc_ref_Sources/Base32/StringExtension.swift /* StringExtension.swift in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 1 - 1
Base32.xcodeproj/xcshareddata/xcschemes/Base32.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "0930"
+   LastUpgradeVersion = "1020"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 18 - 0
Package@swift-4.2.swift

@@ -0,0 +1,18 @@
+// swift-tools-version:4.2
+import PackageDescription
+
+var package = Package(
+    name: "Base32",
+    products: [
+      .library(name: "Base32", targets: ["Base32"])
+    ],
+    targets: [
+        .target(name: "Base32"),
+        .testTarget(name: "Base32Tests", dependencies: ["Base32"])
+    ],
+    swiftLanguageVersions: [.v4, .v4_2]
+)
+
+#if os(macOS)
+    package.targets.append(.testTarget(name: "SecEncodeTransformTests", dependencies: ["Base32"]))
+#endif

+ 18 - 0
Package@swift-5.swift

@@ -0,0 +1,18 @@
+// swift-tools-version:5.0
+import PackageDescription
+
+var package = Package(
+    name: "Base32",
+    products: [
+      .library(name: "Base32", targets: ["Base32"])
+    ],
+    targets: [
+        .target(name: "Base32"),
+        .testTarget(name: "Base32Tests", dependencies: ["Base32"])
+    ],
+    swiftLanguageVersions: [.v4, .v4_2, .v5]
+)
+
+#if os(macOS)
+    package.targets.append(.testTarget(name: "SecEncodeTransformTests", dependencies: ["Base32"]))
+#endif

+ 1 - 1
Sources/Base32/Base32.swift

@@ -305,7 +305,7 @@ private func base32decode(_ string: String, _ table: [UInt8]) -> [UInt8]? {
     
     // validate string
     let leastPaddingLength = getLeastPaddingLength(string)
-    if let index = string.unicodeScalars.index(where: {$0.value > 0xff || table[Int($0.value)] > 31}) {
+    if let index = string.unicodeScalars.firstIndex(where: {$0.value > 0xff || table[Int($0.value)] > 31}) {
         // index points padding "=" or invalid character that table does not contain.
         let pos = string.unicodeScalars.distance(from: string.unicodeScalars.startIndex, to: index)
         // if pos points padding "=", it's valid.

+ 9 - 0
Sources/Base32/shim.swift

@@ -0,0 +1,9 @@
+#if !swift(>=4.2)
+extension Collection {
+    public func firstIndex(
+        where predicate: (Element) throws -> Bool
+    ) rethrows -> Index? {
+        return try index(where: predicate)
+    }
+}
+#endif

+ 7 - 3
azure-pipelines.yml

@@ -3,7 +3,7 @@ trigger:
 jobs:
 - job: macOS
   pool:
-    vmImage: 'macOS-10.13'
+    vmImage: $[ coalesce(variables['VM_IMAGE'], 'macOS-10.13') ] 
   strategy:
     maxParallel: 10
     matrix:
@@ -23,6 +23,10 @@ jobs:
       Xcode 10.1:
         DEVELOPER_DIR: '/Applications/Xcode_10.1.app'
         XCODE_FLAGS_FOR_TEST: -parallel-testing-enabled NO
+      Xcode 10.2:
+        DEVELOPER_DIR: '/Applications/Xcode_10.2.app'
+        VM_IMAGE: 'macOS-10.14'
+        XCODE_FLAGS_FOR_TEST: -parallel-testing-enabled NO
   steps:
     - script: |
         xcodebuild -version
@@ -66,9 +70,9 @@ jobs:
 
 - job: pod_lib_lint
   pool:
-    vmImage: 'macOS-10.13'
+    vmImage: 'macOS-10.14'
   variables:
-    DEVELOPER_DIR: '/Applications/Xcode_9.4.1.app'
+    DEVELOPER_DIR: '/Applications/Xcode_10.2.app'
   steps:
     - script: pod lib lint
       displayName: pod lib lint