-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16317 from github/redsun82/go
Go: add bazel build
- Loading branch information
Showing
48 changed files
with
979 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]), | ||
attributes = pkg_attributes(mode = "0755"), | ||
) | ||
|
||
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__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/*/**/BUILD.bazel linguist-generated=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) | ||
|
||
# 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( | ||
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.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.