forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUILD.bazel
334 lines (300 loc) · 9.16 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "nogo")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@io_bazel_rules_go//proto:compiler.bzl", "go_proto_compiler")
load("@io_bazel_rules_go//proto/wkt:well_known_types.bzl", "WELL_KNOWN_TYPES_APIV2")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//dev/linters/staticcheck:analyzers.bzl", "STATIC_CHECK_ANALYZERS")
load("@npm//:eslint/package_json.bzl", eslint_bin = "bin")
load("//dev:eslint.bzl", "eslint_test_with_types")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
# Gazelle config
#
# Tell gazelle what is our main module
# gazelle:prefix github.com/sourcegraph/sourcegraph
# gazelle:build_file_name BUILD.bazel
# Disable some by default, only include configured BUILDs
#
# gazelle:js disabled
# gazelle:js_npm_package_target_name {dirname}_pkg
# Enable: Aspect javascript, standard go
# gazelle:lang js,go,proto,gomockgen
# Enable race detection for all go_test rules.
# gazelle:map_kind go_test go_test //dev:go_defs.bzl
package(default_visibility = ["//visibility:public"])
npm_link_all_packages(name = "node_modules")
eslint_bin.eslint_binary(
name = "eslint",
testonly = True,
visibility = ["//visibility:public"],
)
js_library(
name = "prettier_config_js",
srcs = ["prettier.config.js"],
data = [
"//:node_modules/@sourcegraph/prettierrc",
],
)
ts_config(
name = "tsconfig",
src = "tsconfig.base.json",
visibility = ["//visibility:public"],
deps = [
"//:node_modules/@sourcegraph/tsconfig",
],
)
ts_config(
name = "tsconfig-all",
src = "tsconfig.json",
visibility = ["//visibility:public"],
deps = [
":tsconfig",
],
)
js_library(
name = "postcss_config_js",
srcs = ["postcss.config.js"],
visibility = ["//visibility:public"],
deps = [
"//:node_modules/autoprefixer",
"//:node_modules/postcss-custom-media",
"//:node_modules/postcss-focus-visible",
"//:node_modules/postcss-inset",
],
)
copy_to_bin(
name = "package_json",
srcs = ["package.json"],
visibility = ["//visibility:public"],
)
js_library(
name = "vitest_config",
testonly = True,
srcs = [
"vitest.shared.ts",
],
visibility = ["//visibility:public"],
deps = [
"//:node_modules/@testing-library/jest-dom",
"//:node_modules/abort-controller",
"//:node_modules/core-js",
"//:node_modules/identity-obj-proxy",
"//:node_modules/message-port-polyfill",
"//:node_modules/regenerator-runtime",
"//client/testing:testing_lib",
],
)
js_library(
name = "mocha_config",
testonly = True,
srcs = [
".mocharc.js",
],
deps = [
"//:node_modules/abort-controller",
"//client/shared/dev:mocha-reporter",
"//client/shared/dev:suppress-polly-errors",
"//client/testing:fetch-mock",
],
)
js_library(
name = "graphql_schema_config",
srcs = [
".graphqlrc.yml",
"graphql-schema-linter.config.js",
],
visibility = ["//visibility:public"],
)
js_library(
name = "eslint-relative-formatter",
srcs = [
"eslint-relative-formatter.js",
],
deps = [
":node_modules/chalk",
":node_modules/strip-ansi",
":node_modules/text-table",
],
)
js_library(
name = "eslint_config",
testonly = True,
srcs = [
".eslintrc.js",
],
data = [
"package.json",
":eslint-relative-formatter",
],
deps = [
":node_modules/@sourcegraph/eslint-config",
":node_modules/@sourcegraph/eslint-plugin-sourcegraph",
":node_modules/@sourcegraph/eslint-plugin-wildcard",
":node_modules/@typescript-eslint/eslint-plugin",
":node_modules/eslint-config-prettier",
":node_modules/eslint-import-resolver-node",
":node_modules/eslint-plugin-ban",
":node_modules/eslint-plugin-etc",
":node_modules/eslint-plugin-import",
":node_modules/eslint-plugin-jest-dom",
":node_modules/eslint-plugin-jsdoc",
":node_modules/eslint-plugin-jsx-a11y",
":node_modules/eslint-plugin-monorepo",
":node_modules/eslint-plugin-react",
":node_modules/eslint-plugin-react-hooks",
":node_modules/eslint-plugin-rxjs",
":node_modules/eslint-plugin-storybook",
":node_modules/eslint-plugin-unicorn",
":node_modules/eslint-plugin-unused-imports",
":node_modules/react", # required to resolve the react version for eslint-plugin-react
":tsconfig-all",
"//:node_modules/tslib",
],
)
eslint_test_with_types(
name = "eslint_test",
srcs = glob(["*.js"]),
config = ":eslint_config",
deps = [
":node_modules/@types/node",
],
)
buildifier(
name = "buildifier",
exclude_patterns = [
"./.git/*",
"cmd/symbols/squirrel/test_repos/starlark/**/*",
],
# TODO: enable these lint checks
# lint_mode = "fix",
mode = "fix",
)
buildifier(
name = "buildifier.check",
exclude_patterns = [
"./.git/*",
"cmd/symbols/squirrel/test_repos/starlark/**/*",
],
# TODO: enable these lint checks
# lint_mode = "warn",
mode = "diff",
)
# Go
gazelle_binary(
name = "gazelle-bin",
languages = [
# Loads the native proto extension
"@bazel_gazelle//language/proto:go_default_library",
# Gazelle-buf does not include the Go plugin by default, so we have to add it
# ourselves.
"@bazel_gazelle//language/go:go_default_library",
"//dev/go-mockgen-gazelle:go-mockgen-gazelle",
# Bundled with aspect-cli, but we're missing out on buf that way
"@aspect_cli//gazelle/js:js",
# Loads the Buf extension
# NOTE: This needs to be loaded after the proto language
"@rules_buf//gazelle/buf:buf",
],
)
gazelle(
name = "gazelle",
gazelle = ":gazelle-bin",
)
sh_binary(
name = "configure",
srcs = ["//dev/ci:bazel-configure.sh"],
)
go_library(
name = "sourcegraph",
srcs = [
"doc.go",
"gen.go",
],
importpath = "github.com/sourcegraph/sourcegraph",
)
gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=deps.bzl%go_dependencies",
"-prune",
"-build_file_proto_mode=disable_global",
],
command = "update-repos",
)
# Because the current implementation of rules_go uses the old protoc grpc compiler, we have to declare our own, and declare it manually in the build files.
# See https://github.com/bazelbuild/rules_go/issues/3022
# gazelle:go_grpc_compilers //:gen-go-grpc,@io_bazel_rules_go//proto:go_proto
go_proto_compiler(
name = "gen-go-grpc",
plugin = "@org_golang_google_grpc_cmd_protoc_gen_go_grpc//:protoc-gen-go-grpc",
suffix = "_grpc.pb.go",
valid_archive = False,
visibility = ["//visibility:public"],
deps = WELL_KNOWN_TYPES_APIV2 + [
"@org_golang_google_grpc//:go_default_library",
"@org_golang_google_grpc//codes:go_default_library",
"@org_golang_google_grpc//status:go_default_library",
],
)
# nogo config
#
# For nogo to be able to run a linter, it needs to have `var Analyzer analysis.Analyzer` defined in the main package.
# some of the linters do not have that, so we need to define that ourselves. The linters where we have defined can
# be found at dev/linters. Finally, the nogo configuration can be found at the root of the repository in `nogo_config.json`
bool_flag(
name = "disable_nogo",
build_setting_default = False,
)
config_setting(
name = "nogo_disabled",
flag_values = {":disable_nogo": "true"},
)
nogo(
name = "sg_nogo",
config = ":nogo_config.json",
vet = True,
visibility = ["//visibility:public"], # must have public visibility
deps = select({
"//:nogo_disabled": [],
"//conditions:default": [
"//dev/linters/bodyclose",
"//dev/linters/depguard",
"//dev/linters/exportloopref",
"//dev/linters/forbidigo",
"//dev/linters/gocheckcompilerdirectives",
"//dev/linters/gocritic",
"//dev/linters/ineffassign",
"//dev/linters/logging",
"//dev/linters/unparam",
"//dev/linters/tracinglibraries",
"//dev/linters/dbconn",
"//dev/linters/nolocalhost",
# Disabled because we currently have a lot of unused code
# "//dev/linters/unused",
] + STATIC_CHECK_ANALYZERS,
}),
)
exports_files([
"go.mod",
"sg.config.yaml",
# Used for when copy_to_directory might reference an empty filegroup
# under certain conditions. See //ui/assets/...
"CONTRIBUTING.md",
".swcrc",
] + glob(["mockgen*.yaml"]))
# sg msp settings
bool_flag(
name = "sg_msp",
build_setting_default = False,
visibility = ["//visibility:public"],
)
config_setting(
name = "sg_msp_flag",
flag_values = {
"//:sg_msp": "True",
},
)