From fa156c10280ae33b9ba202d6e2a925fb2dc6f118 Mon Sep 17 00:00:00 2001 From: yonaskolb Date: Mon, 25 Mar 2019 21:10:39 +1100 Subject: [PATCH] Swiftformat --- .../CarthageDependencyResolver.swift | 14 ++--- .../XcodeGenKit/CarthageVersionLoader.swift | 4 +- Sources/XcodeGenKit/PBXProjGenerator.swift | 5 +- Sources/XcodeGenKit/PathExtensions.swift | 14 ++--- .../CarthageDependencyResolverTests.swift | 11 ++-- .../PathExtensionsTests.swift | 14 ++--- Tests/XcodeGenKitTests/ProjectSpecTests.swift | 2 +- Tests/XcodeGenKitTests/SpecLoadingTests.swift | 52 +++++++++---------- 8 files changed, 57 insertions(+), 59 deletions(-) diff --git a/Sources/XcodeGenKit/CarthageDependencyResolver.swift b/Sources/XcodeGenKit/CarthageDependencyResolver.swift index ca3bc0b6..08827261 100644 --- a/Sources/XcodeGenKit/CarthageDependencyResolver.swift +++ b/Sources/XcodeGenKit/CarthageDependencyResolver.swift @@ -22,10 +22,10 @@ public class CarthageDependencyResolver { var executable: String { return project.options.carthageExecutablePath ?? "carthage" } - + private let project: Project lazy var versionLoader = CarthageVersionLoader(buildPath: project.basePath + buildPath) - + init(project: Project) { self.project = project } @@ -89,16 +89,16 @@ public class CarthageDependencyResolver { return frameworks.sorted(by: { $0.reference < $1.reference }) } - + /// Reads the .version file generated for a given Carthage dependency /// and returns a list of its related dependencies including self func relatedDependencies(for dependency: Dependency, in platform: Platform) -> [Dependency] { guard case .carthage = dependency.type, let versionFile = try? versionLoader.getVersionFile(for: dependency.reference) else { - // No .version file or we've been unable to parse - // so fail gracefully by returning the main dependency - return [dependency] + // No .version file or we've been unable to parse + // so fail gracefully by returning the main dependency + return [dependency] } return versionFile.frameworks(for: platform) .map { Dependency( @@ -109,7 +109,7 @@ public class CarthageDependencyResolver { link: dependency.link, implicit: dependency.implicit, weakLink: dependency.weakLink - )} + ) } .sorted(by: { $0.reference < $1.reference }) } } diff --git a/Sources/XcodeGenKit/CarthageVersionLoader.swift b/Sources/XcodeGenKit/CarthageVersionLoader.swift index 93b6642a..eb4cd860 100644 --- a/Sources/XcodeGenKit/CarthageVersionLoader.swift +++ b/Sources/XcodeGenKit/CarthageVersionLoader.swift @@ -38,10 +38,10 @@ struct CarthageVersionFile: Decodable { } private let data: [Platform: [String]] - + internal init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: Platform.self) - data = try Platform.allCases.reduce(into: [:]) { (data, platform) in + data = try Platform.allCases.reduce(into: [:]) { data, platform in let references = try container.decodeIfPresent([Reference].self, forKey: platform) ?? [] let frameworks = Array(Set(references.map { $0.name })).sorted() data[platform] = frameworks diff --git a/Sources/XcodeGenKit/PBXProjGenerator.swift b/Sources/XcodeGenKit/PBXProjGenerator.swift index eaca29f0..6d819c74 100644 --- a/Sources/XcodeGenKit/PBXProjGenerator.swift +++ b/Sources/XcodeGenKit/PBXProjGenerator.swift @@ -518,15 +518,14 @@ public class PBXProjGenerator { ) } - if dependency.link ?? true { let buildFile = addObject( PBXBuildFile(file: fileReference, settings: getDependencyFrameworkSettings(dependency: dependency)) ) - + targetFrameworkBuildFiles.append(buildFile) } - + if !frameworkFiles.contains(fileReference) { frameworkFiles.append(fileReference) } diff --git a/Sources/XcodeGenKit/PathExtensions.swift b/Sources/XcodeGenKit/PathExtensions.swift index b74d5cef..0e0546ce 100644 --- a/Sources/XcodeGenKit/PathExtensions.swift +++ b/Sources/XcodeGenKit/PathExtensions.swift @@ -13,7 +13,7 @@ extension Path { public func simplifyingParentDirectoryReferences() -> Path { return normalize().components.reduce(Path(), +) } - + /// Returns the relative path necessary to go from `base` to `self`. /// /// Both paths must be absolute or relative paths. @@ -26,13 +26,13 @@ extension Path { /// It's impossible to determine the path between an absolute and a relative path case unmatchedAbsolutePath } - + func pathComponents(for path: ArraySlice, relativeTo base: ArraySlice, memo: [String]) throws -> [String] { switch (base.first, path.first) { // Base case: Paths are equivalent case (.none, .none): return memo - + // No path to backtrack from case (.none, .some(let rhs)): guard rhs != "." else { @@ -40,11 +40,11 @@ extension Path { return try pathComponents(for: path.dropFirst(), relativeTo: base, memo: memo) } return try pathComponents(for: path.dropFirst(), relativeTo: base, memo: memo + [rhs]) - + // Both sides have a common parent case (.some(let lhs), .some(let rhs)) where lhs == rhs: return try pathComponents(for: path.dropFirst(), relativeTo: base.dropFirst(), memo: memo) - + // `base` has a path to back out of case (.some(let lhs), _): guard lhs != ".." else { @@ -57,11 +57,11 @@ extension Path { return try pathComponents(for: path, relativeTo: base.dropFirst(), memo: memo + [".."]) } } - + guard isAbsolute && base.isAbsolute || !isAbsolute && !base.isAbsolute else { throw PathArgumentError.unmatchedAbsolutePath } - + return Path(components: try pathComponents(for: ArraySlice(simplifyingParentDirectoryReferences().components), relativeTo: ArraySlice(base.simplifyingParentDirectoryReferences().components), memo: [])) diff --git a/Tests/XcodeGenKitTests/CarthageDependencyResolverTests.swift b/Tests/XcodeGenKitTests/CarthageDependencyResolverTests.swift index 21297421..84407904 100644 --- a/Tests/XcodeGenKitTests/CarthageDependencyResolverTests.swift +++ b/Tests/XcodeGenKitTests/CarthageDependencyResolverTests.swift @@ -6,9 +6,7 @@ import PathKit class CarthageDependencyResolverTests: XCTestCase { - override func setUp() { - - } + override func setUp() {} func testBaseBuildPath() { describe { @@ -45,6 +43,7 @@ class CarthageDependencyResolverTests: XCTestCase { } } } + func testBuildPathForPlatform() { describe { $0.it("generates the build path for a given platform") { @@ -75,7 +74,7 @@ class CarthageDependencyResolverTests: XCTestCase { .macOS: ["DependencyFixtureB", "DependencyFixtureA", "CarthageTestFixture"], .watchOS: ["DependencyFixtureA", "DependencyFixtureB", "CarthageTestFixture"], .tvOS: ["CarthageTestFixture", "DependencyFixtureA", "DependencyFixtureB"], - .iOS: ["CarthageTestFixture", "DependencyFixtureA", "DependencyFixtureB"] + .iOS: ["CarthageTestFixture", "DependencyFixtureA", "DependencyFixtureB"], ] try Platform.allCases.forEach { platform in @@ -119,7 +118,7 @@ class CarthageDependencyResolverTests: XCTestCase { let resolver = CarthageDependencyResolver(project: makeTestProject(options: options)) let target = Target(name: "1", type: .application, platform: .iOS, dependencies: [dependency]) let dependencies = resolver.dependencies(for: target) - + try expect(dependencies) == [dependency] } @@ -138,7 +137,7 @@ class CarthageDependencyResolverTests: XCTestCase { } } } - + } private func makeTestProject(with targets: [Target] = [], options: SpecOptions = SpecOptions()) -> Project { diff --git a/Tests/XcodeGenKitTests/PathExtensionsTests.swift b/Tests/XcodeGenKitTests/PathExtensionsTests.swift index 195c2a7a..05661a2d 100644 --- a/Tests/XcodeGenKitTests/PathExtensionsTests.swift +++ b/Tests/XcodeGenKitTests/PathExtensionsTests.swift @@ -3,12 +3,12 @@ import PathKit import XCTest class PathExtensionsTests: XCTestCase { - + func testPathRelativeToPath() { func relativePath(to path: String, from base: String) throws -> String { return try Path(path).relativePath(from: Path(base)).string } - + // These are based on ruby's tests for Pathname#relative_path_from: // https://github.com/ruby/ruby/blob/7c2bbd1c7d40a30583844d649045824161772e36/test/pathname/test_pathname.rb#L297 describe { @@ -22,12 +22,12 @@ class PathExtensionsTests: XCTestCase { try expect(relativePath(to: "/a/", from: "/b")) == "../a" try expect(relativePath(to: "/a/", from: "/b/")) == "../a" } - + $0.it("resolves paths with a common parent") { try expect(relativePath(to: "a/b", from: "a/c")) == "../b" try expect(relativePath(to: "../a", from: "../b")) == "../a" } - + $0.it("resolves dot paths") { try expect(relativePath(to: "a", from: ".")) == "a" try expect(relativePath(to: ".", from: "a")) == ".." @@ -35,7 +35,7 @@ class PathExtensionsTests: XCTestCase { try expect(relativePath(to: "..", from: "..")) == "." try expect(relativePath(to: "..", from: ".")) == ".." } - + $0.it("resolves multi-level paths") { try expect(relativePath(to: "/a/b/c/d", from: "/a/b")) == "c/d" try expect(relativePath(to: "/a/b", from: "/a/b/c/d")) == "../.." @@ -47,12 +47,12 @@ class PathExtensionsTests: XCTestCase { try expect(relativePath(to: "a/..", from: "a")) == ".." try expect(relativePath(to: "a/../b", from: "b")) == "." } - + $0.it("backtracks on a non-normalized base path") { try expect(relativePath(to: "a", from: "b/..")) == "a" try expect(relativePath(to: "b/c", from: "b/..")) == "b/c" } - + $0.it("throws when given unresolvable paths") { try expect(relativePath(to: "/", from: ".")).toThrow() try expect(relativePath(to: ".", from: "/")).toThrow() diff --git a/Tests/XcodeGenKitTests/ProjectSpecTests.swift b/Tests/XcodeGenKitTests/ProjectSpecTests.swift index cc5d6eef..bbb4378a 100644 --- a/Tests/XcodeGenKitTests/ProjectSpecTests.swift +++ b/Tests/XcodeGenKitTests/ProjectSpecTests.swift @@ -117,7 +117,7 @@ class ProjectSpecTests: XCTestCase { project.configFiles = ["missingConfiguration": configPath.string] try project.validate() } - + $0.it("allows non-existent config files") { var project = baseProject project.options = SpecOptions(disabledValidations: [.missingConfigFiles]) diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index 3e190222..492b79ec 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -72,7 +72,7 @@ class SpecLoadingTests: XCTestCase { sources: [ "paths_test/simplesource", TargetSource(path: "paths_test/source", excludes: ["file"]), - ], + ], dependencies: [Dependency(type: .framework, reference: "paths_test/Framework")], info: Plist(path: "paths_test/info"), entitlements: Plist(path: "paths_test/entitlements"), @@ -88,7 +88,7 @@ class SpecLoadingTests: XCTestCase { sources: [ "paths_test/template_source", "source", - ], + ], dependencies: [Dependency(type: .framework, reference: "Framework")], info: Plist(path: "info"), entitlements: Plist(path: "entitlements"), @@ -418,8 +418,8 @@ class SpecLoadingTests: XCTestCase { "sources": ["targetSource"], "templates": ["temp2", "temp"], "templateAttributes": [ - "source": "replacedSource" - ] + "source": "replacedSource", + ], ] let project = try getProjectSpec([ @@ -435,9 +435,9 @@ class SpecLoadingTests: XCTestCase { "deploymentTarget": "1.1.0", "configFiles": [ "debug": "Configs/$target_name/debug.xcconfig", - "release": "Configs/${target_name}/release.xcconfig" + "release": "Configs/${target_name}/release.xcconfig", ], - "sources": ["${source}"] + "sources": ["${source}"], ], ], ]) @@ -477,7 +477,7 @@ class SpecLoadingTests: XCTestCase { "configFiles": ["debug": "Configs/$target_name/debug.xcconfig"], "templates": ["temp", "temp1"], "sources": ["templateSource"], - ] + ], ], ]) @@ -499,8 +499,8 @@ class SpecLoadingTests: XCTestCase { "templateAttributes": [ "temp": "temp-by-target", "a": "a-by-target", - "b": "b-by-target" // This should win over attributes defined in template "temp" - ] + "b": "b-by-target", // This should win over attributes defined in template "temp" + ], ] let project = try getProjectSpec([ @@ -512,15 +512,15 @@ class SpecLoadingTests: XCTestCase { "templateAttributes": [ "b": "b-by-temp", "c": "c-by-temp", - "d": "d-by-temp" - ] + "d": "d-by-temp", + ], ], "a": [ "templates": ["b", "c"], "sources": ["a", "${a}"], "templateAttributes": [ - "c": "c-by-a" - ] + "c": "c-by-a", + ], ], "b": [ "sources": ["b", "${b}"], @@ -532,8 +532,8 @@ class SpecLoadingTests: XCTestCase { "sources": ["d", "${d}"], "templates": ["e"], "templateAttributes": [ - "e": "e-by-d" - ] + "e": "e-by-d", + ], ], "e": [ "sources": ["e", "${e}"], @@ -582,7 +582,7 @@ class SpecLoadingTests: XCTestCase { "configFiles": ["debug": "Configs/$target_name/debug.xcconfig"], "templates": ["temp", "temp1"], "sources": ["templateSource"], - ] + ], ], ]) @@ -593,23 +593,23 @@ class SpecLoadingTests: XCTestCase { try expect(target.sources) == ["nestedTemplateSource2", "nestedTemplateSource1", "templateSource", "targetSource"] // merges array in order try expect(target.configFiles["debug"]) == "Configs/Framework/debug.xcconfig" // replaces $target_name } - + $0.it("parses cross platform target templates") { - + let project = try getProjectSpec([ "targets": [ "Framework": [ "type": "framework", "templates": ["temp"], - ] + ], ], "targetTemplates": [ "temp": [ "platform": ["iOS", "tvOS"], - ] + ], ], - ]) - + ]) + let iOSTarget = project.targets.first { $0.platform == .iOS } let tvOSTarget = project.targets.first { $0.platform == .tvOS } try expect(iOSTarget?.type) == .framework @@ -624,7 +624,7 @@ class SpecLoadingTests: XCTestCase { "type": "framework", "platform": ["iOS", "tvOS"], "templates": ["$platform"], - ] + ], ], "targetTemplates": [ "iOS": [ @@ -632,9 +632,9 @@ class SpecLoadingTests: XCTestCase { ], "tvOS": [ "sources": "B", - ] + ], ], - ]) + ]) let iOSTarget = project.targets.first { $0.platform == .iOS } let tvOSTarget = project.targets.first { $0.platform == .tvOS } @@ -910,7 +910,7 @@ class SpecLoadingTests: XCTestCase { "createIntermediateGroups": true, "developmentLanguage": "ja", "deploymentTarget": ["iOS": 11.1, "tvOS": 10.0, "watchOS": "3", "macOS": "10.12.1"], - "findCarthageFrameworks": true + "findCarthageFrameworks": true, ]] let parsedSpec = try getProjectSpec(dictionary) try expect(parsedSpec) == expected