forked from material-components/material-components-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
material_components_ios.bzl
313 lines (284 loc) · 9.56 KB
/
material_components_ios.bzl
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
"""Bazel macros for building MDC component libraries."""
load("@bazel_ios_warnings//:strict_warnings_objc_library.bzl", "strict_warnings_objc_library")
load("@build_bazel_rules_apple//apple/testing/default_runner:ios_test_runner.bzl", "ios_test_runner")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test", "ios_unit_test_suite")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
IOS_MINIMUM_OS = "9.0"
SNAPSHOT_IOS_MINIMUM_OS = "10.0"
SWIFT_VERSION = "4.2"
DEFAULT_IOS_RUNNER_TARGETS = [
"//components/testing/runners:IPAD_PRO_12_9_IN_9_3",
"//components/testing/runners:IPHONE_7_PLUS_IN_10_3",
]
KOKORO_ENVIRONMENT_IOS_RUNNER_TARGET = "//components/testing/runners:IPHONE_X_IN_11_0"
AUTOBOT_ENVIRONMENT_IOS_RUNNER_TARGET = "//components/testing/runners:IPHONE_8_IN_13_0"
SNAPSHOT_IOS_RUNNER_TARGET = "//components/testing/runners:IPHONE_7_IN_11_2"
def mdc_objc_library(
name,
copts = [],
**kwargs):
"""Declare an Objective-C library with strict_warnings_objc_library."""
strict_warnings_objc_library(
name = name,
copts = copts,
**kwargs)
def mdc_public_objc_library(
name,
deps = [],
extra_srcs = [],
sdk_frameworks = [],
visibility = ["//visibility:public"],
**kwargs):
"""Declare a public MDC component as a Objective-C library according to MDC's conventions.
The conventions for an MDC component are:
- The public implementation lives inside of src.
- The private implementation lives inside of src/private.
The default visibility of "//visibility:public" can be overridden, for
example, "//some/package:__subpackages__".
Args:
name: The name of the library.
deps: The dependencies of the library.
extra_srcs: Extra sources to add to the standard ones.
sdk_frameworks: The SDK frameworks needed, e.g. "CoreGraphics".
visibility: The visibility of the package.
**kwargs: Any arguments accepted by _mdc_objc_library().
"""
mdc_objc_library(
name = name,
deps = deps,
sdk_frameworks = sdk_frameworks,
visibility = visibility,
srcs = native.glob(["src/*.m", "src/private/*.h", "src/private/*.m"]) + extra_srcs,
hdrs = native.glob(["src/*.h"]),
includes = ["src"],
enable_modules = 1,
**kwargs)
def mdc_extension_objc_library(
name,
deps = [],
sdk_frameworks = [],
visibility = ["//visibility:public"],
**kwargs):
"""Declare a public MDC component extension as an Objective-C library according to MDC's
conventions.
The conventions for an MDC component extension are:
- The public implementation lives in `src/$name/`.
- The private implementation lives in `src/$name/private`.
The default visibility can be overridden.
Args:
name: The name of the extension. It must match the folder it resides in.
deps: The dependencies of the extension.
sdk_frameworks: Extra SDK frameworks (e.g., CoreGraphics) required by the extension.
visibility: The visibility of the extension.
**kwarrgs: Any arguments accepted by _mdc_objc_library().
"""
mdc_objc_library(
name = name,
deps = deps,
sdk_frameworks = sdk_frameworks,
visibility = visibility,
srcs = native.glob([
"src/" + name + "/*.m",
"src/" + name + "/private/*.m",
"src/" + name + "/private/*.h",
]),
hdrs = native.glob(["src/" + name + "/*.h"]),
includes = ["src/" + name],
enable_modules = 1,
**kwargs)
def mdc_examples_objc_library(
name,
deps = [],
sdk_frameworks = [],
visibility = ["//visibility:public"],
**kwargs):
"""Declare an MDC component examples target as an Objective-C library according to MDC's
conventions.
The conventions for MDC component examples are:
- The source lives in `examples/` and `examples/supplemental/`.
The default visibility can be overridden.
Args:
name: The name of the examples target.
deps: The examples dependencies.
sdk_frameworks: Extra SDK frameworks (e.g., CoreGraphics) required by the examples.
visibility: The visibility of the examples.
**kwarrgs: Any arguments accepted by _mdc_objc_library().
"""
mdc_objc_library(
name = name,
deps = deps,
sdk_frameworks = sdk_frameworks,
visibility = visibility,
srcs = native.glob([
"examples/*.m",
"examples/*.h",
"examples/supplemental/*.m",
"examples/supplemental/*.h",
]),
enable_modules = 1,
**kwargs)
def mdc_examples_swift_library(
name,
deps = [],
visibility = ["//visibility:public"],
**kwargs):
"""Declare an MDC component examples target as a Swift library according to MDC's
conventions.
The conventions for MDC component examples are:
- The source lives in `examples/` and `examples/supplemental/`.
The default visibility can be overridden.
Args:
name: The name of the examples target.
deps: The examples dependencies.
visibility: The visibility of the examples.
**kwarrgs: Any arguments accepted by _mdc_objc_library().
"""
swift_library(
name = name,
deps = deps,
visibility = visibility,
copts = [
"-swift-version",
"4.2",
],
srcs = native.glob([
"examples/*.swift",
"examples/supplemental/*.swift",
]),
**kwargs)
def mdc_unit_test_objc_library(
name,
extra_srcs = [],
deps = [],
sdk_frameworks = [],
visibility = ["//visibility:private"],
testonly = 1,
**kwargs):
"""Declare an mdc_objc_library for unit test sources."""
mdc_objc_library(
name = name,
srcs = native.glob([
"tests/unit/*.m",
"tests/unit/*.h",
]) + extra_srcs,
deps = deps,
sdk_frameworks = ["XCTest"] + sdk_frameworks,
visibility = visibility,
testonly = testonly,
**kwargs)
def mdc_unit_test_swift_library(
name,
extra_srcs = [],
deps = [],
visibility = ["//visibility:private"],
testonly = 1,
**kwargs):
"""Declare a swift_library for unit test sources."""
swift_library(
name = name,
srcs = native.glob(["tests/unit/*.swift"]) + extra_srcs,
deps = deps,
visibility = visibility,
testonly = testonly,
copts = [
"-swift-version",
SWIFT_VERSION,
],
**kwargs)
def mdc_snapshot_objc_library(
name,
extra_srcs = [],
deps = [],
sdk_frameworks = [],
visibility = ["//visibility:private"],
testonly = 1,
**kwargs):
"""Declare an mdc_objc_library for snapshot test source."""
mdc_objc_library(
name = name,
srcs = native.glob([
"tests/snapshot/*.m",
"tests/snapshot/*.h",
"tests/snapshot/supplemental/*.m",
"tests/snapshot/supplemental/*.h",
]) + extra_srcs,
deps = ["//components/private/Snapshot"] + deps,
sdk_frameworks = ["XCTest", "CoreGraphics"] + sdk_frameworks,
visibility = visibility,
testonly = testonly,
**kwargs)
def mdc_snapshot_test(
name,
deps = [],
minimum_os_version = SNAPSHOT_IOS_MINIMUM_OS,
visibility = ["//visibility:private"],
size = "medium",
tags = ["exclusive"],
**kwargs):
"""Declare an MDC ios_unit_test for snapshot tests."""
ios_unit_test(
name = name,
deps = deps,
minimum_os_version = minimum_os_version,
runner = SNAPSHOT_IOS_RUNNER_TARGET,
tags = tags,
test_host = "//components/private/Snapshot/TestHost",
visibility = visibility,
# TODO(https://github.com/material-components/material-components-ios/issues/6335)
flaky = 1,
size = size,
**kwargs)
def mdc_ci_config_setting():
"""Config setting for mdc continuous integration, e.g. --define ci_mode=kokoro"""
native.config_setting(
name = "kokoro",
values = {"define": "ci_mode=kokoro"},
)
native.config_setting(
name = "autobot",
values = {"define": "ci_mode=autobot"},
)
def mdc_unit_test_suite(
name,
deps = [],
minimum_os_version = IOS_MINIMUM_OS,
visibility = ["//visibility:private"],
size = "medium",
use_autobot_environment_runner = True,
**kwargs):
"""Declare a MDC unit_test_suite and a unit_test_environment using the ios_runners matrix.
Args:
name: The name of the target.
deps: The dependencies of the target.
minimum_os_version: The minimum iOS version supported by the target.
visibility: The visibility of the package.
size: The size of the test.
use_autobot_environment_runner: Indicates whether autobot (a testing machine) environment runner should be used.
**kwargs: Any arguments accepted by ios_unit_test().
"""
mdc_ci_config_setting()
runners = list(DEFAULT_IOS_RUNNER_TARGETS)
if use_autobot_environment_runner:
ios_unit_test(
name = name + '_environment',
deps = deps,
minimum_os_version = minimum_os_version,
runner = select({
":kokoro": KOKORO_ENVIRONMENT_IOS_RUNNER_TARGET,
":autobot": AUTOBOT_ENVIRONMENT_IOS_RUNNER_TARGET,
"//conditions:default": KOKORO_ENVIRONMENT_IOS_RUNNER_TARGET,
}),
visibility = visibility,
size = size,
**kwargs)
else:
runners.append(KOKORO_ENVIRONMENT_IOS_RUNNER_TARGET)
ios_unit_test_suite(
name = name,
deps = deps,
minimum_os_version = minimum_os_version,
runners = runners,
visibility = visibility,
size = size,
**kwargs
)