feat: add maybe_http_archive (#270)
This commit is contained in:
parent
3e4604f9f7
commit
f030847908
|
@ -145,6 +145,55 @@ Returns True if the given Label (or stringy version of a label) represents a tar
|
|||
a bool
|
||||
|
||||
|
||||
<a id="maybe_http_archive"></a>
|
||||
|
||||
## maybe_http_archive
|
||||
|
||||
<pre>
|
||||
maybe_http_archive(<a href="#maybe_http_archive-kwargs">kwargs</a>)
|
||||
</pre>
|
||||
|
||||
Adapts a maybe(http_archive, ...) to look like an http_archive.
|
||||
|
||||
This makes WORKSPACE dependencies easier to read and update.
|
||||
|
||||
Typical usage looks like,
|
||||
|
||||
```
|
||||
load("//lib:utils.bzl", http_archive = "maybe_http_archive")
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_js",
|
||||
sha256 = "5bb643d9e119832a383e67f946dc752b6d719d66d1df9b46d840509ceb53e1f1",
|
||||
strip_prefix = "rules_js-1.6.2",
|
||||
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.6.2.tar.gz",
|
||||
)
|
||||
```
|
||||
|
||||
instead of the classic maybe pattern of,
|
||||
|
||||
```
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
|
||||
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "aspect_rules_js",
|
||||
sha256 = "5bb643d9e119832a383e67f946dc752b6d719d66d1df9b46d840509ceb53e1f1",
|
||||
strip_prefix = "rules_js-1.6.2",
|
||||
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.6.2.tar.gz",
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
**PARAMETERS**
|
||||
|
||||
|
||||
| Name | Description | Default Value |
|
||||
| :------------- | :------------- | :------------- |
|
||||
| <a id="maybe_http_archive-kwargs"></a>kwargs | all arguments to pass-forward to http_archive | none |
|
||||
|
||||
|
||||
<a id="path_to_workspace_root"></a>
|
||||
|
||||
## path_to_workspace_root
|
||||
|
|
|
@ -4,13 +4,8 @@ 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 = "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)
|
||||
load("//lib:utils.bzl", http_archive = "maybe_http_archive")
|
||||
|
||||
# buildifier: disable=unnamed-macro
|
||||
def bazel_lib_internal_deps():
|
||||
|
|
|
@ -178,11 +178,10 @@ bzl_library(
|
|||
name = "repositories",
|
||||
srcs = ["repositories.bzl"],
|
||||
deps = [
|
||||
":utils",
|
||||
"//lib/private/docs:jq_toolchain",
|
||||
"//lib/private/docs:local_config_platform",
|
||||
"//lib/private/docs:yq_toolchain",
|
||||
"@bazel_tools//tools/build_defs/repo:http.bzl",
|
||||
"@bazel_tools//tools/build_defs/repo:utils.bzl",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -108,7 +108,11 @@ bzl_library(
|
|||
|
||||
bzl_library(
|
||||
name = "utils",
|
||||
srcs = ["//lib/private:utils.bzl"],
|
||||
srcs = [
|
||||
"//lib/private:utils.bzl",
|
||||
"@bazel_tools//tools/build_defs/repo:http.bzl",
|
||||
"@bazel_tools//tools/build_defs/repo:utils.bzl",
|
||||
],
|
||||
)
|
||||
|
||||
bzl_library(
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
"""General utility functions"""
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive")
|
||||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
|
||||
|
||||
def _propagate_well_known_tags(tags = []):
|
||||
"""Returns a list of tags filtered from the input set that only contains the ones that are considered "well known"
|
||||
|
||||
|
@ -178,12 +181,51 @@ def _is_bazel_6_or_greater():
|
|||
# native.bazel_version only works in repository rules.
|
||||
return "apple_binary" not in dir(native)
|
||||
|
||||
def _maybe_http_archive(**kwargs):
|
||||
"""Adapts a maybe(http_archive, ...) to look like an http_archive.
|
||||
|
||||
This makes WORKSPACE dependencies easier to read and update.
|
||||
|
||||
Typical usage looks like,
|
||||
|
||||
```
|
||||
load("//lib:utils.bzl", http_archive = "maybe_http_archive")
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_js",
|
||||
sha256 = "5bb643d9e119832a383e67f946dc752b6d719d66d1df9b46d840509ceb53e1f1",
|
||||
strip_prefix = "rules_js-1.6.2",
|
||||
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.6.2.tar.gz",
|
||||
)
|
||||
```
|
||||
|
||||
instead of the classic maybe pattern of,
|
||||
|
||||
```
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
|
||||
|
||||
maybe(
|
||||
http_archive,
|
||||
name = "aspect_rules_js",
|
||||
sha256 = "5bb643d9e119832a383e67f946dc752b6d719d66d1df9b46d840509ceb53e1f1",
|
||||
strip_prefix = "rules_js-1.6.2",
|
||||
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.6.2.tar.gz",
|
||||
)
|
||||
```
|
||||
|
||||
Args:
|
||||
**kwargs: all arguments to pass-forward to http_archive
|
||||
"""
|
||||
maybe(_http_archive, **kwargs)
|
||||
|
||||
utils = struct(
|
||||
default_timeout = _default_timeout,
|
||||
file_exists = _file_exists,
|
||||
glob_directories = _glob_directories,
|
||||
is_bazel_6_or_greater = _is_bazel_6_or_greater,
|
||||
is_external_label = _is_external_label,
|
||||
maybe_http_archive = _maybe_http_archive,
|
||||
path_to_workspace_root = _path_to_workspace_root,
|
||||
propagate_well_known_tags = _propagate_well_known_tags,
|
||||
to_label = _to_label,
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
"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")
|
||||
|
||||
# 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)
|
||||
load("//lib:utils.bzl", http_archive = "maybe_http_archive")
|
||||
|
||||
def aspect_bazel_lib_dependencies(override_local_config_platform = False):
|
||||
"""Load dependencies required by aspect rules
|
||||
|
|
|
@ -7,6 +7,7 @@ file_exists = utils.file_exists
|
|||
glob_directories = utils.glob_directories
|
||||
is_bazel_6_or_greater = utils.is_bazel_6_or_greater
|
||||
is_external_label = utils.is_external_label
|
||||
maybe_http_archive = utils.maybe_http_archive
|
||||
path_to_workspace_root = utils.path_to_workspace_root
|
||||
propagate_well_known_tags = utils.propagate_well_known_tags
|
||||
to_label = utils.to_label
|
||||
|
|
Loading…
Reference in New Issue