Skip to content

Commit f21e322

Browse files
committed
Refactor with Builable protocol
1 parent 8e409c1 commit f21e322

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

Sources/Build/describe().swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public func describe(prefix: String, _ conf: Configuration, _ modules: [Module],
2727
let prefix = try mkdir(prefix, conf.dirname)
2828
let yaml = try YAML(path: "\(prefix).yaml")
2929
let write = yaml.write
30-
let (tests, nontests) = targetSplitter(modules, products)
30+
31+
let (buildableTests, buildableNonTests) = (modules.map{$0 as Buildable} + products.map{$0 as Buildable}).partition{$0.isTest}
32+
let (tests, nontests) = (buildableTests.map{$0.targetName}, buildableNonTests.map{$0.targetName})
3133

3234
defer { yaml.close() }
3335

Sources/Build/misc.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,22 @@ func infoPlist(test: Product) -> String {
107107
return s
108108
}
109109

110-
// this function because I couldn't make a Buildable
111-
// protocol and then implement an isTest function
112-
// without Swift runtime erroring about "Could not
113-
// convert Array from Objective-C.
114-
// FIXME please improve!
115-
func targetSplitter(modules: [Module], _ products: [Product]) -> ([String], [String]) {
116-
let (testmodules, nontestmodules) = modules.partition{ $0 is TestModule }
117-
let (testproducts, nontestproducts) = products.partition{ if case .Test = $0.type { return true } else { return false } }
118-
119-
let one = testmodules.map{$0.targetName} + testproducts.map{$0.targetName}
120-
let two = nontestmodules.map{$0.targetName} + nontestproducts.map{$0.targetName}
121-
122-
return (one, two)
110+
protocol Buildable {
111+
var targetName: String { get }
112+
var isTest: Bool { get }
113+
}
114+
115+
extension Module: Buildable {
116+
var isTest: Bool {
117+
return self is TestModule
118+
}
119+
}
120+
121+
extension Product: Buildable {
122+
var isTest: Bool {
123+
if case .Test = type {
124+
return true
125+
}
126+
return false
127+
}
123128
}

0 commit comments

Comments
 (0)