mirrored from https://skia.googlesource.com/buildbot
-
Notifications
You must be signed in to change notification settings - Fork 65
/
BUILD.bazel
301 lines (262 loc) · 10.2 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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load("@exec_properties//:constants.bzl", "NETWORK_ON")
load("@npm//:defs.bzl", "npm_link_all_packages")
# Disable generation of go_proto_library targets. Let Gazelle use checked-in .pb.go files instead.
#
# We opt out of this feature for the following reasons:
#
# 1) Generated files are invisible to code editors and IDEs, which breaks features such as code
# completion, automated refactors, etc. This can be fixed with editor plugins (see
# https://github.com/bazelbuild/rules_go/issues/512), but none are available at this time.
#
# 2) Leveraging the preexisting, checked-in .pb.go is the fastest way to roll out Bazel as the build
# system for our repository, and is the recommended approach for already established projects, or
# for projects that also need to build with "go build". See
# https://github.com/bazelbuild/rules_go/blob/master/proto/core.rst#option-2-use-pre-generated-pbgo-files.
#
# In the future, we might decide to leverage Gazelle's generation of go_proto_library rules. To
# address point 1) above, a potential approach is to check in any files generated via
# go_proto_library targets. This works because if there's a source file checked in the repository,
# and a build target that generates a file of the same name, Bazel will ignore the checked in file
# and use the generated file instead. To keep the checked in and generated files in sync, a rule
# such as generated_file_test can be used, as mentioned here:
# https://github.com/bazelbuild/rules_go/issues/512#issuecomment-747844469.
#
# Documentation for this directive: https://github.com/bazelbuild/bazel-gazelle#directives.
#
# gazelle:proto disable
# This directive tells Gazelle to use a custom macro instead of rules_go's go_test rule for any
# Gazelle-generated Go test targets.
#
# The custom macro generates separate go_test targets for manual Go tests, which will be tagged as
# manual. The macro relies on the assumption that any manual test cases will be placed on Go source
# files ending in "_manual_test.go". If the test target does not contain any manual test, the
# custom macro behaves exactly like rules_go's go_test rule.
#
# See the macro's docstring for details.
#
# Documentation for this directive: https://github.com/bazelbuild/bazel-gazelle#directives.
#
# gazelle:map_kind go_test go_test //bazel/go:go_test.bzl
# Exclude directories with Bazel outputs. The "_bazel_" prefix is defined in //.bazelrc.
#
# Without this, Gazelle can take several minutes to complete.
#
# gazelle:exclude _bazel_*
# Exclude directory generated by rbe_configs_gen.
# gazelle:exclude bazel/rbe/generated
# The new_element directory has templates which do not compile/run.
# gazelle:exclude new_element*
# gazelle:prefix go.skia.org/infra
gazelle(
name = "gazelle",
# We use a custom Gazelle binary that adds support for our front-end Bazel rules and macros.
gazelle = "//bazel/gazelle",
)
exports_files(
[
"package.json",
"tsconfig.json",
".puppeteerrc.js",
],
visibility = ["//visibility:public"],
)
buildifier(
name = "buildifier",
exclude_patterns = [
"./bazel/rbe/generated/*",
"./node_modules/*",
"./**/node_modules/*",
],
lint_mode = "warn",
)
############################
# Custom platform for RBE. #
############################
platform(
name = "rbe_custom_platform",
# Enable networking. Without this, tests that require network access will fail. Examples include
# go_test targets that try to clone the Skia Git repo from https://skia.googlesource.com/skia,
# tests that hit GCS, etc.
#
# See https://github.com/bazelbuild/bazel-toolchains/tree/master/rules/exec_properties.
#
# Note that depending on network resources breaks test hermeticity.
exec_properties = NETWORK_ON,
# Extend the platform generated with "rbe_configs_gen".
#
# See //bazel/rbe/generated/README.md for details.
parents = ["//bazel/rbe/generated/config:platform"],
)
######################################
# JavaScript and TypeScript support. #
######################################
# Make NPM packages available as dependencies under //:node_modules.
npm_link_all_packages(name = "node_modules")
# Global tsconfig.json file.
ts_config(
name = "ts_config",
src = "tsconfig.json",
visibility = ["//visibility:public"],
)
# Global Puppeteer configuration file.
js_library(
name = "puppeteer_rc",
srcs = [".puppeteerrc.js"],
visibility = ["//visibility:public"],
)
#############################################################################
# Utility tool to extract screenshots taken by Puppeteer tests under Bazel. #
#############################################################################
# Wrapper script so we can invoke the tool from the workspace root, instead of the directory where
# the tool's go_binary target is located.
genrule(
name = "extract_puppeteer_screenshots_wrapper_script",
srcs = ["//puppeteer-tests/bazel/extract_puppeteer_screenshots"],
outs = ["extract_puppeteer_screenshots.sh"],
cmd = " && ".join([
# The $@ variable holds the path to the genrule's only output file. The $$@ variable is the
# shell's $@ variable ($-escaped), which is used here to pipe through to the underlying Go
# program any command-line arguments passed to the wrapper shell script.
#
# See https://docs.bazel.build/versions/master/be/general.html#genrule.
"echo '#!/bin/bash' >> $@",
"echo '$(rootpath //puppeteer-tests/bazel/extract_puppeteer_screenshots) $$@' >> $@",
]),
)
# Usage: "bazel run //:extract_puppeteer_screenshots -- --output_dir=<output directory>".
sh_binary(
name = "extract_puppeteer_screenshots",
srcs = ["extract_puppeteer_screenshots.sh"],
data = ["//puppeteer-tests/bazel/extract_puppeteer_screenshots"],
)
#####################################
# Puppeteer screenshot viewer tool. #
#####################################
# Usage: "bazel run //:puppeteer_screenshot_server".
alias(
name = "puppeteer_screenshot_server",
actual = "//puppeteer-tests/bazel/puppeteer_screenshot_server",
visibility = ["//visibility:public"],
)
##################
# Miscellaneous. #
##################
# This rule is a convenient way to build all the task drivers and copy them all into a single
# place as a tar folder. Otherwise, we would need to run many separate bazel build commands and
# then fish the executables out of a deep folder structure like:
# _bazel_bin/infra/bots/task_drivers/bazel_build_all/bazel_build_all_/bazel_build_all
# After this runs, the executables will all be in //_bazel_bin/built_task_drivers.tar
# Why the tar file? Windows binaries are created with .exe and other platforms are not. However,
# outs *must* be static, thus we cannot use a select. Bazel requires us to define all outputs
# exactly, so the only way to support files with different names on different platforms is to
# package them up into a file with the same name.
# Cross compilation is handled as per https://github.com/bazelbuild/rules_go#how-do-i-cross-compile
genrule(
name = "all_task_drivers",
srcs = [
"//infra/bots/task_drivers/bazel_build_all",
"//infra/bots/task_drivers/bazel_test_all",
"//infra/bots/task_drivers/build_and_deploy_cipd",
"//infra/bots/task_drivers/build_push_docker_image",
"//infra/bots/task_drivers/canary",
"//infra/bots/task_drivers/command_wrapper",
"//infra/bots/task_drivers/presubmit",
],
outs = ["built_task_drivers.tar"],
# Make a temporary directory in the output directory, as recommended by
# https://bazel.build/reference/be/make-variables#predefined_genrule_variables
# Reminder that $(@D) refers to that output directory and $(SRCS) refers to all
# the input files, in a space separated list.
cmd = "mkdir -p $(@D)/tmp_task_drivers && " +
# Copy all the task drivers to the same folder
"cp $(SRCS) $(@D)/tmp_task_drivers && " +
# Tar them up from that folder (so they will be in the top level of the tar directory)
# The parent directory of our temp directory is where the output tar file should go.
"cd $(@D)/tmp_task_drivers && tar --file ../built_task_drivers.tar --create . && " +
# Delete the temp folder (as per the recommendation above)
"cd .. && rm -rf tmp_task_drivers",
)
######
# go #
######
# Sample usage: "bazel run //:go -- generate ./...".
alias(
name = "go",
actual = "//bazel/tools/go",
visibility = ["//visibility:public"],
)
#########
# gofmt #
#########
# Sample usage: "bazel run //:gofmt -- -s -w .".
alias(
name = "gofmt",
actual = "@go_sdk//:bin/gofmt",
visibility = ["//visibility:public"],
)
#############
# goimports #
#############
# Sample usage: "bazel run //:goimports "--run_under=cd $PWD &&" -- -w myfile.go".
alias(
name = "goimports",
actual = "@org_golang_x_tools//cmd/goimports",
visibility = ["//visibility:public"],
)
############
# Errcheck #
############
# Sample usage: "bazel run //:errcheck -- go.skia.org/infra/...".
alias(
name = "errcheck",
actual = "//bazel/tools/errcheck",
visibility = ["//visibility:public"],
)
###########
# Mockery #
###########
alias(
name = "mockery",
actual = "@com_github_vektra_mockery_v2//:v2",
visibility = ["//visibility:public"],
)
##########
# protoc #
##########
# Sample usage: "bazel run //:protoc -- --twirp_out=. --go_out=. myproto.proto"
alias(
name = "protoc",
actual = "//bazel/tools/protoc",
visibility = ["//visibility:public"],
)
#######
# npm #
#######
# Sample usage: "bazel run //:npm -- install some-package"
alias(
name = "npm",
actual = "//bazel/tools/npm",
visibility = ["//visibility:public"],
)
#######
# npx #
#######
# Sample usage: "bazel run //:npx -- eslint --fix ."
alias(
name = "npx",
actual = "//bazel/tools/npx",
visibility = ["//visibility:public"],
)
######
# sk #
######
# Sample usage: "bazel run //:sk -- asset download <asset name> <target directory>"
alias(
name = "sk",
actual = "//sk/go/sk",
visibility = ["//visibility:public"],
)