mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Swift+Bazel: apply review comments
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
|
||||
workspace(name = "ql")
|
||||
|
||||
load("@ql//misc/bazel:workspace.bzl", "ql_workspace")
|
||||
load("//misc/bazel:workspace.bzl", "ql_workspace")
|
||||
|
||||
ql_workspace()
|
||||
|
||||
load("@ql//misc/bazel:workspace_deps.bzl", "ql_workspace_deps")
|
||||
load("//misc/bazel:workspace_deps.bzl", "ql_workspace_deps")
|
||||
|
||||
ql_workspace_deps()
|
||||
|
||||
@@ -4,14 +4,14 @@ load("@rules_pkg//:mappings.bzl", "pkg_filegroup")
|
||||
|
||||
alias(
|
||||
name = "dbscheme",
|
||||
actual = "@ql//cpp/ql/lib:dbscheme",
|
||||
actual = "//cpp/ql/lib:dbscheme",
|
||||
)
|
||||
|
||||
pkg_filegroup(
|
||||
name = "db-files",
|
||||
srcs = [
|
||||
":dbscheme",
|
||||
"@ql//cpp/downgrades",
|
||||
"@ql//cpp/ql/lib:dbscheme-stats",
|
||||
"//cpp/downgrades",
|
||||
"//cpp/ql/lib:dbscheme-stats",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
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",
|
||||
)
|
||||
@@ -1,11 +0,0 @@
|
||||
def root_source_dir():
|
||||
""" get absolute path to the root source directory
|
||||
|
||||
This can break hermeticity if used in a build step"""
|
||||
return '{root}'
|
||||
|
||||
def current_source_dir():
|
||||
""" get absolute path to the source directory of this bazel package
|
||||
|
||||
This can break hermeticity if used in a build step"""
|
||||
return root_source_dir() + '/' + native.package_name()
|
||||
@@ -1,38 +0,0 @@
|
||||
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,
|
||||
)
|
||||
@@ -1,3 +0,0 @@
|
||||
import os
|
||||
|
||||
os.execl("{codeql_cli_path}", "test", "run", "--check-databases", "--", *{test_sources})
|
||||
@@ -1,22 +1,7 @@
|
||||
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")
|
||||
repository_ctx.template(
|
||||
"source_dir.bzl",
|
||||
Label("@ql//misc/bazel:source_dir.bzl.tpl"),
|
||||
substitutions = {"{root}": str(root)},
|
||||
)
|
||||
|
||||
_ql_utils = repository_rule(
|
||||
implementation = _ql_utils_impl,
|
||||
)
|
||||
|
||||
def ql_workspace():
|
||||
_ql_utils(name = "ql_utils")
|
||||
|
||||
maybe(
|
||||
repo_rule = http_archive,
|
||||
name = "rules_pkg",
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
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")
|
||||
load("//:defs.bzl", "codeql_platform")
|
||||
|
||||
pkg_files(
|
||||
name = "dbscheme",
|
||||
@@ -56,10 +55,13 @@ pkg_filegroup(
|
||||
)
|
||||
|
||||
pkg_install(
|
||||
name = "create-extractor-pack",
|
||||
name = "_create_extractor_pack",
|
||||
srcs = ["//swift:extractor-pack"],
|
||||
args = [
|
||||
"--destdir",
|
||||
current_source_dir() + "/extractor-pack",
|
||||
],
|
||||
)
|
||||
|
||||
py_binary(
|
||||
name = "create-extractor-pack",
|
||||
srcs = ["tools/create_extractor_pack.py"],
|
||||
main = "tools/create_extractor_pack.py",
|
||||
deps = [":_create_extractor_pack"],
|
||||
)
|
||||
|
||||
@@ -6,4 +6,4 @@ The Swift codeql package is an experimental and unsupported work in progress.
|
||||
|
||||
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`.
|
||||
`--search-path=swift`, as the extractor pack is mentioned in `swift/.codeqlmanifest.json`.
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
cc_binary(
|
||||
name = "extractor",
|
||||
srcs = ["main.cpp"],
|
||||
target_compatible_with = select({
|
||||
"@platforms//os:linux": [],
|
||||
"@platforms//os:macos": [],
|
||||
"//conditions:default": ["@platforms//:incompatible"],
|
||||
}),
|
||||
visibility = ["//swift:__pkg__"],
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
name: codeql-swift-tests
|
||||
version: 0.0.0
|
||||
libraryPathDependencies:
|
||||
- codeql/swift-all
|
||||
dependencies:
|
||||
codeql/swift-all: "*"
|
||||
tests: .
|
||||
extractor: swift
|
||||
|
||||
16
swift/tools/create_extractor_pack.py
Normal file
16
swift/tools/create_extractor_pack.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import sys
|
||||
from swift._create_extractor_pack_install_script import main
|
||||
|
||||
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 / 'swift' / 'extractor-pack'
|
||||
shutil.rmtree(dest_dir)
|
||||
os.environ['DESTDIR'] = str(dest_dir)
|
||||
main(sys.argv)
|
||||
Reference in New Issue
Block a user