-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Project.swift
218 lines (211 loc) · 8.16 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import ProjectDescription
import Foundation
import Env
// MARK: - Project
let bundleId = "com.zenangst.Keyboard-Cowboy"
func xcconfig(_ targetName: String) -> String { "Configurations/\(targetName).xcconfig" }
func sources(_ folder: String) -> SourceFilesList { "\(folder)/Sources/**" }
func resources(_ folder: String) -> ResourceFileElements { "\(folder)/Resources/**" }
let rootPath = URL(fileURLWithPath: String(#filePath))
.deletingLastPathComponent()
.absoluteString
.replacingOccurrences(of: "file://", with: "")
let assetPath = rootPath.appending("Assets")
let envPath = rootPath.appending(".env")
let env = EnvHelper(envPath)
let shell = Shell(path: rootPath)
let buildNumber = (try? shell.run("git rev-list --count HEAD")) ?? "x.x.x"
// Main application target
let mainAppTarget = Target.target(
name: "Keyboard-Cowboy",
destinations: .macOS,
product: .app,
bundleId: "com.zenangst.Keyboard-Cowboy",
deploymentTargets: .macOS("13.0"),
infoPlist: .file(path: .relativeToRoot("App/Info.plist")),
sources: sources("App"),
resources: resources("App"),
entitlements: "App/Entitlements/com.zenangst.Keyboard-Cowboy.entitlements",
dependencies: [
.package(product: "AXEssibility"),
.package(product: "Apps"),
.package(product: "Bonzai"),
.package(product: "Dock"),
.package(product: "DynamicNotchKit"),
.package(product: "Inject"),
.package(product: "InputSources"),
.package(product: "Intercom"),
.package(product: "KeyCodes"),
.package(product: "LaunchArguments"),
.package(product: "MachPort"),
.package(product: "Sparkle"),
.package(product: "Windows"),
],
settings:
Settings.settings(
base: [
"ASSETCATALOG_COMPILER_APPICON_NAME": "AppIcon",
"CODE_SIGN_IDENTITY": "Apple Development",
"CODE_SIGN_STYLE": "Automatic",
"CURRENT_PROJECT_VERSION": SettingValue(stringLiteral: buildNumber),
"DEVELOPMENT_TEAM": env["TEAM_ID"],
"ENABLE_HARDENED_RUNTIME": true,
"MARKETING_VERSION": "3.25.1",
"PRODUCT_NAME": "Keyboard Cowboy"
],
configurations: [
.debug(name: "Debug", xcconfig: "\(xcconfig("Debug"))"),
.release(name: "Release", xcconfig: "\(xcconfig("Release"))")
],
defaultSettings: .recommended)
)
// Unit Tests
let unitTestTarget = Target.target(
name: "UnitTests",
destinations: .macOS,
product: .unitTests,
bundleId: bundleId.appending(".unit-tests"),
deploymentTargets: .macOS("13.0"),
infoPlist: .file(path: .relativeToRoot("UnitTests/Info.plist")),
sources: sources("UnitTests"),
dependencies: [
.target(name: "Keyboard-Cowboy")
],
settings:
Settings.settings(base: [
"BUNDLE_LOADER": "$(TEST_HOST)",
"CODE_SIGN_IDENTITY": "Apple Development",
"CODE_SIGN_STYLE": "-",
"DEVELOPMENT_TEAM": env["TEAM_ID"],
"PRODUCT_BUNDLE_IDENTIFIER": "\(bundleId).UnitTests",
"TEST_HOST": "$(BUILT_PRODUCTS_DIR)/Keyboard Cowboy.app/Contents/MacOS/Keyboard Cowboy",
])
)
let assetGeneratorTarget = Target.target(
name: "AssetGenerator",
destinations: .macOS,
product: .unitTests,
bundleId: bundleId.appending(".asset-generator"),
deploymentTargets: .macOS("13.0"),
infoPlist: .file(path: .relativeToRoot("AssetGenerator/Info.plist")),
sources: sources("AssetGenerator"),
dependencies: [
.target(name: "Keyboard-Cowboy")
],
settings:
Settings.settings(base: [
"BUNDLE_LOADER": "$(TEST_HOST)",
"CODE_SIGN_IDENTITY": "Apple Development",
"CODE_SIGN_STYLE": "-",
"DEVELOPMENT_TEAM": env["TEAM_ID"],
"PRODUCT_BUNDLE_IDENTIFIER": "\(bundleId).AssetGenerator",
"TEST_HOST": "$(BUILT_PRODUCTS_DIR)/Keyboard Cowboy.app/Contents/MacOS/Keyboard Cowboy",
])
)
let project = Project(
name: "Keyboard Cowboy",
options: Project.Options.options(
textSettings: .textSettings(indentWidth: 2,
tabWidth: 2)),
packages: PackageResolver.packages(env),
settings: Settings.settings(configurations: [
.debug(name: "Debug", xcconfig: "\(xcconfig("Debug"))"),
.release(name: "Release", xcconfig: "\(xcconfig("Release"))")
], defaultSettings: .recommended),
targets: [
mainAppTarget,
unitTestTarget,
assetGeneratorTarget
],
schemes: [
Scheme.scheme(
name: mainAppTarget.name,
shared: true,
hidden: false,
buildAction: .buildAction(targets: [.target(mainAppTarget.name)]),
testAction: .targets(
[.testableTarget(target: .target(unitTestTarget.name))],
arguments: .arguments(
environmentVariables: [
"ASSET_PATH": .environmentVariable(value: assetPath, isEnabled: true),
"SOURCE_ROOT": .environmentVariable(value: rootPath, isEnabled: true),
],
launchArguments: [
.launchArgument(name: "-running-unit-tests", isEnabled: true)
])
,
options: .options(
coverage: true,
codeCoverageTargets: [.target(mainAppTarget.name)]
)
),
runAction: .runAction(
executable: .target(mainAppTarget.name),
arguments: .arguments(
environmentVariables: [
"APP_ENVIRONMENT_OVERRIDE": .environmentVariable(value: "development", isEnabled: true),
"SOURCE_ROOT": .environmentVariable(value: rootPath, isEnabled: true),
],
launchArguments: [
.launchArgument(name: "-benchmark", isEnabled: false),
.launchArgument(name: "-debugEditing", isEnabled: false),
.launchArgument(name: "-injection", isEnabled: false),
.launchArgument(name: "-disableMachPorts", isEnabled: false),
]
)
)
)
],
additionalFiles: [
.glob(pattern: .path( ".env")),
.glob(pattern: .path( ".github/workflows")),
.glob(pattern: .path( ".gitignore")),
.glob(pattern: .path( "ci_scripts")),
.glob(pattern: .path( "Fixtures")),
.glob(pattern: .path( "Project.swift")),
.glob(pattern: .path( "README.md")),
.glob(pattern: .path( "Tuist/Dependencies.swift")),
.glob(pattern: .path( "appcast.xml")),
.glob(pattern: .path( "gh-pages")),
.glob(pattern: .path( "_RELEASE_NOTES.md")),
]
)
public enum PackageResolver {
public static func packages(_ env: EnvHelper) -> [Package] {
let packages: [Package]
if env["PACKAGE_DEVELOPMENT"] == "true" {
packages = [
.package(url: "https://github.com/krzysztofzablocki/Inject.git", from: "1.5.2"),
.package(url: "https://github.com/sparkle-project/Sparkle.git", from: "2.4.1"),
.package(path: "../AXEssibility"),
.package(path: "../Apps"),
.package(path: "../Bonzai"),
.package(path: "../Dock"),
.package(path: "../DynamicNotchKit"),
.package(path: "../InputSources"),
.package(path: "../Intercom"),
.package(path: "../KeyCodes"),
.package(path: "../LaunchArguments"),
.package(path: "../MachPort"),
.package(path: "../Windows"),
]
} else {
packages = [
.package(url: "https://github.com/krzysztofzablocki/Inject.git", from: "1.5.2"),
.package(url: "https://github.com/sparkle-project/Sparkle.git", from: "2.4.1"),
.package(url: "https://github.com/zenangst/AXEssibility.git", from: "0.1.3"),
.package(url: "https://github.com/zenangst/Bonzai.git", .revision("e8bb0b48cce45ab33de90982ce107ca5cad51c02")),
.package(url: "https://github.com/zenangst/Apps.git", from: "1.4.2"),
.package(url: "https://github.com/zenangst/Dock.git", from: "1.0.1"),
.package(url: "https://github.com/MrKai77/DynamicNotchKit", .revision("6c12b5bc1ecb9776419ed2f2747cc9a1132af8bc")),
.package(url: "https://github.com/zenangst/InputSources.git", from: "1.0.1"),
.package(url: "https://github.com/zenangst/Intercom.git", .revision("5a340e185e571d058c09ab8b8ad8716098282443")),
.package(url: "https://github.com/zenangst/KeyCodes.git", from: "4.1.1"),
.package(url: "https://github.com/zenangst/LaunchArguments.git", from: "1.0.2"),
.package(url: "https://github.com/zenangst/MachPort.git", from: "4.2.0"),
.package(url: "https://github.com/zenangst/Windows.git", from: "1.2.1"),
]
}
return packages
}
}