Skip to content

Commit

Permalink
fix: disable stardoc under bzlmod and windows by default
Browse files Browse the repository at this point in the history
We've been making these exceptions in downstream repos
  • Loading branch information
alexeagle committed Mar 11, 2023
1 parent 5faf59e commit 0354738
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//lib/private:stamping.bzl", "stamp_build_setting")

# Ensure that users building their own rules can dep on our bzl_library targets for their stardoc
Expand All @@ -15,6 +16,23 @@ exports_files(
# Macro that creates targets enabling the use of `--stamp` in Starlark rules
stamp_build_setting(name = "stamp")

# Add a flag indicating that bzlmod is enabled so that we can use select()
# to skip bzlmod-incompatible targets. Note that Bazel does not currently
# support declaring a config_setting directly on --enable_bzlmod, so we
# must use set this flag instead.

config_setting(
name = "bzlmod",
flag_values = {
":flag_bzlmod": "true",
},
)

bool_flag(
name = "flag_bzlmod",
build_setting_default = False,
)

toolchain_type(
name = "jq_toolchain_type",
)
Expand Down
11 changes: 11 additions & 0 deletions lib/private/docs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ def stardoc_with_diff_test(
**kwargs: additional attributes passed to the stardoc() rule, such as for overriding the templates
"""

target_compatible_with = kwargs.pop("target_compatible_with", select({
# stardoc doesn't work under bzlmod:
# https://github.com/bazelbuild/bazel/issues/14140
"@aspect_bazel_lib//lib:bzlmod": ["@platforms//:incompatible"],
# stardoc produces different line endings on Windows
# which makes the diff_test fail
"@platforms//os:windows": ["@platforms//:incompatible"],
"//conditions:default": [],
}))

# Generate MD from .bzl
_stardoc(
name = name,
out = name + "-docgen.md",
input = bzl_library_target + ".bzl",
deps = [bzl_library_target],
tags = ["package:" + native.package_name()], # Tag the package name which will help us reconstruct the write_source_files label in update_docs
target_compatible_with = target_compatible_with,
**kwargs
)

Expand Down

0 comments on commit 0354738

Please sign in to comment.