-
Notifications
You must be signed in to change notification settings - Fork 49
/
BUILD.bazel
281 lines (260 loc) · 7.73 KB
/
BUILD.bazel
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@build_bazel_rules_apple//apple:macos.bzl",
"macos_application",
)
load(
"@build_bazel_rules_apple//apple:resources.bzl",
"apple_resource_bundle",
"apple_resource_group",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_library",
)
load(
"@build_bazel_rules_apple//apple:versioning.bzl",
"apple_bundle_version",
)
load(
"@com_github_bazelbuild_buildtools//buildifier:def.bzl",
"buildifier",
)
load(
"//third_party:repositories.bzl",
"namespaced_name",
)
load(
"//:BazelExtensions/xchammerconfig.bzl",
"execution_action",
"gen_xchammer_config",
"project_config",
"scheme_action_config",
"target_config",
"xchammer_config",
)
apple_resource_group(
name = "XCHammerAssets",
structured_resources = glob([
"XCHammerAssets/**",
]),
)
# Build system support. Currently, we use the example xcbuildkit
# to simply show the progress bar.
# Stick this into a bundle to group files together
apple_resource_bundle(
name = "XCBuildKit",
resources = [
"@xcbuildkit//:BazelBuildServiceInstaller",
"@xcbuildkit//:BuildInfo",
# We use this to check if it's installed into each Xcode
"@bazel_tools//tools/osx:xcode-locator-genrule",
],
)
load(
"//:BazelExtensions/xcode_configuration_provider.bzl",
"declare_target_config",
)
load(
"@build_bazel_rules_apple//apple:resources.bzl",
"apple_resource_group",
)
# Note:
# - $(SPAWN_OPTS) is determined at build time by tools/XCHammerXcodeRunscript.sh
# XCHammer's `bazel`, tools/bazelwrapper subs out make variable
xchammer_xcode_target_config = target_config(
build_bazel_options = "$(SPAWN_OPTS)",
build_bazel_template = "tools/XCHammerXcodeRunscript.sh",
)
# This is an example of declaring a target config.
declare_target_config(
name = "XCHammerSourcesXcodeConfig",
config = xchammer_xcode_target_config,
)
# This BUILD file is not actually imported into XCHammer
# There is already a BUILD file placed in there by another dep.
apple_resource_group(
name = "BazelExtensions",
structured_resources = glob([
"BazelExtensions/*.bzl",
]),
)
swift_library(
name = "XCHammerSources",
srcs = glob(["Sources/**/*.swift"]),
copts = [
"-swift-version",
"4.2",
],
data = [
":XCHammerAssets",
":BazelExtensions",
] + [
":XCBuildKit",
],
deps = ["@" + namespaced_name(x) for x in [
"AEXML//:AEXML",
"Commandant//:Commandant",
"Commander//:Commander",
"JSONUtilities//:JSONUtilities",
"PathKit//:PathKit",
"Rainbow//:Rainbow",
"Result//:Result",
"ShellOut//:ShellOut",
"Tulsi//src/TulsiGenerator:tulsi_generator_lib",
"XcodeGen//:XcodeGenKit",
"XcodeGen//:ProjectSpec",
"XcodeProj//:XcodeProj",
"Yams//:Yams",
]] + [":XCHammerSourcesXcodeConfig"],
)
apple_bundle_version(
name = "XCHammerVersion",
build_version = "1.0",
)
macos_application(
name = "xchammer",
bundle_id = "com.pinterest.xchammer",
infoplists = ["Info.plist"],
minimum_os_version = "10.14",
version = ":XCHammerVersion",
deps = [
":XCHammerSources",
":XCHammerSourcesXcodeConfig",
],
)
buildifier(
name = "buildifier",
)
script_base = "$SRCROOT/tools/instrumentation_helpers"
scheme_config = {
"Build": scheme_action_config(
post_actions = [
execution_action(
name = "Report build end",
script = "python " + script_base + "/statsd_post_build_action.py",
),
],
pre_actions = [
execution_action(
name = "Track build start",
script = script_base + "/statsd_pre_build_action.sh",
),
],
),
}
# XCHammer config for the CLI build project
# For large projects, we'd want to use the xcode_project rule
# and let the `xcode_project` rule aggregate the config options.
gen_xchammer_config(
name = "xchammer_config",
config = xchammer_config(
projects = {
"xchammer": project_config(paths = ["**"]),
},
target_config = {
"//:xchammer": xchammer_xcode_target_config,
"//tools/XCConfigExporter:xcconfig-exporter": xchammer_xcode_target_config,
},
targets = [
"//:xchammer",
"//tools/XCConfigExporter:xcconfig-exporter",
],
),
)
# Xcode project for Bazel built project
load(
"//:BazelExtensions/xcodeproject.bzl",
"xcode_project",
)
# The xcode_project for Bazel built Xcode project
# Note: the target_config is declared in :XCHammerSourcesXcodeConfig
xcode_project(
name = "workspace_v2",
bazel = "tools/bazelwrapper",
project_config = project_config(
generate_xcode_schemes = False,
paths = ["**"],
xcconfig_overrides = {
"Release": "tools/BazelToolchain.xcconfig",
"Debug": "tools/BazelToolchain.xcconfig",
"Profile": "tools/BazelToolchain.xcconfig",
},
),
targets = [
"//:xchammer",
"//tools/XCConfigExporter:xcconfig-exporter",
],
)
# Development / Distribution
genrule(
name = "xchammer_unzip",
srcs = [":xchammer"],
outs = ["xchammer_unzip"],
cmd = "unzip -q $(SRCS) -d $(OUTS)",
)
# This produces the same interface as the XCHammer repository, so a person
# could use a distribution artifact or a source build without changing thier
# build files
# Building XCHammer ( or any decently complex tool using external deps ) from
# source isn't suggested as it will involve making sure your iOS env has the
# same bazel, Xcode version installed, and all transitive deps in the
# WORKSPACE. Outside of being difficulto update/manage, it's also very
# cumbersome in Bazel
# https://github.com/bazelbuild/bazel/issues/1550
# The current API is
# :xchammer ( excutable binary )
# BazelExtensions/*.bzl ( related bazel API )
# Usage:
# http_archive(
# name = "xchammer",
# urls = ["file:////path/to/xchammer/bazel-bin/xchammer_dist.zip"]
# )
gen_workspace_cmd = """
touch BUILD
RESOURCES=xchammer.app/Contents/Resources
ln -s $$RESOURCES/BazelExtensions BazelExtensions
sed -i '' 's,@xchammer_tulsi_aspects//,,g' BazelExtensions/tulsi.bzl
ln -s $$RESOURCES/tulsi tulsi
touch WORKSPACE
echo 'sh_binary(name="xchammer", srcs=["xchammer.app/Contents/MacOS/xchammer"], visibility=["//visibility:public"])' > BUILD
"""
genrule(
name = "xchammer_dist",
srcs = [":xchammer_unzip"],
outs = ["xchammer_dist_repo.zip"],
cmd = """
mkdir zipdir/
cp -r $(SRCS)/xchammer.app zipdir/xchammer.app
cd zipdir
{gen_workspace_cmd}
zip -q ../$(OUTS) -r .
""".format(gen_workspace_cmd = gen_workspace_cmd),
)
# Builds an xchammer WORKSPACE use for local development. By creating a symlink
# to the build artifact to ensure the upstream repository is using the latest
# artifacts.
#
# If we were to just use `xchammer_dist` Bazel will not check a `.zip` of an
# http_archive, so this symlinks the files instead.
#
# TODO: migrate to tree artifacts and load the `.app` directly
# ( --define "apple.experimental.tree_artifact_outputs=True" )
#
# local_repository(
# name = "xchammer",
# path = "/path/to/xchammer/bazel-bin/xchammer_dev_repo/"
# )
# --override_repository=xchammer=/path/to/xchammer/bazel-bin/xchammer_dev_repo/
genrule(
name = "xchammer_dev",
srcs = [":xchammer"],
outs = ["xchammer_dev_repo"],
cmd = """
mkdir $(OUTS)
ln -s $$(dirname $$PWD/$(SRCS))/xchammer_archive-root/xchammer.app $(OUTS)/xchammer.app
cd $(OUTS)
{gen_workspace_cmd}
""".format(gen_workspace_cmd = gen_workspace_cmd),
)