Skip to content

Commit 2132c7b

Browse files
committed
Bazel/Go: make @codeql//go:gen runnable from internal repo
1 parent 8f0b884 commit 2132c7b

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

go/BUILD.bazel

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
2-
load("@gazelle//:def.bzl", "gazelle")
32
load("@rules_pkg//pkg:install.bzl", "pkg_install")
43
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")
54
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
65
load("//:defs.bzl", "codeql_platform")
76

8-
gazelle(
7+
native_binary(
98
name = "gazelle",
10-
extra_args = ["go/extractor"],
9+
src = "@gazelle//cmd/gazelle",
10+
out = "gazelle.exe",
11+
args = ["go/extractor"],
1112
)
1213

1314
_gen_binaries = [
@@ -24,9 +25,9 @@ py_binary(
2425
deps = ["@rules_python//python/runfiles"],
2526
)
2627

27-
# this is an internal copy of the dbscheme to be used by extractor-pack
28-
# this allows the extractor-pack target to be independent and up-to-date with respect to
29-
# having run //go:gen to update the checked in files
28+
# this is an instance of the dbscheme kept in the bazel build tree
29+
# this allows everything that bazel builds to be up-to-date,
30+
# independently from whether //go:gen was already run to update the checked in files
3031
genrule(
3132
name = "dbscheme",
3233
outs = ["go.dbscheme"],
@@ -108,12 +109,3 @@ py_binary(
108109
main = "create_extractor_pack.py",
109110
deps = ["@rules_python//python/runfiles"],
110111
)
111-
112-
native_binary(
113-
name = "gen-dbscheme",
114-
src = "//go/extractor/cli/go-gen-dbscheme",
115-
out = "go-gen-dbscheme",
116-
args = [
117-
"$$BUILD_WORKSPACE_DIRECTORY/go/ql/lib/go.dbscheme",
118-
],
119-
)

go/gen.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ def options():
2424
opts = options()
2525

2626
try:
27-
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY'])
27+
workspace_dir = pathlib.Path(os.environ.pop('BUILD_WORKSPACE_DIRECTORY'))
2828
except KeyError:
2929
print("this should be run with bazel run", file=sys.stderr)
3030
sys.exit(1)
3131

3232
go_extractor_dir = workspace_dir / "go" / "extractor"
33+
34+
if not go_extractor_dir.exists():
35+
# internal repo?
36+
workspace_dir /= "ql"
37+
go_extractor_dir = workspace_dir / "go" / "extractor"
38+
3339
go_dbscheme = workspace_dir / "go" / "ql" / "lib" / "go.dbscheme"
3440
r = runfiles.Create()
3541
go, gazelle, go_gen_dbscheme = map(r.Rlocation, opts.executables)
@@ -49,8 +55,8 @@ def options():
4955
for build_file in existing_build_files:
5056
build_file.unlink()
5157

52-
print("running gazelle")
53-
subprocess.check_call([gazelle])
58+
print("running gazelle", gazelle, go_extractor_dir)
59+
subprocess.check_call([gazelle, "go/extractor"], cwd=workspace_dir)
5460

5561
# we want to stamp all newly generated `BUILD.bazel` files with a header
5662
build_files_to_update = set(go_extractor_dir.glob("*/**/BUILD.bazel"))

0 commit comments

Comments
 (0)