Skip to content

Commit

Permalink
Easier External Repo Definitions
Browse files Browse the repository at this point in the history
* Making BUILD file content strings public (removing leading `_`) in `deps.bzl`.
  * Adding `_CONTENT` suffix to variable names to be more clear and match the repo attribute name.
* Wrapping dependency `http_archive` definitions with `maybe()`.

This is to more easily allow downstream projects to define the dependency targets (bats-core, etc) with slightly changed attributes if they want/need to.
Changing `urls` or adding `patches`, etc, can be done less verbosely by reusing BUILD file contents defined here.
Applying changes can be done to only the necessary repos, others can still be loaded via `bazel_bats_dependencies()`.
  • Loading branch information
CauhxMilloy authored and filmil committed May 11, 2024
1 parent 16c2529 commit 69415af
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://stackoverflow.com/questions/47192668/idiomatic-retrieval-of-the-bazel-execution-path#
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

_BATS_CORE_BUILD = """
BATS_CORE_BUILD_CONTENT = """
sh_library(
name = "bats_lib",
srcs = glob(["libexec/**"]),
Expand Down Expand Up @@ -69,7 +69,7 @@ sh_library(
exports_files(glob(["test/*.bats"]))
"""

_BATS_ASSERT_BUILD = """
BATS_ASSERT_BUILD_CONTENT = """
filegroup(
name = "load_files",
srcs = [
Expand All @@ -81,7 +81,7 @@ filegroup(
)
"""

_BATS_SUPPORT_BUILD = """
BATS_SUPPORT_BUILD_CONTENT = """
filegroup(
name = "load_files",
srcs = [
Expand All @@ -104,9 +104,10 @@ def bazel_bats_dependencies(
if not sha256:
fail("sha256 for bats-core was not supplied.")

http_archive(
maybe(
http_archive,
name = "bats_core",
build_file_content = _BATS_CORE_BUILD,
build_file_content = BATS_CORE_BUILD_CONTENT,
urls = [
"https://github.com/bats-core/bats-core/archive/refs/tags/v%s.tar.gz" % version,
],
Expand All @@ -119,9 +120,10 @@ def bazel_bats_dependencies(
fail("bats-assert version was set, but was missing set version for dependency bats-support.")
if not bats_assert_sha256:
fail("sha256 for bats-assert was not supplied.")
http_archive(
maybe(
http_archive,
name = "bats_assert",
build_file_content = _BATS_ASSERT_BUILD,
build_file_content = BATS_ASSERT_BUILD_CONTENT,
sha256 = bats_assert_sha256,
strip_prefix = "bats-assert-%s" % bats_assert_version,
urls = [
Expand All @@ -131,9 +133,10 @@ def bazel_bats_dependencies(
if bats_support_version:
if not bats_support_sha256:
fail("sha256 for bats-support was not supplied.")
http_archive(
maybe(
http_archive,
name = "bats_support",
build_file_content = _BATS_SUPPORT_BUILD,
build_file_content = BATS_SUPPORT_BUILD_CONTENT,
sha256 = bats_support_sha256,
strip_prefix = "bats-support-%s" % bats_support_version,
urls = [
Expand Down

0 comments on commit 69415af

Please sign in to comment.