mirror of
https://github.com/github/codeql.git
synced 2025-12-16 08:43:11 +01:00
Bazel/Go: make @codeql//go:gen runnable from internal repo
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
|
||||
load("@gazelle//:def.bzl", "gazelle")
|
||||
load("@rules_pkg//pkg:install.bzl", "pkg_install")
|
||||
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")
|
||||
load("@rules_pkg//pkg:zip.bzl", "pkg_zip")
|
||||
load("//:defs.bzl", "codeql_platform")
|
||||
|
||||
gazelle(
|
||||
native_binary(
|
||||
name = "gazelle",
|
||||
extra_args = ["go/extractor"],
|
||||
src = "@gazelle//cmd/gazelle",
|
||||
out = "gazelle.exe",
|
||||
args = ["go/extractor"],
|
||||
)
|
||||
|
||||
_gen_binaries = [
|
||||
@@ -24,9 +25,9 @@ py_binary(
|
||||
deps = ["@rules_python//python/runfiles"],
|
||||
)
|
||||
|
||||
# this is an internal copy of the dbscheme to be used by extractor-pack
|
||||
# this allows the extractor-pack target to be independent and up-to-date with respect to
|
||||
# having run //go:gen to update the checked in files
|
||||
# this is an instance of the dbscheme kept in the bazel build tree
|
||||
# this allows everything that bazel builds to be up-to-date,
|
||||
# independently from whether //go:gen was already run to update the checked in files
|
||||
genrule(
|
||||
name = "dbscheme",
|
||||
outs = ["go.dbscheme"],
|
||||
@@ -108,12 +109,3 @@ py_binary(
|
||||
main = "create_extractor_pack.py",
|
||||
deps = ["@rules_python//python/runfiles"],
|
||||
)
|
||||
|
||||
native_binary(
|
||||
name = "gen-dbscheme",
|
||||
src = "//go/extractor/cli/go-gen-dbscheme",
|
||||
out = "go-gen-dbscheme",
|
||||
args = [
|
||||
"$$BUILD_WORKSPACE_DIRECTORY/go/ql/lib/go.dbscheme",
|
||||
],
|
||||
)
|
||||
|
||||
12
go/gen.py
12
go/gen.py
@@ -24,12 +24,18 @@ def options():
|
||||
opts = options()
|
||||
|
||||
try:
|
||||
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY'])
|
||||
workspace_dir = pathlib.Path(os.environ.pop('BUILD_WORKSPACE_DIRECTORY'))
|
||||
except KeyError:
|
||||
print("this should be run with bazel run", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
go_extractor_dir = workspace_dir / "go" / "extractor"
|
||||
|
||||
if not go_extractor_dir.exists():
|
||||
# internal repo?
|
||||
workspace_dir /= "ql"
|
||||
go_extractor_dir = workspace_dir / "go" / "extractor"
|
||||
|
||||
go_dbscheme = workspace_dir / "go" / "ql" / "lib" / "go.dbscheme"
|
||||
r = runfiles.Create()
|
||||
go, gazelle, go_gen_dbscheme = map(r.Rlocation, opts.executables)
|
||||
@@ -49,8 +55,8 @@ if opts.force:
|
||||
for build_file in existing_build_files:
|
||||
build_file.unlink()
|
||||
|
||||
print("running gazelle")
|
||||
subprocess.check_call([gazelle])
|
||||
print("running gazelle", gazelle, go_extractor_dir)
|
||||
subprocess.check_call([gazelle, "go/extractor"], cwd=workspace_dir)
|
||||
|
||||
# we want to stamp all newly generated `BUILD.bazel` files with a header
|
||||
build_files_to_update = set(go_extractor_dir.glob("*/**/BUILD.bazel"))
|
||||
|
||||
Reference in New Issue
Block a user