From 677a1b80d06d0319ccbc887621b75464944012a2 Mon Sep 17 00:00:00 2001 From: Derek Cormier Date: Sat, 18 Feb 2023 20:08:12 -0800 Subject: [PATCH 1/2] feat: declare host_repo in bzlmod extension --- lib/extensions.bzl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/extensions.bzl b/lib/extensions.bzl index 97d1b3d81..81d908772 100644 --- a/lib/extensions.bzl +++ b/lib/extensions.bzl @@ -7,12 +7,14 @@ load( "register_jq_toolchains", "register_yq_toolchains", ) +load("//lib/private:host_repo.bzl", "host_repo") def _toolchain_extension(_): register_copy_directory_toolchains(register = False) register_copy_to_directory_toolchains(register = False) register_jq_toolchains(register = False) register_yq_toolchains(register = False) + host_repo(name = "aspect_bazel_lib_host") # TODO: some way for users to control repo name/version of the tools installed ext = module_extension( From b1822c4da5bc71037972813cdc4cc5087d9e796c Mon Sep 17 00:00:00 2001 From: Derek Cormier Date: Sat, 18 Feb 2023 20:09:27 -0800 Subject: [PATCH 2/2] feat: allow additional common args to be passed to update_docs --- docs/docs.md | 3 ++- e2e/bzlmod/BUILD.bazel | 7 +++++++ e2e/bzlmod/MODULE.bazel | 6 ++++++ lib/extensions.bzl | 12 ++++++++++-- lib/private/docs.bzl | 4 +++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/docs.md b/docs/docs.md index fc70eef9f..64ca99852 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -30,7 +30,7 @@ This is helpful for minimizing boilerplate in repos wih lots of stardoc targets. ## update_docs
-update_docs(name)
+update_docs(name, kwargs)
 
Stamps an executable run for writing all stardocs declared with stardoc_with_diff_test to the source tree. @@ -55,5 +55,6 @@ bazel build //docs/... && bazel test //docs/... && bazel run //docs:update | Name | Description | Default Value | | :------------- | :------------- | :------------- | | name | the name of executable target | "update" | +| kwargs | Other common named parameters such as tags or visibility | none | diff --git a/e2e/bzlmod/BUILD.bazel b/e2e/bzlmod/BUILD.bazel index 1635ea1ae..94c33399c 100644 --- a/e2e/bzlmod/BUILD.bazel +++ b/e2e/bzlmod/BUILD.bazel @@ -12,6 +12,7 @@ load("@aspect_bazel_lib//lib:diff_test.bzl", "diff_test") load("@aspect_bazel_lib//lib:jq.bzl", "jq") load("@aspect_bazel_lib//lib:yq.bzl", "yq") load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@aspect_bazel_lib_host//:defs.bzl", "host") bzl_library( name = "defs", @@ -86,3 +87,9 @@ diff_test( # Source directories are not support on remote execution. tags = ["no-remote-exec"], ) + +genrule( + name = "host_bazel_version", + outs = ["host_bazel_version.txt"], + cmd = "echo '%s' > $@" % host.bazel_version, +) diff --git a/e2e/bzlmod/MODULE.bazel b/e2e/bzlmod/MODULE.bazel index e6d67d83f..04c1ac0f7 100644 --- a/e2e/bzlmod/MODULE.bazel +++ b/e2e/bzlmod/MODULE.bazel @@ -12,3 +12,9 @@ local_path_override( module_name = "aspect_bazel_lib", path = "../..", ) + +ext = use_extension("@aspect_bazel_lib//lib:extensions.bzl", "ext") + +ext.host() + +use_repo(ext, "aspect_bazel_lib_host") diff --git a/lib/extensions.bzl b/lib/extensions.bzl index 81d908772..f555c6ec0 100644 --- a/lib/extensions.bzl +++ b/lib/extensions.bzl @@ -9,14 +9,22 @@ load( ) load("//lib/private:host_repo.bzl", "host_repo") -def _toolchain_extension(_): +def _toolchain_extension(mctx): register_copy_directory_toolchains(register = False) register_copy_to_directory_toolchains(register = False) register_jq_toolchains(register = False) register_yq_toolchains(register = False) - host_repo(name = "aspect_bazel_lib_host") + + create_host_repo = False + for module in mctx.modules: + if len(module.tags.host) > 0: + create_host_repo = True + + if create_host_repo: + host_repo(name = "aspect_bazel_lib_host") # TODO: some way for users to control repo name/version of the tools installed ext = module_extension( implementation = _toolchain_extension, + tag_classes = {"host": tag_class(attrs = {})}, ) diff --git a/lib/private/docs.bzl b/lib/private/docs.bzl index 7831d2d02..ad6cc65de 100644 --- a/lib/private/docs.bzl +++ b/lib/private/docs.bzl @@ -27,7 +27,7 @@ def stardoc_with_diff_test( **kwargs ) -def update_docs(name = "update"): +def update_docs(name = "update", **kwargs): """Stamps an executable run for writing all stardocs declared with stardoc_with_diff_test to the source tree. This is to be used in tandem with `stardoc_with_diff_test()` to produce a convenient workflow @@ -45,6 +45,7 @@ def update_docs(name = "update"): Args: name: the name of executable target + **kwargs: Other common named parameters such as `tags` or `visibility` """ update_files = {} @@ -60,4 +61,5 @@ def update_docs(name = "update"): write_source_files( name = name, files = update_files, + **kwargs )