Skip to content

Commit 19b2e56

Browse files
committed
Go: group BUILD and dbscheme generation target
1 parent 925a2cc commit 19b2e56

4 files changed

Lines changed: 42 additions & 19 deletions

File tree

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ repos:
2727

2828
- repo: local
2929
hooks:
30-
- id: gazelle
31-
name: Check gazelle-generated BUILD files
32-
files: go/extractor/.*
30+
- id: go-gen
31+
name: Check checked in generated files in go
32+
files: go/.*
3333
language: system
34-
entry: bazel run //go/gazelle
34+
entry: bazel run //go:gen
3535
pass_filenames: false
3636

3737
- id: codeql-format

go/BUILD.bazel

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
22
load("@rules_pkg//pkg:install.bzl", "pkg_install")
3+
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
4+
load("@gazelle//:def.bzl", "gazelle")
35
load("//:defs.bzl", "codeql_platform")
46

7+
gazelle(
8+
name = "_gazelle",
9+
)
10+
11+
_gen_binaries = [
12+
":_gazelle",
13+
"//go/extractor/cli/go-gen-dbscheme",
14+
]
15+
16+
py_binary(
17+
name = "gen",
18+
srcs = ["gen.py"],
19+
args = ["$(rlocationpath %s)" % bin for bin in _gen_binaries],
20+
data = _gen_binaries,
21+
deps = ["@rules_python//python/runfiles"],
22+
)
23+
524
pkg_files(
625
name = "resources",
726
srcs = [
@@ -57,3 +76,12 @@ py_binary(
5776
main = "create_extractor_pack.py",
5877
deps = [":_create_extractor_pack"],
5978
)
79+
80+
native_binary(
81+
name = "gen-dbscheme",
82+
src = "//go/extractor/cli/go-gen-dbscheme",
83+
out = "go-gen-dbscheme",
84+
args = [
85+
"$$BUILD_WORKSPACE_DIRECTORY/go/ql/lib/go.dbscheme",
86+
],
87+
)

go/gazelle/BUILD.bazel

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@
44
from python.runfiles import runfiles
55

66
this = pathlib.Path(__file__).resolve()
7-
go_extractor_dir = this.parents[1] / "extractor"
8-
gazelle = runfiles.Create().Rlocation(sys.argv[1])
7+
go_extractor_dir = this.parent / "extractor"
8+
go_dbscheme = this.parent / "ql" / "lib" / "go.dbscheme"
9+
r = runfiles.Create()
10+
gazelle, go_gen_dbscheme = map(r.Rlocation, sys.argv[1:])
11+
12+
print("clearing generated BUILD files")
913
for build_file in go_extractor_dir.glob("*/**/BUILD.bazel"):
1014
build_file.unlink()
1115

16+
print("running gazelle")
1217
subprocess.check_call([gazelle, "go/extractor"])
1318

19+
print("adding header to generated BUILD files")
1420
for build_file in go_extractor_dir.glob("*/**/BUILD.bazel"):
1521
contents = build_file.read_text()
1622
build_file.write_text(f"# generated running `bazel run //go/gazelle`, do not edit\n\n{contents}")
23+
24+
subprocess.check_call([go_gen_dbscheme, go_dbscheme])

0 commit comments

Comments
 (0)