diff --git a/CHANGELOG.md b/CHANGELOG.md index d7edd949..da6e686b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,12 @@ #### Fixed - Validate scheme test action and test coverage target references before generating. [#775](https://github.com/yonaskolb/XcodeGen/pull/775) @liamnichols +- Fixed parsing prerelease identifiers in Swift package versions [#779](https://github.com/yonaskolb/XcodeGen/pull/779) @yonaskolb - Fixed using legacy targets as dependencies [#778](https://github.com/yonaskolb/XcodeGen/pull/778) @yonaskolb #### Internal - Updated to XcodeProj 7.8.0 [#777](https://github.com/yonaskolb/XcodeGen/pull/777) @yonaskolb +- Use https://github.com/mxcl/Version [#779](https://github.com/yonaskolb/XcodeGen/pull/779) @yonaskolb ## 2.13.0 diff --git a/Package.resolved b/Package.resolved index 9d13079f..257847a0 100644 --- a/Package.resolved +++ b/Package.resolved @@ -55,6 +55,15 @@ "version": "6.0.1" } }, + { + "package": "Version", + "repositoryURL": "https://github.com/mxcl/Version", + "state": { + "branch": null, + "revision": "a94b48f36763c05629fc102837398505032dead9", + "version": "2.0.0" + } + }, { "package": "XcodeProj", "repositoryURL": "https://github.com/tuist/XcodeProj.git", diff --git a/Package.swift b/Package.swift index e46baab2..1ff8fc24 100644 --- a/Package.swift +++ b/Package.swift @@ -18,10 +18,12 @@ let package = Package( .package(url: "https://github.com/onevcat/Rainbow.git", from: "3.0.0"), .package(url: "https://github.com/tuist/XcodeProj.git", .exact("7.8.0")), .package(url: "https://github.com/jakeheis/SwiftCLI.git", from: "6.0.0"), + .package(url: "https://github.com/mxcl/Version", from: "2.0.0"), ], targets: [ .target(name: "XcodeGen", dependencies: [ "XcodeGenCLI", + "Version", ]), .target(name: "XcodeGenCLI", dependencies: [ "XcodeGenKit", @@ -29,6 +31,7 @@ let package = Package( "SwiftCLI", "Rainbow", "PathKit", + "Version", ]), .target(name: "XcodeGenKit", dependencies: [ "ProjectSpec", @@ -42,6 +45,7 @@ let package = Package( "XcodeProj", "Yams", "Core", + "Version", ]), .target(name: "Core", dependencies: [ "PathKit", diff --git a/Sources/ProjectSpec/CacheFile.swift b/Sources/ProjectSpec/CacheFile.swift index 4f055171..10e21afd 100644 --- a/Sources/ProjectSpec/CacheFile.swift +++ b/Sources/ProjectSpec/CacheFile.swift @@ -1,5 +1,6 @@ import Foundation import Core +import Version public class CacheFile { diff --git a/Sources/ProjectSpec/DeploymentTarget.swift b/Sources/ProjectSpec/DeploymentTarget.swift index f75fdd0b..95838031 100644 --- a/Sources/ProjectSpec/DeploymentTarget.swift +++ b/Sources/ProjectSpec/DeploymentTarget.swift @@ -1,5 +1,6 @@ import Foundation import JSONUtilities +import Version public struct DeploymentTarget: Equatable { @@ -65,9 +66,9 @@ extension DeploymentTarget: JSONObjectConvertible { func parseVersion(_ platform: String) throws -> Version? { if let string: String = jsonDictionary.json(atKeyPath: .key(platform)) { - return try Version(string) + return try Version.parse(string) } else if let double: Double = jsonDictionary.json(atKeyPath: .key(platform)) { - return try Version(double) + return try Version.parse(double) } else { return nil } @@ -82,10 +83,10 @@ extension DeploymentTarget: JSONObjectConvertible { extension DeploymentTarget: JSONEncodable { public func toJSONValue() -> Any { [ - "iOS": iOS?.string, - "tvOS": tvOS?.string, - "watchOS": watchOS?.string, - "macOS": macOS?.string, + "iOS": iOS?.description, + "tvOS": tvOS?.description, + "watchOS": watchOS?.description, + "macOS": macOS?.description, ] } } diff --git a/Sources/ProjectSpec/SpecLoader.swift b/Sources/ProjectSpec/SpecLoader.swift index b4fc4675..2385c2b8 100644 --- a/Sources/ProjectSpec/SpecLoader.swift +++ b/Sources/ProjectSpec/SpecLoader.swift @@ -3,6 +3,7 @@ import JSONUtilities import PathKit import XcodeProj import Yams +import Version public class SpecLoader { diff --git a/Sources/ProjectSpec/SpecOptions.swift b/Sources/ProjectSpec/SpecOptions.swift index 5229b740..ecb14adf 100644 --- a/Sources/ProjectSpec/SpecOptions.swift +++ b/Sources/ProjectSpec/SpecOptions.swift @@ -1,5 +1,6 @@ import Foundation import JSONUtilities +import Version public struct SpecOptions: Equatable { public static let settingPresetsDefault = SettingPresets.all @@ -118,7 +119,7 @@ extension SpecOptions: JSONObjectConvertible { public init(jsonDictionary: JSONDictionary) throws { if let string: String = jsonDictionary.json(atKeyPath: "minimumXcodeGenVersion") { - minimumXcodeGenVersion = try Version(string) + minimumXcodeGenVersion = try Version.parse(string) } carthageBuildPath = jsonDictionary.json(atKeyPath: "carthageBuildPath") @@ -151,7 +152,7 @@ extension SpecOptions: JSONEncodable { "transitivelyLinkDependencies": transitivelyLinkDependencies, "groupSortPosition": groupSortPosition.rawValue, "disabledValidations": disabledValidations.map { $0.rawValue }, - "minimumXcodeGenVersion": minimumXcodeGenVersion?.string, + "minimumXcodeGenVersion": minimumXcodeGenVersion?.description, "carthageBuildPath": carthageBuildPath, "carthageExecutablePath": carthageExecutablePath, "bundleIdPrefix": bundleIdPrefix, diff --git a/Sources/ProjectSpec/SpecValidation.swift b/Sources/ProjectSpec/SpecValidation.swift index 4d4e5849..ba5741ef 100644 --- a/Sources/ProjectSpec/SpecValidation.swift +++ b/Sources/ProjectSpec/SpecValidation.swift @@ -1,6 +1,7 @@ import Foundation import JSONUtilities import PathKit +import Version extension Project { diff --git a/Sources/ProjectSpec/SpecValidationError.swift b/Sources/ProjectSpec/SpecValidationError.swift index 8011fca8..c1948652 100644 --- a/Sources/ProjectSpec/SpecValidationError.swift +++ b/Sources/ProjectSpec/SpecValidationError.swift @@ -1,4 +1,5 @@ import Foundation +import Version public struct SpecValidationError: Error, CustomStringConvertible { diff --git a/Sources/ProjectSpec/SwiftPackage.swift b/Sources/ProjectSpec/SwiftPackage.swift index 7aee8575..b8447136 100644 --- a/Sources/ProjectSpec/SwiftPackage.swift +++ b/Sources/ProjectSpec/SwiftPackage.swift @@ -1,6 +1,7 @@ import Foundation import XcodeProj import JSONUtilities +import Version public struct SwiftPackage: Equatable { @@ -27,17 +28,17 @@ extension SwiftPackage: JSONObjectConvertible { switch versionRequirement { case .upToNextMajorVersion(let version): - try _ = Version(version) + try _ = Version.parse(version) case .upToNextMinorVersion(let version): - try _ = Version(version) + try _ = Version.parse(version) case .range(let from, let to): - try _ = Version(from) - try _ = Version(to) + try _ = Version.parse(from) + try _ = Version.parse(to) case .exact(let version): - try _ = Version(version) + try _ = Version.parse(version) default: break diff --git a/Sources/ProjectSpec/Target.swift b/Sources/ProjectSpec/Target.swift index e28e33c3..d5a5e1fe 100644 --- a/Sources/ProjectSpec/Target.swift +++ b/Sources/ProjectSpec/Target.swift @@ -1,6 +1,7 @@ import Foundation import JSONUtilities import XcodeProj +import Version public struct LegacyTarget: Equatable { public static let passSettingsDefault = false @@ -257,9 +258,9 @@ extension Target: NamedJSONDictionaryConvertible { } if let string: String = jsonDictionary.json(atKeyPath: "deploymentTarget") { - deploymentTarget = try Version(string) + deploymentTarget = try Version.parse(string) } else if let double: Double = jsonDictionary.json(atKeyPath: "deploymentTarget") { - deploymentTarget = try Version(double) + deploymentTarget = try Version.parse(String(double)) } else { deploymentTarget = nil } diff --git a/Sources/ProjectSpec/Version.swift b/Sources/ProjectSpec/Version.swift deleted file mode 100644 index cfd2914c..00000000 --- a/Sources/ProjectSpec/Version.swift +++ /dev/null @@ -1,65 +0,0 @@ -import Foundation - -public struct Version: CustomStringConvertible, Equatable, Comparable, ExpressibleByStringLiteral { - - public var major: UInt - public var minor: UInt - public var patch: UInt - - public init(stringLiteral value: String) { - try! self.init(value) - } - - public init(_ string: String) throws { - let components = try string.split(separator: ".").map { (componentString) -> UInt in - guard let uint = UInt(componentString) else { - throw SpecParsingError.invalidVersion(string) - } - return uint - } - - guard components.count <= 3 else { - throw SpecParsingError.invalidVersion(string) - } - - major = components[0] - minor = (components.count >= 2) ? components[1] : 0 - patch = (components.count == 3) ? components[2] : 0 - } - - public init(_ double: Double) throws { - try self.init(String(double)) - } - - public init(major: UInt, minor: UInt? = 0, patch: UInt? = 0) { - self.major = major - self.minor = minor ?? 0 - self.patch = patch ?? 0 - } - - public var string: String { - "\(major).\(minor).\(patch)" - } - - public var description: String { - string - } - - public func bumpingMajor() -> Version { - Version(major: major + 1, minor: 0, patch: 0) - } - - public func bumpingMinor() -> Version { - Version(major: major, minor: minor + 1, patch: 0) - } - - public func bumpingPatch() -> Version { - Version(major: major, minor: minor, patch: patch + 1) - } - - public static func < (lhs: Version, rhs: Version) -> Bool { - guard lhs.major == rhs.major else { return lhs.major < rhs.major } - guard lhs.minor == rhs.minor else { return lhs.minor < rhs.minor } - return lhs.patch < rhs.patch - } -} diff --git a/Sources/ProjectSpec/VersionExtensions.swift b/Sources/ProjectSpec/VersionExtensions.swift new file mode 100644 index 00000000..010db80a --- /dev/null +++ b/Sources/ProjectSpec/VersionExtensions.swift @@ -0,0 +1,28 @@ +// +// File.swift +// +// +// Created by Yonas Kolb on 7/2/20. +// + +import Foundation +import Version + +extension Version: ExpressibleByStringLiteral { + + public static func parse(_ string: String) throws -> Version { + if let version = Version(tolerant: string) { + return version + } else { + throw SpecParsingError.invalidVersion(string) + } + } + + public static func parse(_ double: Double) throws -> Version { + return try Version.parse(String(double)) + } + + public init(stringLiteral value: String) { + self.init(tolerant: value)! + } +} diff --git a/Sources/XcodeGen/main.swift b/Sources/XcodeGen/main.swift index eb21cff2..b71fdfa8 100644 --- a/Sources/XcodeGen/main.swift +++ b/Sources/XcodeGen/main.swift @@ -1,6 +1,7 @@ import Foundation import ProjectSpec import XcodeGenCLI +import Version let version = Version("2.13.0") let cli = XcodeGenCLI(version: version) diff --git a/Sources/XcodeGenCLI/Commands/DumpCommand.swift b/Sources/XcodeGenCLI/Commands/DumpCommand.swift index dc30fbda..0f84a160 100644 --- a/Sources/XcodeGenCLI/Commands/DumpCommand.swift +++ b/Sources/XcodeGenCLI/Commands/DumpCommand.swift @@ -3,6 +3,7 @@ import SwiftCLI import PathKit import ProjectSpec import Yams +import Version class DumpCommand: ProjectCommand { diff --git a/Sources/XcodeGenCLI/Commands/GenerateCommand.swift b/Sources/XcodeGenCLI/Commands/GenerateCommand.swift index c01c7b9a..bfea587e 100644 --- a/Sources/XcodeGenCLI/Commands/GenerateCommand.swift +++ b/Sources/XcodeGenCLI/Commands/GenerateCommand.swift @@ -4,6 +4,7 @@ import ProjectSpec import SwiftCLI import XcodeGenKit import XcodeProj +import Version class GenerateCommand: ProjectCommand { diff --git a/Sources/XcodeGenCLI/Commands/ProjectCommand.swift b/Sources/XcodeGenCLI/Commands/ProjectCommand.swift index 7bb9dac8..1ae7816d 100644 --- a/Sources/XcodeGenCLI/Commands/ProjectCommand.swift +++ b/Sources/XcodeGenCLI/Commands/ProjectCommand.swift @@ -4,6 +4,7 @@ import ProjectSpec import XcodeGenKit import PathKit import Core +import Version class ProjectCommand: Command { diff --git a/Sources/XcodeGenCLI/XcodeGenCLI.swift b/Sources/XcodeGenCLI/XcodeGenCLI.swift index 32936561..42afef03 100644 --- a/Sources/XcodeGenCLI/XcodeGenCLI.swift +++ b/Sources/XcodeGenCLI/XcodeGenCLI.swift @@ -1,6 +1,7 @@ import Foundation import ProjectSpec import SwiftCLI +import Version public class XcodeGenCLI { let cli: CLI @@ -10,7 +11,7 @@ public class XcodeGenCLI { cli = CLI( name: "xcodegen", - version: version.string, + version: version.description, description: "Generates Xcode projects", commands: [ generateCommand, diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index c8bfcd91..17abd007 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -3,6 +3,7 @@ import PathKit import ProjectSpec import XcodeProj import Yams +import Version public class PBXProjGenerator { @@ -427,7 +428,7 @@ public class PBXProjGenerator { let buildSettings = defaultConfiguration.buildSettings let settings = Settings(buildSettings: buildSettings, configSettings: [:], groups: []) let deploymentTargetString = buildSettings[platform.deploymentTargetSetting] as? String - let deploymentTarget = deploymentTargetString == nil ? nil : try Version(deploymentTargetString!) + let deploymentTarget = deploymentTargetString == nil ? nil : try Version.parse(deploymentTargetString!) let requiresObjCLinking = (buildSettings["OTHER_LDFLAGS"] as? String)?.contains("-ObjC") ?? (productType == .staticLibrary) let dependencyTarget = Target( name: targetObject.name, @@ -778,7 +779,7 @@ public class PBXProjGenerator { ? carthageResolver.relatedDependencies(for: dependency, in: target.platform) : [dependency] allDependencies.forEach { dependency in - var platformPath = Path(carthageResolver.buildPath(for: target.platform, linkType: linkType)) + let platformPath = Path(carthageResolver.buildPath(for: target.platform, linkType: linkType)) var frameworkPath = platformPath + dependency.reference if frameworkPath.extension == nil { frameworkPath = Path(frameworkPath.string + ".framework") diff --git a/Tests/ProjectSpecTests/ProjectSpecTests.swift b/Tests/ProjectSpecTests/ProjectSpecTests.swift index 39b4f50a..1e163163 100644 --- a/Tests/ProjectSpecTests/ProjectSpecTests.swift +++ b/Tests/ProjectSpecTests/ProjectSpecTests.swift @@ -4,6 +4,7 @@ import Spectre import XcodeProj import XCTest import TestSupport +import Version class ProjectSpecTests: XCTestCase { @@ -50,18 +51,18 @@ class ProjectSpecTests: XCTestCase { } $0.it("parses version correctly") { - try expect(Version("2").deploymentTarget) == "2.0" - try expect(Version("2.0").deploymentTarget) == "2.0" - try expect(Version("2.1").deploymentTarget) == "2.1" - try expect(Version("2.10").deploymentTarget) == "2.10" - try expect(Version("2.1.0").deploymentTarget) == "2.1" - try expect(Version("2.12.0").deploymentTarget) == "2.12" - try expect(Version("2.1.2").deploymentTarget) == "2.1.2" - try expect(Version("2.10.2").deploymentTarget) == "2.10.2" - try expect(Version("2.0.2").deploymentTarget) == "2.0.2" - try expect(Version(2).deploymentTarget) == "2.0" - try expect(Version(2.0).deploymentTarget) == "2.0" - try expect(Version(2.1).deploymentTarget) == "2.1" + try expect(Version.parse("2").deploymentTarget) == "2.0" + try expect(Version.parse("2.0").deploymentTarget) == "2.0" + try expect(Version.parse("2.1").deploymentTarget) == "2.1" + try expect(Version.parse("2.10").deploymentTarget) == "2.10" + try expect(Version.parse("2.1.0").deploymentTarget) == "2.1" + try expect(Version.parse("2.12.0").deploymentTarget) == "2.12" + try expect(Version.parse("2.1.2").deploymentTarget) == "2.1.2" + try expect(Version.parse("2.10.2").deploymentTarget) == "2.10.2" + try expect(Version.parse("2.0.2").deploymentTarget) == "2.0.2" + try expect(Version.parse(2).deploymentTarget) == "2.0" + try expect(Version.parse(2.0).deploymentTarget) == "2.0" + try expect(Version.parse(2.1).deploymentTarget) == "2.1" } } } @@ -76,7 +77,7 @@ class ProjectSpecTests: XCTestCase { ) $0.it("fails with invalid XcodeGen version") { - let minimumVersion = Version("1.11.1") + let minimumVersion = try Version.parse("1.11.1") var project = baseProject project.options = SpecOptions(minimumXcodeGenVersion: minimumVersion) @@ -86,9 +87,9 @@ class ProjectSpecTests: XCTestCase { } } - try expectMinimumXcodeGenVersionError(project, minimumVersion: minimumVersion, xcodeGenVersion: Version("1.11.0")) - try expectMinimumXcodeGenVersionError(project, minimumVersion: minimumVersion, xcodeGenVersion: Version("1.10.99")) - try expectMinimumXcodeGenVersionError(project, minimumVersion: minimumVersion, xcodeGenVersion: Version("0.99")) + try expectMinimumXcodeGenVersionError(project, minimumVersion: minimumVersion, xcodeGenVersion: Version.parse("1.11.0")) + try expectMinimumXcodeGenVersionError(project, minimumVersion: minimumVersion, xcodeGenVersion: Version.parse("1.10.99")) + try expectMinimumXcodeGenVersionError(project, minimumVersion: minimumVersion, xcodeGenVersion: Version.parse("0.99")) } $0.it("fails with invalid project") { diff --git a/Tests/ProjectSpecTests/SpecLoadingTests.swift b/Tests/ProjectSpecTests/SpecLoadingTests.swift index beab9d2b..c1d3a765 100644 --- a/Tests/ProjectSpecTests/SpecLoadingTests.swift +++ b/Tests/ProjectSpecTests/SpecLoadingTests.swift @@ -6,6 +6,7 @@ import XcodeProj import XCTest import Yams import TestSupport +import Version class SpecLoadingTests: XCTestCase { @@ -1101,6 +1102,7 @@ class SpecLoadingTests: XCTestCase { "package5": SwiftPackage(url: "package.git", versionRequirement: .revision("x")), "package6": SwiftPackage(url: "package.git", versionRequirement: .range(from: "1.2.0", to: "1.2.5")), "package7": SwiftPackage(url: "package.git", versionRequirement: .exact("1.2.2")), + "package8": SwiftPackage(url: "package.git", versionRequirement: .upToNextMajorVersion("4.0.0-beta.5")), ], localPackages: ["../../Package"], options: .init(localPackagesGroup: "MyPackages")) @@ -1118,6 +1120,7 @@ class SpecLoadingTests: XCTestCase { "package5": ["url": "package.git", "revision": "x"], "package6": ["url": "package.git", "minVersion": "1.2.0", "maxVersion": "1.2.5"], "package7": ["url": "package.git", "version": "1.2.2"], + "package8": ["url": "package.git", "majorVersion": "4.0.0-beta.5"], ], "localPackages": ["../../Package"], ]