diff --git a/Sources/ProjectSpec/ProjectExtensions.swift b/Sources/ProjectSpec/ProjectExtensions.swift index 68f804ce..96bd6829 100644 --- a/Sources/ProjectSpec/ProjectExtensions.swift +++ b/Sources/ProjectSpec/ProjectExtensions.swift @@ -46,7 +46,7 @@ extension BuildSettings: CustomStringConvertible { } } -public func +=( lhs: inout BuildSettings, rhs: BuildSettings?) { +public func +=(lhs: inout BuildSettings, rhs: BuildSettings?) { guard let rhs = rhs else { return } lhs.merge(rhs) } @@ -63,4 +63,3 @@ extension PBXProductType { } } } - diff --git a/Sources/ProjectSpec/ProjectSpecError.swift b/Sources/ProjectSpec/ProjectSpecError.swift index ff243b1b..400c1921 100644 --- a/Sources/ProjectSpec/ProjectSpecError.swift +++ b/Sources/ProjectSpec/ProjectSpecError.swift @@ -15,9 +15,9 @@ public enum ProjectSpecError: Error, CustomStringConvertible { public var description: String { switch self { - case let .unknownTargetType(type): return "Unknown Target type: \(type)" - case let .unknownTargetPlatform(platform): return "Unknown Target platform: \(platform)" - case let .invalidDependency(dependency): return "Unknown Target dependency: \(dependency)" + case let .unknownTargetType(type): return "Unknown Target type: \(type)" + case let .unknownTargetPlatform(platform): return "Unknown Target platform: \(platform)" + case let .invalidDependency(dependency): return "Unknown Target dependency: \(dependency)" } } } diff --git a/Sources/ProjectSpec/Scheme.swift b/Sources/ProjectSpec/Scheme.swift index a005dfc8..819f3801 100644 --- a/Sources/ProjectSpec/Scheme.swift +++ b/Sources/ProjectSpec/Scheme.swift @@ -105,24 +105,28 @@ extension Scheme.Run: JSONObjectConvertible { config = try jsonDictionary.json(atKeyPath: "config") } } + extension Scheme.Test: JSONObjectConvertible { public init(jsonDictionary: JSONDictionary) throws { config = try jsonDictionary.json(atKeyPath: "config") } } + extension Scheme.Profile: JSONObjectConvertible { public init(jsonDictionary: JSONDictionary) throws { config = try jsonDictionary.json(atKeyPath: "config") } } + extension Scheme.Analyze: JSONObjectConvertible { public init(jsonDictionary: JSONDictionary) throws { config = try jsonDictionary.json(atKeyPath: "config") } } + extension Scheme.Archive: JSONObjectConvertible { public init(jsonDictionary: JSONDictionary) throws { @@ -152,14 +156,14 @@ extension Scheme.Build: JSONObjectConvertible { for (key, value) in dictionary { let buildTypes: [XCScheme.BuildAction.Entry.BuildFor] - switch value { - case "all": buildTypes = [.running, .testing, .profiling, .analyzing, .archiving] - case "none": buildTypes = [] - case "testing": buildTypes = [.testing,.analyzing] - case "indexing": buildTypes = [.testing, .analyzing, .archiving] - default: buildTypes = [.running, .testing, .profiling, .analyzing, .archiving] - } - targets.append(Scheme.BuildTarget(target: key, buildTypes: buildTypes)) + switch value { + case "all": buildTypes = [.running, .testing, .profiling, .analyzing, .archiving] + case "none": buildTypes = [] + case "testing": buildTypes = [.testing, .analyzing] + case "indexing": buildTypes = [.testing, .analyzing, .archiving] + default: buildTypes = [.running, .testing, .profiling, .analyzing, .archiving] + } + targets.append(Scheme.BuildTarget(target: key, buildTypes: buildTypes)) } self.targets = targets @@ -172,11 +176,11 @@ extension XCScheme.BuildAction.Entry.BuildFor: JSONPrimitiveConvertible { public static func from(jsonValue: String) -> XCScheme.BuildAction.Entry.BuildFor? { switch jsonValue { - case "test","testing": return .testing - case "profile", "profiling": return .profiling - case "run", "running": return .running - case "archive", "archiving": return .archiving - case "analyze", "analyzing": return .analyzing + case "test", "testing": return .testing + case "profile", "profiling": return .profiling + case "run", "running": return .running + case "archive", "archiving": return .archiving + case "analyze", "analyzing": return .analyzing default: return nil } } diff --git a/Sources/ProjectSpec/Settings.swift b/Sources/ProjectSpec/Settings.swift index a90a87f7..f5e2eb9b 100644 --- a/Sources/ProjectSpec/Settings.swift +++ b/Sources/ProjectSpec/Settings.swift @@ -10,7 +10,7 @@ import Foundation import JSONUtilities import xcodeproj -public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertible { +public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertible { public let buildSettings: BuildSettings public let configSettings: [String: Settings] @@ -23,9 +23,9 @@ public struct Settings: Equatable, JSONObjectConvertible, CustomStringConvertibl } public init(dictionary: [String: Any]) { - self.buildSettings = BuildSettings(dictionary: dictionary) - self.configSettings = [:] - self.presets = [] + buildSettings = BuildSettings(dictionary: dictionary) + configSettings = [:] + presets = [] } static let empty: Settings = Settings(dictionary: [:]) @@ -86,7 +86,6 @@ extension Settings: ExpressibleByDictionaryLiteral { elements.forEach { dictionary[$0.0] = $0.1 } self.init(dictionary: dictionary) } - } extension BuildSettings: JSONObjectConvertible { diff --git a/Sources/ProjectSpec/Target.swift b/Sources/ProjectSpec/Target.swift index 318585f8..eb4755e8 100644 --- a/Sources/ProjectSpec/Target.swift +++ b/Sources/ProjectSpec/Target.swift @@ -57,7 +57,7 @@ extension Target: JSONObjectConvertible { throw ProjectSpecError.unknownTargetType(typeString) } let platformString: String = try jsonDictionary.json(atKeyPath: "platform") - if let platform = Platform(rawValue: platformString) { + if let platform = Platform(rawValue: platformString) { self.platform = platform } else { throw ProjectSpecError.unknownTargetPlatform(platformString) @@ -89,9 +89,9 @@ public enum Dependency: Equatable { public static func ==(lhs: Dependency, rhs: Dependency) -> Bool { switch (lhs, rhs) { - case (let .target(lhs), let .target(rhs)): return lhs == rhs - case (let .framework(lhs), let .framework(rhs)): return lhs == rhs - case (let .carthage(lhs), let .carthage(rhs)): return lhs == rhs + case let (.target(lhs), .target(rhs)): return lhs == rhs + case let (.framework(lhs), .framework(rhs)): return lhs == rhs + case let (.carthage(lhs), .carthage(rhs)): return lhs == rhs default: return false } } @@ -111,4 +111,3 @@ extension Dependency: JSONObjectConvertible { } } } - diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index 03761946..ef47ebc3 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -31,12 +31,12 @@ public class PBXProjGenerator { var carthageFrameworksByPlatform: [String: [String]] = [:] var frameworkFiles: [String] = [] - var uuids:Set = [] + var uuids: Set = [] var projectReference: String public init(spec: ProjectSpec, path: Path) { self.spec = spec - self.basePath = path + basePath = path projectReference = "" projectReference = generateUUID(PBXProject.self, spec.name) @@ -51,7 +51,7 @@ public class PBXProjGenerator { repeat { counter += 1 uuid = "\(classAcronym)\(stringID)\(String(format: "%02d", counter))" - } while(uuids.contains(uuid)) + } while (uuids.contains(uuid)) return uuid } @@ -130,7 +130,7 @@ public class PBXProjGenerator { return SourceFile(path: path, fileReference: fileReference, buildFile: buildFile) } - func generateTarget(_ target: Target) throws -> PBXNativeTarget { + func generateTarget(_ target: Target) throws -> PBXNativeTarget { let sourcePaths = target.sources.map { basePath + $0 } var sourceFilePaths: [Path] = [] @@ -161,17 +161,17 @@ public class PBXProjGenerator { switch dependancy { case let .target(dependencyTarget): let targetProxy = PBXContainerItemProxy(reference: generateUUID(PBXContainerItemProxy.self, target.name), containerPortal: projectReference, remoteGlobalIDString: targetNativeReferences[dependencyTarget]!, proxyType: .nativeTarget, remoteInfo: dependencyTarget) - let targetDependancy = PBXTargetDependency(reference: generateUUID(PBXTargetDependency.self, dependencyTarget), target: targetNativeReferences[dependencyTarget]!, targetProxy: targetProxy.reference ) + let targetDependancy = PBXTargetDependency(reference: generateUUID(PBXTargetDependency.self, dependencyTarget), target: targetNativeReferences[dependencyTarget]!, targetProxy: targetProxy.reference) objects.append(.pbxContainerItemProxy(targetProxy)) objects.append(.pbxTargetDependency(targetDependancy)) dependancies.append(targetDependancy.reference) let dependencyBuildFile = targetBuildFileReferences[dependencyTarget]! - //link + // link targetFrameworkBuildFiles.append(dependencyBuildFile) - //embed + // embed let embedSettings: [String: Any] = ["ATTRIBUTES": ["CodeSignOnCopy", "RemoveHeadersOnCopy"]] let embedFile = PBXBuildFile(reference: generateUUID(PBXBuildFile.self, targetFileReferences[dependencyTarget]!), fileRef: targetFileReferences[dependencyTarget]!, settings: embedSettings) objects.append(.pbxBuildFile(embedFile)) @@ -216,7 +216,7 @@ public class PBXProjGenerator { objects.append(.pbxBuildFile(buildFile)) } - //TODO: don't generate build files for files that won't be built + // TODO: don't generate build files for files that won't be built func getBuildFilesForPhase(_ buildPhase: BuildPhase) -> Set { let files = sourceFilePaths.filter { getBuildPhaseForPath($0) == buildPhase }.map(generateSourceFile) @@ -243,15 +243,14 @@ public class PBXProjGenerator { objects.append(.pbxCopyFilesBuildPhase(copyFilesPhase)) buildPhases.append(copyFilesPhase.reference) - if target.type == .application { func getCarthageFrameworks(target: Target) -> [String] { var frameworks: [String] = [] for dependency in target.dependencies { switch dependency { - case .carthage(let framework): frameworks.append(framework) - case .target(let targetName): - if let target = spec.targets.first(where: {$0.name == targetName}) { + case let .carthage(framework): frameworks.append(framework) + case let .target(targetName): + if let target = spec.targets.first(where: { $0.name == targetName }) { frameworks += getCarthageFrameworks(target: target) } default: break @@ -360,5 +359,4 @@ public class PBXProjGenerator { groups.insert(group, at: 0) return (allFilePaths, groups) } - } diff --git a/Sources/XcodeGenKit/ProjectGenerator.swift b/Sources/XcodeGenKit/ProjectGenerator.swift index eed67945..59c4587b 100644 --- a/Sources/XcodeGenKit/ProjectGenerator.swift +++ b/Sources/XcodeGenKit/ProjectGenerator.swift @@ -59,7 +59,7 @@ public class ProjectGenerator { for target in spec.targets { for dependency in target.dependencies { - if case .target(let targetName) = dependency, spec.getTarget(targetName) == nil { + if case let .target(targetName) = dependency, spec.getTarget(targetName) == nil { errors.append(.invalidTargetDependency(target: target.name, dependency: targetName)) } } @@ -95,19 +95,19 @@ public class ProjectGenerator { errors.append(.invalidSchemeTarget(scheme: scheme.name, target: buildTarget.target)) } } - if let buildAction = scheme.run, spec.getConfig(buildAction.config) == nil { + if let buildAction = scheme.run, spec.getConfig(buildAction.config) == nil { errors.append(.invalidSchemeConfig(scheme: scheme.name, config: buildAction.config)) } - if let buildAction = scheme.test, spec.getConfig(buildAction.config) == nil { + if let buildAction = scheme.test, spec.getConfig(buildAction.config) == nil { errors.append(.invalidSchemeConfig(scheme: scheme.name, config: buildAction.config)) } - if let buildAction = scheme.profile, spec.getConfig(buildAction.config) == nil { + if let buildAction = scheme.profile, spec.getConfig(buildAction.config) == nil { errors.append(.invalidSchemeConfig(scheme: scheme.name, config: buildAction.config)) } - if let buildAction = scheme.analyze, spec.getConfig(buildAction.config) == nil { + if let buildAction = scheme.analyze, spec.getConfig(buildAction.config) == nil { errors.append(.invalidSchemeConfig(scheme: scheme.name, config: buildAction.config)) } - if let buildAction = scheme.archive, spec.getConfig(buildAction.config) == nil { + if let buildAction = scheme.archive, spec.getConfig(buildAction.config) == nil { errors.append(.invalidSchemeConfig(scheme: scheme.name, config: buildAction.config)) } } @@ -148,7 +148,7 @@ public class ProjectGenerator { let buildAction = XCScheme.BuildAction(buildActionEntries: buildActionEntries, parallelizeBuild: true, buildImplicitDependencies: true) - let testAction = XCScheme.TestAction(buildConfiguration: scheme.test?.config ?? defaultDebugConfig.name, macroExpansion: buildableReference) + let testAction = XCScheme.TestAction(buildConfiguration: scheme.test?.config ?? defaultDebugConfig.name, macroExpansion: buildableReference) let launchAction = XCScheme.LaunchAction(buildableProductRunnable: productRunabke, buildConfiguration: scheme.run?.config ?? defaultDebugConfig.name) diff --git a/Sources/XcodeGenKit/SettingsBuilder.swift b/Sources/XcodeGenKit/SettingsBuilder.swift index 452c5793..2b74bab1 100644 --- a/Sources/XcodeGenKit/SettingsBuilder.swift +++ b/Sources/XcodeGenKit/SettingsBuilder.swift @@ -55,7 +55,6 @@ extension ProjectSpec { } } - private var buildSettingFiles: [String: BuildSettings] = [:] extension SettingsPresetFile { diff --git a/Tests/XcodeGenKitTests/FixtureTests.swift b/Tests/XcodeGenKitTests/FixtureTests.swift index 48d780cc..12455040 100644 --- a/Tests/XcodeGenKitTests/FixtureTests.swift +++ b/Tests/XcodeGenKitTests/FixtureTests.swift @@ -16,7 +16,6 @@ func generate(specPath: Path, projectPath: Path) throws { func fixtureTests() { - describe("Test Project") { $0.it("generates") { try generate(specPath: fixturePath + "TestProject/spec.yml", projectPath: fixturePath + "TestProject/GeneratedProject.xcodeproj") diff --git a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift index 6f5c642a..ca558b55 100644 --- a/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift +++ b/Tests/XcodeGenKitTests/ProjectGeneratorTests.swift @@ -56,9 +56,11 @@ func projectGeneratorTests() { buildSettings += SettingsPresetFile.base.getBuildSettings() buildSettings += SettingsPresetFile.config(.debug).getBuildSettings() - buildSettings += ["SETTING": "value", - "SETTING 5": "value 5", - "SETTING 6": "value 6"] + buildSettings += [ + "SETTING": "value", + "SETTING 5": "value 5", + "SETTING 6": "value 6", + ] try expect(debugProjectSettings) == buildSettings var expectedTargetDebugSettings = BuildSettings() @@ -78,8 +80,8 @@ func projectGeneratorTests() { let pbxProject = try getPbxProj(spec) let nativeTargets = pbxProject.objects.nativeTargets try expect(nativeTargets.count) == 2 - try expect(nativeTargets.contains{ $0.name == application.name }).beTrue() - try expect(nativeTargets.contains{ $0.name == framework.name}).beTrue() + try expect(nativeTargets.contains { $0.name == application.name }).beTrue() + try expect(nativeTargets.contains { $0.name == framework.name }).beTrue() } $0.it("generates dependencies") { @@ -98,7 +100,7 @@ func projectGeneratorTests() { let scheme = Scheme(name: "MyScheme", build: Scheme.Build(targets: [buildTarget])) let spec = ProjectSpec(name: "test", targets: [application, framework], schemes: [scheme]) let project = try getProject(spec) - guard let target = project.pbxproj.objects.nativeTargets.first (where: { $0.name == application.name }) else { throw failure("Target not found") } + guard let target = project.pbxproj.objects.nativeTargets.first(where: { $0.name == application.name }) else { throw failure("Target not found") } guard let xcscheme = project.sharedData?.schemes.first else { throw failure("Scheme not found") } try expect(scheme.name) == "MyScheme" guard let buildActionEntry = xcscheme.buildAction?.buildActionEntries.first else { throw failure("Build Action entry not found") } @@ -108,7 +110,8 @@ func projectGeneratorTests() { buildActionEntry.buildableReference, xcscheme.launchAction?.buildableProductRunnable.buildableReference, xcscheme.profileAction?.buildableProductRunnable.buildableReference, - xcscheme.testAction?.macroExpansion].flatMap { $0 } + xcscheme.testAction?.macroExpansion, + ].flatMap { $0 } for buildableReference in buildableReferences { try expect(buildableReference.blueprintIdentifier) == target.reference @@ -132,14 +135,14 @@ func projectGeneratorTests() { Config(name: "Production Debug", type: .debug), Config(name: "Test Release", type: .release), Config(name: "Production Release", type: .release), - ] + ] let spec = ProjectSpec(name: "test", configs: configs, targets: [target, framework]) let project = try getProject(spec) try expect(project.sharedData?.schemes.count) == 2 - guard let nativeTarget = project.pbxproj.objects.nativeTargets.first (where: { $0.name == application.name }) else { throw failure("Target not found") } + guard let nativeTarget = project.pbxproj.objects.nativeTargets.first(where: { $0.name == application.name }) else { throw failure("Target not found") } guard let xcscheme = project.sharedData?.schemes.first(where: { $0.name == "\(target.name) Test" }) else { throw failure("Scheme not found") } guard let buildActionEntry = xcscheme.buildAction?.buildActionEntries.first else { throw failure("Build Action entry not found") } try expect(buildActionEntry.buildableReference.blueprintIdentifier) == nativeTarget.reference @@ -150,8 +153,6 @@ func projectGeneratorTests() { try expect(xcscheme.analyzeAction?.buildConfiguration) == "Test Debug" try expect(xcscheme.archiveAction?.buildConfiguration) == "Test Release" } - } } } - diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index 56eb9d5b..f5632106 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -21,7 +21,7 @@ func specLoadingTests() { } } - func expectTargetError( _ target: [String: Any], _ expectedError: ProjectSpecError) throws { + func expectTargetError(_ target: [String: Any], _ expectedError: ProjectSpecError) throws { try expectError(expectedError) { _ = try Target(jsonDictionary: target) } @@ -56,7 +56,7 @@ func specLoadingTests() { ["target": "name"], ["carthage": "name"], ["framework": "path"], - ] + ] let target = try Target(jsonDictionary: targetDictionary) try expect(target.dependencies.count) == 3 try expect(target.dependencies[0]) == .target("name") @@ -66,7 +66,7 @@ func specLoadingTests() { $0.it("parses schemes") { let schemeDictionary: [String: Any] = [ - "build": ["targets": ["Target": "all"]] + "build": ["targets": ["Target": "all"]], ] let scheme = try Scheme(name: "Scheme", jsonDictionary: schemeDictionary) let target = scheme.build.targets.first! @@ -101,5 +101,4 @@ func specLoadingTests() { try expect(spec.settingPresets["preset8"]) == preset8 } } - } diff --git a/Tests/XcodeGenKitTests/TestHelpers.swift b/Tests/XcodeGenKitTests/TestHelpers.swift index 12913d70..2e881382 100644 --- a/Tests/XcodeGenKitTests/TestHelpers.swift +++ b/Tests/XcodeGenKitTests/TestHelpers.swift @@ -2,7 +2,7 @@ import Foundation import Spectre import xcodeproj -func expectError(_ expectedError: T, _ closure: () throws -> ()) throws where T: CustomStringConvertible { +func expectError(_ expectedError: T, _ closure: () throws -> Void) throws where T: CustomStringConvertible { do { try closure() } catch let error as T { @@ -14,7 +14,7 @@ func expectError(_ expectedError: T, _ closure: () throws -> ()) throw throw failure("Supposed to fail with \"\(expectedError)\"") } -struct ExpectationFailure : FailureType { +struct ExpectationFailure: FailureType { let file: String let line: Int let function: String @@ -29,7 +29,7 @@ struct ExpectationFailure : FailureType { } } -open class ArrayExpectation : ExpectationType { +open class ArrayExpectation: ExpectationType { public typealias ValueType = Array open let expression: () throws -> ValueType? @@ -53,7 +53,7 @@ open class ArrayExpectation : ExpectationType { } } -public func expect( _ expression: @autoclosure @escaping () throws -> [T]?, file: String = #file, line: Int = #line, function: String = #function) -> ArrayExpectation { +public func expect(_ expression: @autoclosure @escaping () throws -> [T]?, file: String = #file, line: Int = #line, function: String = #function) -> ArrayExpectation { return ArrayExpectation(file: file, line: line, function: function, expression: expression) } @@ -74,7 +74,7 @@ extension ArrayExpectation where T: Named { public func contains(name: String) throws { let value = try expression() if let value = value { - if !value.contains(where: { $0.name == name}) { + if !value.contains(where: { $0.name == name }) { throw failure("Array does not contain item with name \(name)") } } @@ -85,6 +85,6 @@ public protocol Named { var name: String { get } } -extension XCBuildConfiguration: Named { } -extension PBXNativeTarget: Named { } -extension XCScheme: Named { } +extension XCBuildConfiguration: Named {} +extension PBXNativeTarget: Named {} +extension XCScheme: Named {} diff --git a/format_code.sh b/format_code.sh new file mode 100644 index 00000000..791e0883 --- /dev/null +++ b/format_code.sh @@ -0,0 +1,2 @@ +swiftformat Tests --stripunusedargs closure-only +swiftformat sources --stripunusedargs closure-only