Skip to content

Commit 13b2442

Browse files
committedApr 12, 2022
Bazel: code reorganization
1 parent 664d5ba commit 13b2442

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed
 

‎WORKSPACE.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ http_archive(
2727
],
2828
)
2929

30-
load("@ql//:defs.bzl", "ql_utils")
30+
load("@ql//misc/bazel:workspace.bzl", "ql_workspace")
3131

32-
ql_utils(name = "utils")
32+
ql_workspace()

‎defs.bzl

-14
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,3 @@ codeql_platform = select({
33
"@platforms//os:macos": "osx64",
44
"@platforms//os:windows": "win64",
55
})
6-
7-
_paths_bzl = """
8-
def source_dir():
9-
return '%s/' + native.package_name()
10-
"""
11-
12-
def _ql_utils_impl(repository_ctx):
13-
root = repository_ctx.path(Label("@ql//:WORKSPACE.bazel")).realpath.dirname
14-
repository_ctx.file("BUILD.bazel")
15-
repository_ctx.file("paths.bzl", content = _paths_bzl % root)
16-
17-
ql_utils = repository_rule(
18-
implementation = _ql_utils_impl,
19-
)

‎misc/bazel/BUILD.bazel

Whitespace-only changes.

‎misc/bazel/source_dir.bzl.tpl

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def root_source_dir():
2+
""" get absolute path to the root source directory
3+
4+
This can break hermeticity if used in a build step"""
5+
return '{root}'
6+
7+
def current_source_dir():
8+
""" get absolute path to the source directory of this bazel package
9+
10+
This can break hermeticity if used in a build step"""
11+
return root_source_dir() + '/' + native.package_name()

‎misc/bazel/workspace.bzl

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def _ql_utils_impl(repository_ctx):
2+
root = repository_ctx.path(Label("//:WORKSPACE.bazel")).realpath.dirname
3+
repository_ctx.file("BUILD.bazel")
4+
repository_ctx.template(
5+
"source_dir.bzl",
6+
Label("@ql//misc/bazel:source_dir.bzl.tpl"),
7+
substitutions = {"{root}": str(root)},
8+
)
9+
10+
_ql_utils = repository_rule(
11+
implementation = _ql_utils_impl,
12+
)
13+
14+
def ql_workspace():
15+
_ql_utils(name = "utils")

‎swift/install/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
load("@utils//:paths.bzl", "source_dir")
1+
load("@utils//:source_dir.bzl", "current_source_dir")
22
load("@rules_pkg//:install.bzl", "pkg_install")
33

44
pkg_install(
55
name = "install",
66
srcs = ["//swift:extractor-pack"],
77
args = [
88
"--destdir",
9-
source_dir() + "/../extractor_pack",
9+
current_source_dir() + "/../extractor_pack",
1010
],
1111
)

0 commit comments

Comments
 (0)
Please sign in to comment.