Skip to content

Refactor Build/describe() with Buildable protocol #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/Build/describe().swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
let prefix = try mkdir(prefix, conf.dirname)
let yaml = try YAML(path: "\(prefix).yaml")
let write = yaml.write
let (tests, nontests) = targetSplitter(modules, products)

let (buildableTests, buildableNonTests) = (modules.map{$0 as Buildable} + products.map{$0 as Buildable}).partition{$0.isTest}
let (tests, nontests) = (buildableTests.map{$0.targetName}, buildableNonTests.map{$0.targetName})

defer { yaml.close() }

Expand Down
31 changes: 18 additions & 13 deletions Sources/Build/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,22 @@ func infoPlist(test: Product) -> String {
return s
}

// this function because I couldn't make a Buildable
// protocol and then implement an isTest function
// without Swift runtime erroring about "Could not
// convert Array from Objective-C.
// FIXME please improve!
func targetSplitter(modules: [Module], _ products: [Product]) -> ([String], [String]) {
let (testmodules, nontestmodules) = modules.partition{ $0 is TestModule }
let (testproducts, nontestproducts) = products.partition{ if case .Test = $0.type { return true } else { return false } }

let one = testmodules.map{$0.targetName} + testproducts.map{$0.targetName}
let two = nontestmodules.map{$0.targetName} + nontestproducts.map{$0.targetName}

return (one, two)
protocol Buildable {
var targetName: String { get }
var isTest: Bool { get }
}

extension Module: Buildable {
var isTest: Bool {
return self is TestModule
}
}

extension Product: Buildable {
var isTest: Bool {
if case .Test = type {
return true
}
return false
}
}