|
| 1 | +// swift-tools-version:4.0 |
| 2 | + |
1 | 3 | import PackageDescription
|
2 |
| -import Foundation |
3 | 4 |
|
4 | 5 | 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 |
17 | 6 |
|
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 | +} |
53 | 10 |
|
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 | +} |
65 | 20 |
|
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 | + } |
67 | 29 |
|
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 | + } |
69 | 37 |
|
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 | +} |
79 | 46 |
|
80 | 47 | 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 | + ]) |
84 | 64 | )
|
0 commit comments