Skip to content

Commit a205b46

Browse files
committed
Bazel: reorganization
* fixed 5.0.0 as bazel version * made dependencies better loadable * moved `//swift/install` to `//swift:create-extractor-pack` (following the clearer ruby naming) * renamed `extractor_pack` to `extractor-pack` for consistency with Ruby
1 parent 13b2442 commit a205b46

File tree

12 files changed

+102
-40
lines changed

12 files changed

+102
-40
lines changed

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.0.0

WORKSPACE.bazel

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,10 @@
33

44
workspace(name = "ql")
55

6-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
7-
8-
http_archive(
9-
name = "rules_pkg",
10-
sha256 = "62eeb544ff1ef41d786e329e1536c1d541bb9bcad27ae984d57f18f314018e66",
11-
urls = [
12-
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz",
13-
"https://github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz",
14-
],
15-
)
16-
17-
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
18-
19-
rules_pkg_dependencies()
20-
21-
http_archive(
22-
name = "platforms",
23-
sha256 = "460caee0fa583b908c622913334ec3c1b842572b9c23cf0d3da0c2543a1a157d",
24-
urls = [
25-
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz",
26-
"https://github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz",
27-
],
28-
)
29-
306
load("@ql//misc/bazel:workspace.bzl", "ql_workspace")
317

328
ql_workspace()
9+
10+
load("@ql//misc/bazel:workspace_deps.bzl", "ql_workspace_deps")
11+
12+
ql_workspace_deps()

misc/bazel/BUILD.toolchain.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@//misc/bazel:toolchain.bzl", "codeql_cli_toolchain")
2+
3+
codeql_cli_toolchain(
4+
name = "codeql-cli",
5+
path = "{codeql_cli_path}",
6+
)
7+
8+
toolchain(
9+
name = "codeql-cli-toolchain",
10+
toolchain = ":codeql-cli",
11+
toolchain_type = "@//:toolchain_type",
12+
)

misc/bazel/test.bzl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
def _test_script_impl(ctx):
2+
output = ctx.actions.declare_file("%s.py" % ctx.label.name)
3+
codeql_cli_path = ctx.toolchains["//:toolchain_type"].codeql_cli.path
4+
ctx.actions.expand_template(
5+
template = ctx.file._template,
6+
output = output,
7+
substitutions = {
8+
"{codeql_cli_path}": codeql_cli_path,
9+
"{test_sources}": str([f.path for f in ctx.files.srcs]),
10+
},
11+
)
12+
return DefaultInfo(
13+
files = depset([output]),
14+
)
15+
16+
_test_script = rule(
17+
implementation = _test_script_impl,
18+
attrs = {
19+
"srcs": attr.label_list(allow_files = True),
20+
"_template": attr.label(default = "//misc/bazel:test.template.py", allow_single_file = True),
21+
},
22+
toolchains = ["//:toolchain_type"],
23+
)
24+
25+
def codeql_test(*, name, srcs, deps):
26+
srcs = native.glob(["test/**/*.ql", "test/**/*.qlref"])
27+
data = srcs + deps
28+
script = name + "-script"
29+
_test_script(
30+
name = script,
31+
srcs = srcs,
32+
)
33+
native.py_test(
34+
name = name,
35+
main = script + ".py",
36+
srcs = [script],
37+
data = data,
38+
)

misc/bazel/test.template.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import os
2+
3+
os.execl("{codeql_cli_path}", "test", "run", "--check-databases", "--", *{test_sources})

misc/bazel/workspace.bzl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
3+
14
def _ql_utils_impl(repository_ctx):
25
root = repository_ctx.path(Label("//:WORKSPACE.bazel")).realpath.dirname
36
repository_ctx.file("BUILD.bazel")
@@ -12,4 +15,24 @@ _ql_utils = repository_rule(
1215
)
1316

1417
def ql_workspace():
15-
_ql_utils(name = "utils")
18+
_ql_utils(name = "ql_utils")
19+
20+
maybe(
21+
repo_rule = http_archive,
22+
name = "rules_pkg",
23+
sha256 = "62eeb544ff1ef41d786e329e1536c1d541bb9bcad27ae984d57f18f314018e66",
24+
urls = [
25+
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz",
26+
"https://github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz",
27+
],
28+
)
29+
30+
maybe(
31+
repo_rule = http_archive,
32+
name = "platforms",
33+
sha256 = "460caee0fa583b908c622913334ec3c1b842572b9c23cf0d3da0c2543a1a157d",
34+
urls = [
35+
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz",
36+
"https://github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz",
37+
],
38+
)

misc/bazel/workspace_deps.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
2+
3+
def ql_workspace_deps():
4+
rules_pkg_dependencies()

swift/.codeqlmanifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"provide": [
33
"ql/lib/qlpack.yml",
44
"ql/test/qlpack.yml",
5-
"extractor_pack/codeql-extractor.yml"
5+
"extractor-pack/codeql-extractor.yml"
66
]
77
}

swift/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
extractor_pack
1+
extractor-pack

swift/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")
2+
load("@rules_pkg//:install.bzl", "pkg_install")
23
load("@ql//:defs.bzl", "codeql_platform")
4+
load("@ql_utils//:source_dir.bzl", "current_source_dir")
35

46
pkg_files(
57
name = "dbscheme",
@@ -52,3 +54,12 @@ pkg_filegroup(
5254
],
5355
visibility = ["//visibility:public"],
5456
)
57+
58+
pkg_install(
59+
name = "create-extractor-pack",
60+
srcs = ["//swift:extractor-pack"],
61+
args = [
62+
"--destdir",
63+
current_source_dir() + "/extractor-pack",
64+
],
65+
)

0 commit comments

Comments
 (0)