-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Go: add bazel build #16317
Changes from 38 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,119 @@ | ||
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( | ||
name = "gazelle", | ||
extra_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 internal copy of the dbscheme to be used by extractor-pack | ||
redsun82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 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 | ||
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"), | ||
criemen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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-installer", | ||
srcs = [":extractor-pack"], | ||
) | ||
|
||
# rules_pkg installer is currently broken on Windows | ||
# see https://github.com/bazelbuild/rules_pkg/issues/387 | ||
# for now, work around it using an archive | ||
pkg_zip( | ||
criemen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
name = "_extractor-pack-zip", | ||
srcs = [":extractor-pack"], | ||
) | ||
|
||
alias( | ||
name = "_create-extractor-pack-arg", | ||
actual = select({ | ||
"@platforms//os:windows": ":_extractor-pack-zip", | ||
"//conditions:default": ":_extractor-pack-installer", | ||
}), | ||
) | ||
|
||
py_binary( | ||
name = "create-extractor-pack", | ||
srcs = ["create_extractor_pack.py"], | ||
args = ["$(rlocationpath :_create-extractor-pack-arg)"], | ||
data = [":_create-extractor-pack-arg"], | ||
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", | ||
criemen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
], | ||
) |
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 @@ | ||
import os | ||
import pathlib | ||
import shutil | ||
import sys | ||
import subprocess | ||
import zipfile | ||
from python.runfiles import runfiles | ||
|
||
try: | ||
workspace_dir = pathlib.Path(os.environ['BUILD_WORKSPACE_DIRECTORY']) | ||
except KeyError: | ||
print("this should be run with bazel run", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
dest_dir = workspace_dir / 'go' / 'build' / 'codeql-extractor-go' | ||
installer_or_zip = pathlib.Path(runfiles.Create().Rlocation(sys.argv[1])) | ||
|
||
shutil.rmtree(dest_dir, ignore_errors=True) | ||
|
||
if installer_or_zip.suffix == '.zip': | ||
dest_dir.mkdir() | ||
with zipfile.ZipFile(installer_or_zip) as pack: | ||
pack.extractall(dest_dir) | ||
else: | ||
os.environ['DESTDIR'] = str(dest_dir) | ||
subprocess.check_call([installer_or_zip]) |
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,56 @@ | ||||||||||||||
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 | ||||||||||||||
|
||||||||||||||
# following target is kept up to date by `bazel run //go:gen`, do not edit directly | ||||||||||||||
redsun82 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
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
|
||||||||||||||
|
||||||||||||||
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", | ||||||||||||||
], | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
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", | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you check that this JAR has all the class files? I'd expect you need to build a deploy jar here, as otherwise the tokenizer-deps library class files will not make it into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, I checked that exactly the same files end up in the extractor pack. By the way, I'm no java expert so I don't know what this all entails, but the split between Lines 101 to 106 in 880262d
You can see we are actively There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oo okay, in that case this needs to be documented - the way it's currently written in the BUILD.bazel file it looks like a bug, not intended behavior. It is a correct reproduction of the behavior from the Makefile though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a comment then! |
||||||||||||||
}, | ||||||||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I assume this now replaces the
GO_VERSION
environment variables in the workflows, so we should update the playbook accordingly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, I will open a PR for that!