...

Text file src/github.com/bazelbuild/buildtools/buildifier/buildifier.bzl

Documentation: github.com/bazelbuild/buildtools/buildifier

     1"""
     2The module defines buildifier as a Bazel rule.
     3"""
     4
     5load(
     6    "//buildifier/internal:factory.bzl",
     7    "buildifier_attr_factory",
     8    "buildifier_impl_factory",
     9)
    10
    11def _buildifier_impl(ctx):
    12    return [buildifier_impl_factory(ctx)]
    13
    14_buildifier = rule(
    15    implementation = _buildifier_impl,
    16    attrs = buildifier_attr_factory(),
    17    executable = True,
    18)
    19
    20def buildifier(**kwargs):
    21    """
    22    Wrapper for the _buildifier rule. Adds 'manual' to the tags.
    23
    24    Args:
    25      **kwargs: all parameters for _buildifier
    26    """
    27
    28    tags = kwargs.get("tags", [])
    29    if "manual" not in tags:
    30        tags.append("manual")
    31        kwargs["tags"] = tags
    32    _buildifier(**kwargs)
    33
    34def _buildifier_test_impl(ctx):
    35    return [buildifier_impl_factory(ctx, test_rule = True)]
    36
    37_buildifier_test = rule(
    38    implementation = _buildifier_test_impl,
    39    attrs = buildifier_attr_factory(True),
    40    test = True,
    41)
    42
    43def buildifier_test(**kwargs):
    44    """
    45    Wrapper for the _buildifier_test rule. Optionally disables sandboxing and caching.
    46
    47    Args:
    48      **kwargs: all parameters for _buildifier_test
    49    """
    50    if kwargs.get("no_sandbox", False):
    51        tags = kwargs.get("tags", [])
    52
    53        # Note: the "external" tag is a workaround for
    54        # https://github.com/bazelbuild/bazel/issues/15516.
    55        for t in ["no-sandbox", "no-cache", "external"]:
    56            if t not in tags:
    57                tags.append(t)
    58        kwargs["tags"] = tags
    59    _buildifier_test(**kwargs)

View as plain text