Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_license//rules:license.bzl", "license")
load("//rules:common_settings.bzl", "bool_flag")
load("//:bzl_library.bzl", "bzl_library")

package(
Expand Down Expand Up @@ -95,3 +96,16 @@ filegroup(
"//toolchains/unittest:distribution",
] + glob(["*.bzl"]),
)

bool_flag(
name = "extract_docs",
build_setting_default = False,
visibility = ["//visibility:public"],
)

config_setting(
name = "extract_docs_flag",
flag_values = {
":extract_docs": "true",
},
)
15 changes: 14 additions & 1 deletion bzl_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ load(

StarlarkLibraryInfo = _StarlarkLibraryInfo

def bzl_library(name, **kwargs):
def bzl_library(name, srcs = [], deps = [], **kwargs):
"""Wrapper for bzl_library.

Args:
Expand All @@ -38,9 +38,22 @@ def bzl_library(name, **kwargs):
_ = kwargs.pop("target_compatible_with", None)
_bzl_library(
name = name,
srcs = srcs,
deps = deps,
compatible_with = [],
exec_compatible_with = [],
features = [],
target_compatible_with = [],
**kwargs
)
enable_doc_extract = select({
Label("//:extract_docs_flag"): hasattr(native, "starlark_doc_extract"),
"//conditions:default": False,
})
if enable_doc_extract:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selects don't work in a macro

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah oops, evaluation is deferred until after the loading phase, at which point both branches were taken and the targets were created anyway. I didn't manage to test this yesterday since it was hard to back-port to 1.7.1.

(Aside: could we get a release of this module? It has been nearly a year)

for i, src in enumerate(srcs):
native.starlark_doc_extract(
name = "{}.doc_extract{}".format(name, i if i > 0 else ""),
src = src,
deps = deps,
)