mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Go: group BUILD and dbscheme generation target
This commit is contained in:
@@ -27,11 +27,11 @@ repos:
|
|||||||
|
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: gazelle
|
- id: go-gen
|
||||||
name: Check gazelle-generated BUILD files
|
name: Check checked in generated files in go
|
||||||
files: go/extractor/.*
|
files: go/.*
|
||||||
language: system
|
language: system
|
||||||
entry: bazel run //go/gazelle
|
entry: bazel run //go:gen
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
|
|
||||||
- id: codeql-format
|
- id: codeql-format
|
||||||
|
|||||||
@@ -1,7 +1,26 @@
|
|||||||
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
|
load("@rules_pkg//pkg:mappings.bzl", "pkg_filegroup", "pkg_files")
|
||||||
load("@rules_pkg//pkg:install.bzl", "pkg_install")
|
load("@rules_pkg//pkg:install.bzl", "pkg_install")
|
||||||
|
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
|
||||||
|
load("@gazelle//:def.bzl", "gazelle")
|
||||||
load("//:defs.bzl", "codeql_platform")
|
load("//:defs.bzl", "codeql_platform")
|
||||||
|
|
||||||
|
gazelle(
|
||||||
|
name = "_gazelle",
|
||||||
|
)
|
||||||
|
|
||||||
|
_gen_binaries = [
|
||||||
|
":_gazelle",
|
||||||
|
"//go/extractor/cli/go-gen-dbscheme",
|
||||||
|
]
|
||||||
|
|
||||||
|
py_binary(
|
||||||
|
name = "gen",
|
||||||
|
srcs = ["gen.py"],
|
||||||
|
args = ["$(rlocationpath %s)" % bin for bin in _gen_binaries],
|
||||||
|
data = _gen_binaries,
|
||||||
|
deps = ["@rules_python//python/runfiles"],
|
||||||
|
)
|
||||||
|
|
||||||
pkg_files(
|
pkg_files(
|
||||||
name = "resources",
|
name = "resources",
|
||||||
srcs = [
|
srcs = [
|
||||||
@@ -57,3 +76,12 @@ py_binary(
|
|||||||
main = "create_extractor_pack.py",
|
main = "create_extractor_pack.py",
|
||||||
deps = [":_create_extractor_pack"],
|
deps = [":_create_extractor_pack"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
load("@gazelle//:def.bzl", "gazelle")
|
|
||||||
|
|
||||||
gazelle(
|
|
||||||
name = "_gazelle",
|
|
||||||
)
|
|
||||||
|
|
||||||
py_binary(
|
|
||||||
name = "gazelle",
|
|
||||||
srcs = ["gazelle.py"],
|
|
||||||
args = ["$(rlocationpath :_gazelle)"],
|
|
||||||
data = [":_gazelle"],
|
|
||||||
deps = ["@rules_python//python/runfiles"],
|
|
||||||
)
|
|
||||||
@@ -4,13 +4,21 @@ import subprocess
|
|||||||
from python.runfiles import runfiles
|
from python.runfiles import runfiles
|
||||||
|
|
||||||
this = pathlib.Path(__file__).resolve()
|
this = pathlib.Path(__file__).resolve()
|
||||||
go_extractor_dir = this.parents[1] / "extractor"
|
go_extractor_dir = this.parent / "extractor"
|
||||||
gazelle = runfiles.Create().Rlocation(sys.argv[1])
|
go_dbscheme = this.parent / "ql" / "lib" / "go.dbscheme"
|
||||||
|
r = runfiles.Create()
|
||||||
|
gazelle, go_gen_dbscheme = map(r.Rlocation, sys.argv[1:])
|
||||||
|
|
||||||
|
print("clearing generated BUILD files")
|
||||||
for build_file in go_extractor_dir.glob("*/**/BUILD.bazel"):
|
for build_file in go_extractor_dir.glob("*/**/BUILD.bazel"):
|
||||||
build_file.unlink()
|
build_file.unlink()
|
||||||
|
|
||||||
|
print("running gazelle")
|
||||||
subprocess.check_call([gazelle, "go/extractor"])
|
subprocess.check_call([gazelle, "go/extractor"])
|
||||||
|
|
||||||
|
print("adding header to generated BUILD files")
|
||||||
for build_file in go_extractor_dir.glob("*/**/BUILD.bazel"):
|
for build_file in go_extractor_dir.glob("*/**/BUILD.bazel"):
|
||||||
contents = build_file.read_text()
|
contents = build_file.read_text()
|
||||||
build_file.write_text(f"# generated running `bazel run //go/gazelle`, do not edit\n\n{contents}")
|
build_file.write_text(f"# generated running `bazel run //go/gazelle`, do not edit\n\n{contents}")
|
||||||
|
|
||||||
|
subprocess.check_call([go_gen_dbscheme, go_dbscheme])
|
||||||
Reference in New Issue
Block a user