Skip to content

Commit

Permalink
Bazel: code reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
redsun82 committed Apr 12, 2022
1 parent 664d5ba commit 13b2442
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ http_archive(
],
)

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

ql_utils(name = "utils")
ql_workspace()
14 changes: 0 additions & 14 deletions defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,3 @@ codeql_platform = select({
"@platforms//os:macos": "osx64",
"@platforms//os:windows": "win64",
})

_paths_bzl = """
def source_dir():
return '%s/' + native.package_name()
"""

def _ql_utils_impl(repository_ctx):
root = repository_ctx.path(Label("@ql//:WORKSPACE.bazel")).realpath.dirname
repository_ctx.file("BUILD.bazel")
repository_ctx.file("paths.bzl", content = _paths_bzl % root)

ql_utils = repository_rule(
implementation = _ql_utils_impl,
)
Empty file added misc/bazel/BUILD.bazel
Empty file.
11 changes: 11 additions & 0 deletions misc/bazel/source_dir.bzl.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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()
15 changes: 15 additions & 0 deletions misc/bazel/workspace.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 = "utils")
4 changes: 2 additions & 2 deletions swift/install/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
load("@utils//:paths.bzl", "source_dir")
load("@utils//:source_dir.bzl", "current_source_dir")
load("@rules_pkg//:install.bzl", "pkg_install")

pkg_install(
name = "install",
srcs = ["//swift:extractor-pack"],
args = [
"--destdir",
source_dir() + "/../extractor_pack",
current_source_dir() + "/../extractor_pack",
],
)

0 comments on commit 13b2442

Please sign in to comment.