Skip to content

Commit bd675dd

Browse files
oncillajuagargi
authored andcommitted
build: drop @cgrindel_bazel_starlib//updatesrc (scionproto#4427)
Refactor the remaining targets that depended on @cgrindel_bazel_starlib//updatesrc. The repository has now been completely migrated to @aspect_bazel_lib//lib:write_source_files. During the refactor, we dropped the functionality to write the source files in rules_openapi. Instead, the caller side can decide how to write the source files. This makes the rules more composable and easier to use. The functionality has been moved to a macro in private/mgmtapi/api.bzl, which is used inside of scionproto/scion.
1 parent 8716518 commit bd675dd

File tree

23 files changed

+128
-175
lines changed

23 files changed

+128
-175
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
bin
2+
doc/_build
23
docker/_build
34
rules_openapi/tools/node_modules
45
tools/lint/logctxcheck/testdata/src

BUILD.bazel

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ load("//tools/lint:write_source_files.bzl", "write_source_files")
77
load("//tools/lint/python:flake8_config.bzl", "flake8_lint_config")
88
load("//:nogo.bzl", "nogo_deps")
99
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
10-
load("@cgrindel_bazel_starlib//updatesrc:defs.bzl", "updatesrc_update_all")
1110

1211
# gazelle:prefix github.com/scionproto/scion
1312
# gazelle:map_kind go_library go_library //tools/lint:go.bzl
@@ -233,19 +232,21 @@ buildifier(
233232
mode = "check",
234233
)
235234

236-
# Runs all update_src targets in this Workspace. Currently, generating the
237-
# OpenAPI specs is the last target that depends on update_src. Eventually,
238-
# this should be transitioned to write_all_source_files below.
239-
updatesrc_update_all(
240-
name = "update_all",
241-
)
242-
243235
# Runs all write_source_files targets in this Workspace. To update the list run
244236
# 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
245237
write_source_files(
246238
name = "write_all_source_files",
247239
additional_update_targets = [
248-
"//doc/_build/_static/command:write_files",
240+
"//control/mgmtapi:write_files",
241+
"//daemon/mgmtapi:write_files",
242+
"//dispatcher/mgmtapi:write_files",
249243
"//doc/command:write_files",
244+
"//gateway/mgmtapi:write_files",
245+
"//private/ca/api:write_files",
246+
"//private/mgmtapi/cppki/api:write_files",
247+
"//private/mgmtapi/health/api:write_files",
248+
"//private/mgmtapi/segments/api:write_files",
249+
"//router/mgmtapi:write_files",
250+
"//spec:write_files",
250251
],
251252
)

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ antlr:
7070

7171
write_all_source_files:
7272
bazel run //:write_all_source_files
73-
bazel run //:update_all
7473

7574
.PHONY: lint lint-bazel lint-bazel-buildifier lint-doc lint-doc-mdlint lint-go lint-go-bazel lint-go-gazelle lint-go-golangci lint-go-semgrep lint-openapi lint-openapi-spectral lint-protobuf lint-protobuf-buf
7675

WORKSPACE

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,3 @@ rules_openapi_dependencies()
297297
load("//rules_openapi:install.bzl", "rules_openapi_install_yarn_dependencies")
298298

299299
rules_openapi_install_yarn_dependencies()
300-
301-
# TODO(lukedirtwalker): can that be integrated in the rules_openapi_dependencies
302-
# call above somehow?
303-
load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")
304-
305-
bazel_starlib_dependencies()

control/mgmtapi/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("//tools/lint:go.bzl", "go_library", "go_test")
2-
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_build_docs", "openapi_generate_go")
2+
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_build_docs")
3+
load("//private/mgmtapi:api.bzl", "openapi_generate_go")
34

45
openapi_build_docs(
56
name = "doc",

daemon/mgmtapi/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("//tools/lint:go.bzl", "go_library")
2-
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_build_docs", "openapi_generate_go")
2+
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_build_docs")
3+
load("//private/mgmtapi:api.bzl", "openapi_generate_go")
34

45
openapi_build_docs(
56
name = "doc",

dispatcher/mgmtapi/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("//tools/lint:go.bzl", "go_library")
2-
load("//rules_openapi:defs.bzl", "openapi_build_docs", "openapi_generate_go")
2+
load("//rules_openapi:defs.bzl", "openapi_build_docs")
3+
load("//private/mgmtapi:api.bzl", "openapi_generate_go")
34

45
openapi_build_docs(
56
name = "doc",

gateway/mgmtapi/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
load("//tools/lint:go.bzl", "go_library")
2-
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_build_docs", "openapi_generate_go")
2+
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_build_docs")
3+
load("//private/mgmtapi:api.bzl", "openapi_generate_go")
34

45
openapi_build_docs(
56
name = "doc",

private/ca/api/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//tools/lint:go.bzl", "go_library")
2-
load("@com_github_scionproto_scion//rules_openapi:defs.bzl", "openapi_generate_go")
2+
load("//private/mgmtapi:api.bzl", "openapi_generate_go")
33

44
openapi_generate_go(
55
name = "api_generated",

private/mgmtapi/api.bzl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""OpenAPI Macros
2+
Macros for generating Go code from OpenAPI specs.
3+
"""
4+
5+
load("//tools/lint:write_source_files.bzl", "write_source_files")
6+
load("//rules_openapi:defs.bzl", _openapi_generate_go = "openapi_generate_go")
7+
8+
def openapi_generate_go(
9+
name,
10+
client = True,
11+
server = True,
12+
spec = True,
13+
types = True,
14+
**kwargs):
15+
"""
16+
Generates Go code from an OpenAPI spec.
17+
18+
This macro creates two additional rules:
19+
- {{name}}_files: A filegroup with the generated files.
20+
- write_files: A write_source_files rule that writes the generated files to
21+
the source directory.
22+
23+
Args:
24+
name: The name of the rule.
25+
client: Whether to generate a client.
26+
server: Whether to generate a server.
27+
spec: Whether to generate a spec.
28+
types: Whether to generate types.
29+
**kwargs: Ad.
30+
"""
31+
32+
write_files = {}
33+
for typ, gen in {"client": client, "server": server, "spec": spec, "types": types}.items():
34+
if not gen:
35+
continue
36+
src = typ + ".bzl.gen.go"
37+
kwargs["out_" + typ] = typ + ".bzl.gen.go"
38+
write_files[typ + ".gen.go"] = src
39+
40+
_openapi_generate_go(
41+
name = name,
42+
**kwargs
43+
)
44+
45+
write_source_files(
46+
name = "write_files",
47+
files = write_files,
48+
)

0 commit comments

Comments
 (0)