refactor: nicer pattern for inlined maybe

This commit is contained in:
Alex Eagle 2022-06-10 13:58:40 -07:00
parent d8ec2bc0db
commit 40f130b43b
2 changed files with 61 additions and 63 deletions

View File

@ -4,16 +4,17 @@ Users should *not* need to install these. If users see a load()
statement from these, that's a bug in our distribution.
"""
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Note: we don't use "maybe" because renovate doesn't understand the syntax, see
# https://github.com/renovatebot/renovate/pull/16003/
load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//lib:repositories.bzl", "register_jq_toolchains", "register_yq_toolchains")
# Don't wrap later calls with maybe() as that prevents renovate from parsing our deps
def http_archive(name, **kwargs):
maybe(_http_archive, name = name, **kwargs)
# buildifier: disable=unnamed-macro
def bazel_lib_internal_deps():
"Fetch deps needed for local development"
if not native.existing_rule("build_bazel_integration_testing"):
http_archive(
name = "build_bazel_integration_testing",
urls = [
@ -23,7 +24,6 @@ def bazel_lib_internal_deps():
sha256 = "2401b1369ef44cc42f91dc94443ef491208dbd06da1e1e10b702d8c189f098e3",
)
if not native.existing_rule("io_bazel_rules_go"):
http_archive(
name = "io_bazel_rules_go",
sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
@ -33,7 +33,6 @@ def bazel_lib_internal_deps():
],
)
if not native.existing_rule("bazel_gazelle"):
http_archive(
name = "bazel_gazelle",
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
@ -46,7 +45,6 @@ def bazel_lib_internal_deps():
# Override bazel_skylib distribution to fetch sources instead
# so that the gazelle extension is included
# see https://github.com/bazelbuild/bazel-skylib/issues/250
if not native.existing_rule("bazel_skylib"):
http_archive(
name = "bazel_skylib",
sha256 = "07b4117379dde7ab382345c3b0f5edfc6b7cff6c93756eac63da121e0bbcc5de",
@ -57,7 +55,6 @@ def bazel_lib_internal_deps():
],
)
if not native.existing_rule("io_bazel_stardoc"):
http_archive(
name = "io_bazel_stardoc",
sha256 = "aa814dae0ac400bbab2e8881f9915c6f47c49664bf087c409a15f90438d2c23e",

View File

@ -1,15 +1,16 @@
"Macros for loading dependencies and registering toolchains"
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# Note: we don't use "maybe" because renovate doesn't understand the syntax, see
# https://github.com/renovatebot/renovate/pull/16003/
load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//lib/private:jq_toolchain.bzl", "JQ_PLATFORMS", "jq_host_alias_repo", "jq_platform_repo", "jq_toolchains_repo", _DEFAULT_JQ_VERSION = "DEFAULT_JQ_VERSION")
load("//lib/private:yq_toolchain.bzl", "YQ_PLATFORMS", "yq_host_alias_repo", "yq_platform_repo", "yq_toolchains_repo", _DEFAULT_YQ_VERSION = "DEFAULT_YQ_VERSION")
# Don't wrap later calls with maybe() as that prevents renovate from parsing our deps
def http_archive(name, **kwargs):
maybe(_http_archive, name = name, **kwargs)
def aspect_bazel_lib_dependencies():
"Load dependencies required by aspect rules"
if not native.existing_rule("bazel_skylib"):
http_archive(
name = "bazel_skylib",
sha256 = "c6966ec828da198c5d9adbaa94c05e3a1c7f21bd012a0b29ba8ddbccb2c93b0d",