Skip to content

Commit

Permalink
Swiftformat
Browse files Browse the repository at this point in the history
  • Loading branch information
yonaskolb committed Mar 25, 2019
1 parent 0d81d8e commit fa156c1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 59 deletions.
14 changes: 7 additions & 7 deletions Sources/XcodeGenKit/CarthageDependencyResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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(
Expand All @@ -109,7 +109,7 @@ public class CarthageDependencyResolver {
link: dependency.link,
implicit: dependency.implicit,
weakLink: dependency.weakLink
)}
) }
.sorted(by: { $0.reference < $1.reference })
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/XcodeGenKit/CarthageVersionLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions Sources/XcodeGenKit/PBXProjGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/XcodeGenKit/PathExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -26,25 +26,25 @@ extension Path {
/// It's impossible to determine the path between an absolute and a relative path
case unmatchedAbsolutePath
}

func pathComponents(for path: ArraySlice<String>, relativeTo base: ArraySlice<String>, 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 {
// Skip . instead of appending it
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 {
Expand All @@ -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: []))
Expand Down
11 changes: 5 additions & 6 deletions Tests/XcodeGenKitTests/CarthageDependencyResolverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import PathKit

class CarthageDependencyResolverTests: XCTestCase {

override func setUp() {

}
override func setUp() {}

func testBaseBuildPath() {
describe {
Expand Down Expand Up @@ -45,6 +43,7 @@ class CarthageDependencyResolverTests: XCTestCase {
}
}
}

func testBuildPathForPlatform() {
describe {
$0.it("generates the build path for a given platform") {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
}

Expand All @@ -138,7 +137,7 @@ class CarthageDependencyResolverTests: XCTestCase {
}
}
}

}

private func makeTestProject(with targets: [Target] = [], options: SpecOptions = SpecOptions()) -> Project {
Expand Down
14 changes: 7 additions & 7 deletions Tests/XcodeGenKitTests/PathExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,20 +22,20 @@ 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")) == ".."
try expect(relativePath(to: ".", from: ".")) == "."
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")) == "../.."
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Tests/XcodeGenKitTests/ProjectSpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
52 changes: 26 additions & 26 deletions Tests/XcodeGenKitTests/SpecLoadingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -418,8 +418,8 @@ class SpecLoadingTests: XCTestCase {
"sources": ["targetSource"],
"templates": ["temp2", "temp"],
"templateAttributes": [
"source": "replacedSource"
]
"source": "replacedSource",
],
]

let project = try getProjectSpec([
Expand All @@ -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}"],
],
],
])
Expand Down Expand Up @@ -477,7 +477,7 @@ class SpecLoadingTests: XCTestCase {
"configFiles": ["debug": "Configs/$target_name/debug.xcconfig"],
"templates": ["temp", "temp1"],
"sources": ["templateSource"],
]
],
],
])

Expand All @@ -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([
Expand All @@ -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}"],
Expand All @@ -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}"],
Expand Down Expand Up @@ -582,7 +582,7 @@ class SpecLoadingTests: XCTestCase {
"configFiles": ["debug": "Configs/$target_name/debug.xcconfig"],
"templates": ["temp", "temp1"],
"sources": ["templateSource"],
]
],
],
])

Expand All @@ -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
Expand All @@ -624,17 +624,17 @@ class SpecLoadingTests: XCTestCase {
"type": "framework",
"platform": ["iOS", "tvOS"],
"templates": ["$platform"],
]
],
],
"targetTemplates": [
"iOS": [
"sources": "A",
],
"tvOS": [
"sources": "B",
]
],
],
])
])

let iOSTarget = project.targets.first { $0.platform == .iOS }
let tvOSTarget = project.targets.first { $0.platform == .tvOS }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa156c1

Please sign in to comment.