-
Notifications
You must be signed in to change notification settings - Fork 179
/
Project.swift
130 lines (119 loc) · 4.63 KB
/
Project.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import ProjectDescription
import ProjectDescriptionHelpers
let commonBuildSettingsBase: [String: SettingValue] = [
"PRODUCT_NAME": .string("Cuckoo"),
"SYSTEM_FRAMEWORK_SEARCH_PATHS": .string("$(PLATFORM_DIR)/Developer/Library/Frameworks"),
]
let mocksBuildSettingsBase: [String: SettingValue] = [
"PRODUCT_NAME": .string("CuckooMocks"),
"SYSTEM_FRAMEWORK_SEARCH_PATHS": .string("$(PLATFORM_DIR)/Developer/Library/Frameworks"),
]
let objCBuildSettingsBase: [String: SettingValue] = [
"SWIFT_OBJC_BRIDGING_HEADER": .string("$(PROJECT_DIR)/OCMock/Cuckoo-BridgingHeader.h"),
]
func platformSet(platform: PlatformType) -> (targets: [Target], schemes: [Scheme]) {
var targets: [Target] = []
var schemes: [Scheme] = []
// MARK: Swift targets.
let defaultTarget = Target.target(
name: "Cuckoo-\(platform)",
destinations: platform.destinations,
product: .framework,
bundleId: "org.brightify.Cuckoo",
deploymentTargets: platform.deploymentTargets,
infoPlist: .default,
sources: [
"Source/**",
"OCMock/**",
],
headers: .headers(public: ["OCMock/**"]),
dependencies: [
.sdk(name: "XCTest", type: .framework, status: .optional),
.package(product: "OCMock"),
],
settings: Settings.settings(base: commonBuildSettingsBase.merging(objCBuildSettingsBase, uniquingKeysWith: { $1 }))
)
targets.append(defaultTarget)
let mocksTarget = Target.target(
name: "Cuckoo-\(platform)Tests-Mocks",
destinations: platform.destinations,
product: .framework,
bundleId: "org.brightify.Cuckoo",
deploymentTargets: platform.deploymentTargets,
infoPlist: .default,
sources: [
"Tests/Swift/Generated/*.swift",
"Tests/Swift/Source/*.swift",
],
scripts: [
.pre(
// Any changes in the mock generation phase should be reflected in `Generator/Project.swift` as well.
script: """
if [ "$GENERATE_TEST_MOCKS" = "NO" ] ; then exit; fi
# Make sure the generator is up-to-date.
echo 'Building generator.'
"$PROJECT_DIR"/build_generator
echo 'Generating mocks.'
\([
#""$PROJECT_DIR"/Generator/bin/cuckoonator"#,
"--verbose",
].joined(separator: " \\\n\t"))
""",
name: "Generate mocks",
basedOnDependencyAnalysis: false
),
],
dependencies: [
.target(defaultTarget),
.sdk(name: "XCTest", type: .framework, status: .optional),
],
settings: Settings.settings(base: mocksBuildSettingsBase)
)
targets.append(mocksTarget)
let defaultTestTarget = Target.target(
name: "Cuckoo-\(platform)Tests",
destinations: platform.destinations,
product: .unitTests,
bundleId: "org.brightify.Cuckoo",
deploymentTargets: platform.deploymentTargets,
infoPlist: .default,
sources: SourceFilesList.sourceFilesList(globs: [
.glob("Tests/Common/**"),
.glob("Tests/OCMock/**"),
.glob("Tests/Swift/**", excluding: [
"Tests/Swift/Generated/*.swift",
"Tests/Swift/Source/*.swift",
]),
]),
dependencies: [
.target(defaultTarget),
.target(mocksTarget),
.package(product: "OCMock"),
]
)
targets.append(defaultTestTarget)
// MARK: Schemes.
schemes.append(
Scheme.scheme(
name: defaultTarget.name,
buildAction: BuildAction.buildAction(targets: [defaultTarget.reference, mocksTarget.reference]),
testAction: TestAction.targets([TestableTarget.testableTarget(target: defaultTestTarget.reference)])
)
)
return (targets, schemes)
}
let (iOSTargets, iOSSchemes) = platformSet(platform: .iOS)
let (macOSTargets, macOSSchemes) = platformSet(platform: .macOS)
let (tvOSTargets, tvOSSchemes) = platformSet(platform: .tvOS)
let (watchOSTargets, watchOSSchemes) = platformSet(platform: .watchOS)
// MARK: project definition
let project = Project(
name: "Cuckoo",
options: .options(automaticSchemesOptions: .disabled, disableSynthesizedResourceAccessors: true),
packages: [
.local(path: "OCMockWrapper"),
],
settings: Settings.settings(base: ["GENERATE_TEST_MOCKS": "YES"]),
targets: iOSTargets + macOSTargets + tvOSTargets + watchOSTargets,
schemes: iOSSchemes + macOSSchemes + tvOSSchemes + watchOSSchemes
)