-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Go: add bazel build #16317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Go: add bazel build #16317
Changes from all commits
393f6b7
4ca8faa
7d9a68b
3ad9c02
925a2cc
19b2e56
bfa189e
146d84b
c8b0224
d98ccdf
0f387ee
86d6b8e
d66494d
b0758fd
0dfd336
6ec223c
2f6dd2a
f0f6c22
1f78882
15bb846
e7886d0
cb85a75
2590d8a
608791f
94212d1
a8d3226
12b9b80
520a2c9
9055d95
ca2d94b
318d954
4ae82ac
0bc6934
abcd916
1aafc37
76067cb
81dea9f
00baccb
31c427e
8f0b884
2132c7b
471303b
17990da
77128de
cba4ba0
5b184c1
73df4fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
load("@bazel_skylib//rules:native_binary.bzl", "native_binary") | ||
load("@rules_pkg//pkg:install.bzl", "pkg_install") | ||
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files") | ||
load("//:defs.bzl", "codeql_platform") | ||
|
||
native_binary( | ||
name = "gazelle", | ||
src = "@gazelle//cmd/gazelle", | ||
out = "gazelle.exe", | ||
args = ["go/extractor"], | ||
) | ||
|
||
_gen_binaries = [ | ||
"@rules_go//go", | ||
":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"], | ||
) | ||
|
||
# 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"], | ||
cmd = "$(execpath //go/extractor/cli/go-gen-dbscheme) $@", | ||
tools = ["//go/extractor/cli/go-gen-dbscheme"], | ||
) | ||
|
||
pkg_files( | ||
name = "resources", | ||
srcs = [ | ||
"LICENSE", | ||
"codeql-extractor.yml", | ||
"ql/lib/go.dbscheme.stats", | ||
":dbscheme", | ||
], | ||
) | ||
|
||
pkg_filegroup( | ||
name = "extractor-pack-generic", | ||
srcs = [ | ||
":resources", | ||
"//go/codeql-tools", | ||
"//go/downgrades", | ||
"//go/extractor:tokenizer", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_files( | ||
name = "extractor-pack-arch", | ||
srcs = [ | ||
"//go/extractor/cli/go-autobuilder", | ||
"//go/extractor/cli/go-bootstrap", | ||
"//go/extractor/cli/go-build-runner", | ||
"//go/extractor/cli/go-extractor", | ||
"//go/extractor/cli/go-gen-dbscheme", | ||
"//go/extractor/cli/go-tokenizer", | ||
], | ||
attributes = pkg_attributes(mode = "0755"), | ||
prefix = "tools/" + codeql_platform, | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_filegroup( | ||
name = "extractor-pack", | ||
srcs = [ | ||
":extractor-pack-arch", | ||
":extractor-pack-generic", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
pkg_install( | ||
name = "_extractor_pack", | ||
srcs = [":extractor-pack"], | ||
) | ||
|
||
py_binary( | ||
name = "create-extractor-pack", | ||
srcs = ["create_extractor_pack.py"], | ||
env = {"REPO_NAME": repo_name()}, | ||
main = "create_extractor_pack.py", | ||
deps = ["_extractor_pack"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files") | ||
|
||
pkg_files( | ||
name = "sh-files", | ||
srcs = glob(["*.sh"]), | ||
mbg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
attributes = pkg_attributes(mode = "0755"), | ||
criemen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
pkg_files( | ||
name = "non-sh-files", | ||
srcs = glob( | ||
["*"], | ||
exclude = [ | ||
"*.sh", | ||
"BUILD.bazel", | ||
], | ||
), | ||
) | ||
|
||
pkg_filegroup( | ||
name = "codeql-tools", | ||
srcs = [ | ||
":non-sh-files", | ||
":sh-files", | ||
], | ||
prefix = "tools", | ||
visibility = ["//go:__pkg__"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
import pathlib | ||
import shutil | ||
import sys | ||
import subprocess | ||
|
||
try: | ||
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY']) | ||
except KeyError: | ||
res = subprocess.run(["bazel", "run", ":create-extractor-pack"], cwd=pathlib.Path(__file__).parent) | ||
sys.exit(res.returncode) | ||
|
||
from go._extractor_pack_install_script import main | ||
|
||
build_dir = workspace_dir / 'go' / 'build' | ||
|
||
if not build_dir.exists(): | ||
# we probably are in the internal repo | ||
workspace_dir /= 'ql' | ||
build_dir = workspace_dir / 'go' / 'build' | ||
|
||
dest_dir = build_dir / 'codeql-extractor-pack' | ||
shutil.rmtree(dest_dir, ignore_errors=True) | ||
os.environ['DESTDIR'] = str(dest_dir) | ||
main(sys.argv) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix") | ||
|
||
pkg_files( | ||
name = "downgrades", | ||
srcs = glob( | ||
["**"], | ||
exclude = ["BUILD.bazel"], | ||
), | ||
prefix = "downgrades", | ||
strip_prefix = strip_prefix.from_pkg(), | ||
visibility = ["//go:__pkg__"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/*/**/BUILD.bazel linguist-generated=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
load("@rules_go//go:def.bzl", "go_library") | ||
load("@rules_pkg//pkg:mappings.bzl", "pkg_files") | ||
|
||
# gazelle:prefix github.com/github/codeql-go/extractor | ||
# gazelle:map_kind go_binary codeql_go_binary //go:rules.bzl | ||
|
||
# the immediately following `extractor` target is kept up to date by `bazel run //go:gen`, do not edit directly | ||
go_library( | ||
name = "extractor", | ||
srcs = [ | ||
"extractor.go", | ||
"gomodextractor.go", | ||
"semaphore.go", | ||
], | ||
importpath = "github.com/github/codeql-go/extractor", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//go/extractor/dbscheme", | ||
"//go/extractor/diagnostics", | ||
"//go/extractor/srcarchive", | ||
"//go/extractor/trap", | ||
"//go/extractor/util", | ||
"//go/extractor/vendor/golang.org/x/mod/modfile", | ||
"//go/extractor/vendor/golang.org/x/tools/go/packages", | ||
], | ||
) | ||
redsun82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# the other targets are not generated by gazelle | ||
|
||
# this is separate from `tokenizer-jar` below because we don't want these compiled class files in the pack | ||
java_library( | ||
criemen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name = "tokenizer-deps", | ||
srcs = [ | ||
"net/sourceforge/pmd/cpd/AbstractLanguage.java", | ||
"net/sourceforge/pmd/cpd/SourceCode.java", | ||
"net/sourceforge/pmd/cpd/TokenEntry.java", | ||
"net/sourceforge/pmd/cpd/Tokenizer.java", | ||
], | ||
) | ||
|
||
# we only need these compiled class files in the pack | ||
java_library( | ||
name = "tokenizer-jar", | ||
srcs = [ | ||
"net/sourceforge/pmd/cpd/GoLanguage.java", | ||
"opencsv/CSVParser.java", | ||
"opencsv/CSVReader.java", | ||
], | ||
deps = [":tokenizer-deps"], | ||
) | ||
|
||
pkg_files( | ||
name = "tokenizer", | ||
srcs = [":tokenizer-jar"], | ||
prefix = "tools", | ||
renames = { | ||
":tokenizer-jar": "tokenizer.jar", # name is `libtokenizer.jar` by default | ||
}, | ||
visibility = ["//go:__pkg__"], | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.