Skip to content

Commit

Permalink
Bazel: reorganization
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
redsun82 committed Apr 12, 2022
1 parent 13b2442 commit a205b46
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 40 deletions.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.0
28 changes: 4 additions & 24 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,10 @@

workspace(name = "ql")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_pkg",
sha256 = "62eeb544ff1ef41d786e329e1536c1d541bb9bcad27ae984d57f18f314018e66",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz",
],
)

load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

http_archive(
name = "platforms",
sha256 = "460caee0fa583b908c622913334ec3c1b842572b9c23cf0d3da0c2543a1a157d",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz",
],
)

load("@ql//misc/bazel:workspace.bzl", "ql_workspace")

ql_workspace()

load("@ql//misc/bazel:workspace_deps.bzl", "ql_workspace_deps")

ql_workspace_deps()
12 changes: 12 additions & 0 deletions misc/bazel/BUILD.toolchain.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@//misc/bazel:toolchain.bzl", "codeql_cli_toolchain")

codeql_cli_toolchain(
name = "codeql-cli",
path = "{codeql_cli_path}",
)

toolchain(
name = "codeql-cli-toolchain",
toolchain = ":codeql-cli",
toolchain_type = "@//:toolchain_type",
)
38 changes: 38 additions & 0 deletions misc/bazel/test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
def _test_script_impl(ctx):
output = ctx.actions.declare_file("%s.py" % ctx.label.name)
codeql_cli_path = ctx.toolchains["//:toolchain_type"].codeql_cli.path
ctx.actions.expand_template(
template = ctx.file._template,
output = output,
substitutions = {
"{codeql_cli_path}": codeql_cli_path,
"{test_sources}": str([f.path for f in ctx.files.srcs]),
},
)
return DefaultInfo(
files = depset([output]),
)

_test_script = rule(
implementation = _test_script_impl,
attrs = {
"srcs": attr.label_list(allow_files = True),
"_template": attr.label(default = "//misc/bazel:test.template.py", allow_single_file = True),
},
toolchains = ["//:toolchain_type"],
)

def codeql_test(*, name, srcs, deps):
srcs = native.glob(["test/**/*.ql", "test/**/*.qlref"])
data = srcs + deps
script = name + "-script"
_test_script(
name = script,
srcs = srcs,
)
native.py_test(
name = name,
main = script + ".py",
srcs = [script],
data = data,
)
3 changes: 3 additions & 0 deletions misc/bazel/test.template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os

os.execl("{codeql_cli_path}", "test", "run", "--check-databases", "--", *{test_sources})
25 changes: 24 additions & 1 deletion misc/bazel/workspace.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

def _ql_utils_impl(repository_ctx):
root = repository_ctx.path(Label("//:WORKSPACE.bazel")).realpath.dirname
repository_ctx.file("BUILD.bazel")
Expand All @@ -12,4 +15,24 @@ _ql_utils = repository_rule(
)

def ql_workspace():
_ql_utils(name = "utils")
_ql_utils(name = "ql_utils")

maybe(
repo_rule = http_archive,
name = "rules_pkg",
sha256 = "62eeb544ff1ef41d786e329e1536c1d541bb9bcad27ae984d57f18f314018e66",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz",
"https://github.com/bazelbuild/rules_pkg/releases/download/0.6.0/rules_pkg-0.6.0.tar.gz",
],
)

maybe(
repo_rule = http_archive,
name = "platforms",
sha256 = "460caee0fa583b908c622913334ec3c1b842572b9c23cf0d3da0c2543a1a157d",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.3/platforms-0.0.3.tar.gz",
],
)
4 changes: 4 additions & 0 deletions misc/bazel/workspace_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

def ql_workspace_deps():
rules_pkg_dependencies()
2 changes: 1 addition & 1 deletion swift/.codeqlmanifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"provide": [
"ql/lib/qlpack.yml",
"ql/test/qlpack.yml",
"extractor_pack/codeql-extractor.yml"
"extractor-pack/codeql-extractor.yml"
]
}
2 changes: 1 addition & 1 deletion swift/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
extractor_pack
extractor-pack
11 changes: 11 additions & 0 deletions swift/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files")
load("@rules_pkg//:install.bzl", "pkg_install")
load("@ql//:defs.bzl", "codeql_platform")
load("@ql_utils//:source_dir.bzl", "current_source_dir")

pkg_files(
name = "dbscheme",
Expand Down Expand Up @@ -52,3 +54,12 @@ pkg_filegroup(
],
visibility = ["//visibility:public"],
)

pkg_install(
name = "create-extractor-pack",
srcs = ["//swift:extractor-pack"],
args = [
"--destdir",
current_source_dir() + "/extractor-pack",
],
)
5 changes: 3 additions & 2 deletions swift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ The Swift codeql package is an experimental and unsupported work in progress.

## Usage

Run `bazel run //swift/install`, which will install `swift/extractor_pack`. Using `--search-path=swift` will then pick
up the Swift extractor.
Run `bazel run //swift:create-extractor-pack`, which will install `swift/extractor-pack`.
Using `--search-path=swift/extractor-pack` will then pick up the Swift extractor. You can also use
`--search-path=swift`, as the extractor pack is mentioned in `swift/.codeqlmanifest`.
11 changes: 0 additions & 11 deletions swift/install/BUILD.bazel

This file was deleted.

0 comments on commit a205b46

Please sign in to comment.