Skip to content

Commit b30319e

Browse files
devxoulkzaher
authored andcommitted
Update to PackageDescriptionV4
1 parent a0bf386 commit b30319e

File tree

1 file changed

+53
-73
lines changed

1 file changed

+53
-73
lines changed

Package.swift

Lines changed: 53 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,64 @@
1+
// swift-tools-version:4.0
2+
13
import PackageDescription
2-
import Foundation
34

45
let buildTests = false
5-
let RxTestIsTarget = buildTests || ProcessInfo.processInfo.environment["TEST"] == "1"
6-
7-
#if os(Linux)
8-
let rxCocoaDependencies: [Target.Dependency] = [
9-
.Target(name: "RxSwift"),
10-
]
11-
#else
12-
let rxCocoaDependencies: [Target.Dependency] = [
13-
.Target(name: "RxSwift"),
14-
.Target(name: "RxCocoaRuntime"),
15-
]
16-
#endif
176

18-
let library = [
19-
Target(
20-
name: "RxSwift"
21-
),
22-
Target(
23-
name: "RxBlocking",
24-
dependencies: [
25-
.Target(name: "RxSwift")
26-
]
27-
),
28-
Target(
29-
name: "RxCocoa",
30-
dependencies: rxCocoaDependencies
31-
)
32-
] + (RxTestIsTarget ? [
33-
Target(
34-
name: "RxTest",
35-
dependencies: [
36-
.Target(name: "RxSwift")
37-
]
38-
),
39-
] : [])
40-
41-
#if os(Linux)
42-
let cocoaRuntime: [Target] = []
43-
#else
44-
let cocoaRuntime: [Target] = [
45-
Target(
46-
name: "RxCocoaRuntime",
47-
dependencies: [
48-
.Target(name: "RxSwift")
49-
]
50-
)
51-
]
52-
#endif
7+
func filterNil<T>(_ array: [T?]) -> [T] {
8+
return array.flatMap { $0 }
9+
}
5310

54-
let tests: [Target] = (buildTests ? [
55-
Target(
56-
name: "AllTestz",
57-
dependencies: [
58-
.Target(name: "RxSwift"),
59-
.Target(name: "RxBlocking"),
60-
.Target(name: "RxTest"),
61-
.Target(name: "RxCocoa")
62-
]
63-
)
64-
] : [])
11+
extension Product {
12+
static func allTests() -> Product? {
13+
if buildTests {
14+
return .executable(name: "AllTestz", targets: ["AllTestz"])
15+
} else {
16+
return nil
17+
}
18+
}
19+
}
6520

66-
let testExcludes: [String] = (buildTests ? [] : ["Sources/AllTestz"]) + (RxTestIsTarget ? [] : ["Sources/RxTest"])
21+
extension Target {
22+
static func rxCocoa() -> Target? {
23+
#if os(Linux)
24+
return .target(name: "RxCocoa", dependencies: ["RxSwift"])
25+
#else
26+
return .target(name: "RxCocoa", dependencies: ["RxSwift", "RxCocoaRuntime"])
27+
#endif
28+
}
6729

68-
#if os(Linux)
30+
static func rxCocoaRuntime() -> Target? {
31+
#if os(Linux)
32+
return nil
33+
#else
34+
return .target(name: "RxCocoaRuntime", dependencies: ["RxSwift"])
35+
#endif
36+
}
6937

70-
let excludes: [String] = [
71-
"Tests",
72-
"Sources/RxCocoaRuntime",
73-
] + testExcludes
74-
#else
75-
let excludes: [String] = [
76-
"Tests",
77-
] + testExcludes
78-
#endif
38+
static func allTests() -> Target? {
39+
if buildTests {
40+
return .target(name: "AllTestz", dependencies: ["RxSwift", "RxCocoa", "RxBlocking", "RxTest"])
41+
} else {
42+
return nil
43+
}
44+
}
45+
}
7946

8047
let package = Package(
81-
name: "RxSwift",
82-
targets: library + cocoaRuntime + tests,
83-
exclude: excludes
48+
name: "RxSwift",
49+
products: filterNil([
50+
.library(name: "RxSwift", targets: ["RxSwift"]),
51+
.library(name: "RxCocoa", targets: ["RxCocoa"]),
52+
.library(name: "RxBlocking", targets: ["RxBlocking"]),
53+
.library(name: "RxTest", targets: ["RxTest"]),
54+
.allTests(),
55+
]),
56+
targets: filterNil([
57+
.target(name: "RxSwift", dependencies: []),
58+
.rxCocoa(),
59+
.rxCocoaRuntime(),
60+
.target(name: "RxBlocking", dependencies: ["RxSwift"]),
61+
.target(name: "RxTest", dependencies: ["RxSwift"]),
62+
.allTests(),
63+
])
8464
)

0 commit comments

Comments
 (0)