bazel-lib/lib/repositories.bzl

89 lines
3.6 KiB
Python
Raw Permalink Normal View History

2021-12-09 00:47:45 +00:00
"Macros for loading dependencies and registering toolchains"
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")
load("//lib/private:local_config_platform.bzl", "local_config_platform")
2021-12-09 00:47:45 +00:00
# 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(override_local_config_platform = False):
"""Load dependencies required by aspect rules
Args:
override_local_config_platform: override the @local_config_platform repository with one that adds stardoc
support for loading constraints.bzl.
Should be set in repositories that load @aspect_bazel_lib copy actions and also generate stardoc.
"""
http_archive(
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
urls = [
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
],
)
2021-12-09 00:47:45 +00:00
if override_local_config_platform:
local_config_platform(
name = "local_config_platform",
)
# Re-export the default versions
DEFAULT_JQ_VERSION = _DEFAULT_JQ_VERSION
DEFAULT_YQ_VERSION = _DEFAULT_YQ_VERSION
def register_jq_toolchains(name = "jq", version = DEFAULT_JQ_VERSION, register = True):
2021-12-09 00:47:45 +00:00
"""Registers jq toolchain and repositories
Args:
name: override the prefix for the generated toolchain repositories
version: the version of jq to execute (see https://github.com/stedolan/jq/releases)
register: whether to call through to native.register_toolchains.
Should be True for WORKSPACE users, but false when used under bzlmod extension
2021-12-09 00:47:45 +00:00
"""
for [platform, meta] in JQ_PLATFORMS.items():
2021-12-09 00:47:45 +00:00
jq_platform_repo(
name = "%s_%s" % (name, platform),
2021-12-09 00:47:45 +00:00
platform = platform,
version = version,
2021-12-09 00:47:45 +00:00
)
if register:
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
2021-12-09 00:47:45 +00:00
jq_host_alias_repo(name = name)
2021-12-09 00:47:45 +00:00
jq_toolchains_repo(
name = "%s_toolchains" % name,
user_repository_name = name,
2021-12-09 00:47:45 +00:00
)
2022-04-20 04:45:06 +00:00
def register_yq_toolchains(name = "yq", version = DEFAULT_YQ_VERSION, register = True):
2022-04-20 04:45:06 +00:00
"""Registers yq toolchain and repositories
Args:
name: override the prefix for the generated toolchain repositories
version: the version of yq to execute (see https://github.com/mikefarah/yq/releases)
register: whether to call through to native.register_toolchains.
Should be True for WORKSPACE users, but false when used under bzlmod extension
2022-04-20 04:45:06 +00:00
"""
for [platform, meta] in YQ_PLATFORMS.items():
2022-04-20 04:45:06 +00:00
yq_platform_repo(
name = "%s_%s" % (name, platform),
2022-04-20 04:45:06 +00:00
platform = platform,
version = version,
2022-04-20 04:45:06 +00:00
)
if register:
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
2022-04-20 04:45:06 +00:00
yq_host_alias_repo(name = name)
2022-04-20 04:45:06 +00:00
yq_toolchains_repo(
name = "%s_toolchains" % name,
user_repository_name = name,
2022-04-20 04:45:06 +00:00
)