forked from scionproto/scion
-
Notifications
You must be signed in to change notification settings - Fork 33
/
BUILD.bazel
270 lines (247 loc) · 7.52 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
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@io_bazel_rules_go//go:def.bzl", "nogo")
load("//tools/lint:go_config.bzl", "go_lint_config")
load("//tools/lint:write_source_files.bzl", "write_source_files")
load("//tools/lint/python:flake8_config.bzl", "flake8_lint_config")
load("//:nogo.bzl", "nogo_deps")
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load("@npm//private/mgmtapi/tools:@stoplight/spectral-cli/package_json.bzl", spectral_bin = "bin")
# gazelle:prefix github.com/scionproto/scion
# gazelle:map_kind go_library go_library //tools/lint:go.bzl
# gazelle:map_kind go_test go_test //tools/lint:go.bzl
# gazelle:exclude docker/_build/**
# gazelle:exclude proto/**
# gazelle:exclude doc/**
# gazelle:exclude rules_openapi/tools/node_modules/**
# gazelle:exclude tools/lint/**/testdata/src/**
# We suport two sqlite implementations: modernc and mattn. Each implementation
# has a corresponding sqlite_<impl>.go "driver" in private/storage/db. Which
# driver gets compiled and linked is controled by a go build tag: sqlite_mattn
# or sqlite_modernc. Those are specified on the command line
# with "--define gotags=sqlite_mattn" or "--define gotags=sqlite_modernc"
# (see the build options in .bazelrc).
#
# Unfortunately Gazelle needs to be given these tags explicitly via the builtags
# attribute. So, to ensure consistency we have to translate our two gotags into
# build_tags. To that end, we create two config_setting flags that are
# set in response to matching the gotags value and use them to select the relevant
# tag for gazelle. (The "define_value" attribute of config_setting doesn't define
# anything. It matches a key-value pair from "--define").
#
# This is simplistic but the complete, by-the-everchanging-bazel-book, solution
# is ludicrously complicated. Go there if and when needed.
config_setting(
name = "sqlite_mattn_netgo",
define_values = {
"gotags": "sqlite_mattn,netgo",
},
)
config_setting(
name = "sqlite_modernc_netgo",
define_values = {
"gotags": "sqlite_modernc,netgo",
},
)
config_setting(
name = "sqlite_mattn",
define_values = {
"gotags": "sqlite_mattn",
},
)
config_setting(
name = "sqlite_modernc",
define_values = {
"gotags": "sqlite_modernc",
},
)
# This is a dummy target so Make can "blaze build --announce_rc <something>
# Where something truly does nothing that we may care about.
config_setting(
name = "dummy_setting",
define_values = {
"whatever": "whatever",
},
)
gazelle(
name = "gazelle",
build_tags = select({
":sqlite_modernc_netgo": [
"sqlite_modernc",
"sqlite_modernc_netgo",
],
":sqlite_modernc": [
"sqlite_modernc",
],
":sqlite_mattn_netgo": [
"sqlite_mattn",
"netgo",
],
":sqlite_mattn": [
"sqlite_mattn",
],
}),
command = "update",
extra_args = [
"-mode",
"fix",
"-go_naming_convention",
"go_default_library",
],
)
gazelle(
name = "gazelle_diff",
build_tags = select({
":sqlite_modernc_netgo": [
"sqlite_modernc",
"netgo",
],
":sqlite_modernc": [
"sqlite_modernc",
],
":sqlite_mattn_netgo": [
"sqlite_mattn",
"netgo",
],
":sqlite_mattn": [
"sqlite_mattn",
],
}),
command = "update",
extra_args = [
"-mode",
"diff",
"-go_naming_convention",
"go_default_library",
],
)
gazelle(
name = "gazelle_update_repos",
command = "update-repos",
extra_args = [
"-prune",
"-from_file=go.mod",
"-to_macro=go_deps.bzl%go_deps",
],
)
go_lint_config(
name = "go_lint_config",
exclude_filter = [
"mock_",
".pb.go",
".gen.go",
],
visibility = [
"//visibility:public",
],
)
flake8_lint_config(
name = "flake8_lint_config",
config_file = ".flake8",
visibility = [
"//visibility:public",
],
)
# Optional version string to produce versioned file names. End deliverables, such as installable
# packages will have a name derived from that string.
# The flag is to be used when producing publishable assets (so, typically by the CI build).
# The rest of the time the assets will have an unversioned name. The version tags embedded
# in binaries and package manifests are always set. Regardless of this flag.
string_flag(
name = "file_name_version",
build_setting_default = "dev",
visibility = ["//visibility:public"],
)
# Add a build flag to enable bundling the management API documentation with the
# binaries. This can be enabled by passing --//:mgmtapi_bundle_doc=true when
# invoking bazel
bool_flag(
name = "mgmtapi_bundle_doc",
build_setting_default = False,
)
config_setting(
name = "mgmtapi_bundle_doc_build",
flag_values = {":mgmtapi_bundle_doc": "true"},
)
# This is the SCION distributable package. It contains all (binary) services,
# and the required tools.
pkg_tar(
name = "scion",
srcs = [
"//control/cmd/control",
"//daemon/cmd/daemon",
"//dispatcher/cmd/dispatcher",
"//gateway/cmd/gateway",
"//router/cmd/router",
"//scion-pki/cmd/scion-pki",
"//scion/cmd/scion",
"//tools/pathdb_dump",
],
mode = "0755",
package_dir = "",
)
# This contains all of the binaries needed to run CI (integration & acceptance
# tests)
pkg_tar(
name = "scion-ci",
srcs = [
"//acceptance/cmd/sig_ping_acceptance",
"//acceptance/router_benchmark/brload",
"//pkg/private/xtest/graphupdater",
"//tools/braccept",
"//tools/buildkite/cmd/buildkite_artifacts",
"//tools/end2end",
"//tools/end2end_integration",
"//tools/pktgen/cmd/pktgen",
"//tools/scion_integration",
"//tools/udpproxy",
],
mode = "0755",
package_dir = "",
)
# This contains all of the binaries needed to run the topology generator.
pkg_tar(
name = "scion-topo",
srcs = [
"//scion-pki/cmd/scion-pki",
],
mode = "0755",
package_dir = "",
)
# Nogo - Go code analysis tool
nogo(
name = "nogo",
config = "nogo.json",
visibility = ["//visibility:public"],
deps = nogo_deps,
)
buildifier(
name = "buildifier",
)
buildifier(
name = "buildifier_check",
mode = "check",
)
spectral_bin.spectral_binary(
name = "spectral",
)
# Runs all write_source_files targets in this Workspace. To update the list run
# bazel run @com_github_bazelbuild_buildtools//buildozer -- --root_dir $PWD "add additional_update_targets $( bazel query 'filter("^.*[^\d]$", kind(_write_source_file, //...)) except //:write_all_source_files' | tr '\n' ' ')" //:write_all_source_files
write_source_files(
name = "write_all_source_files",
additional_update_targets = [
"//control/mgmtapi:write_files",
"//daemon/mgmtapi:write_files",
"//dispatcher/mgmtapi:write_files",
"//doc/command:write_files",
"//gateway/mgmtapi:write_files",
"//private/ca/api:write_files",
"//private/mgmtapi/cppki/api:write_files",
"//private/mgmtapi/health/api:write_files",
"//private/mgmtapi/segments/api:write_files",
"//router/mgmtapi:write_files",
"//spec:write_files",
],
)