-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.bzl
51 lines (43 loc) · 1.54 KB
/
rules.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Rules to use the prebuilt buildifier / buildozer binaries
"""
load("//buildifier:buildifier_binary.bzl", _buildifier_binary = "buildifier_binary")
load("//buildozer:buildozer_binary.bzl", _buildozer_binary = "buildozer_binary")
load(
"//buildifier:factory.bzl",
"buildifier_attr_factory",
"buildifier_impl_factory",
)
buildifier_binary = _buildifier_binary
buildozer_binary = _buildozer_binary
def _buildifier_impl(ctx):
return [buildifier_impl_factory(ctx, test_rule = False)]
buildifier = rule(
implementation = _buildifier_impl,
attrs = buildifier_attr_factory(test_rule = False),
toolchains = ["@buildifier_prebuilt//buildifier:toolchain"],
executable = True,
)
def _buildifier_test_impl(ctx):
return [buildifier_impl_factory(ctx, test_rule = True)]
_buildifier_test = rule(
implementation = _buildifier_test_impl,
attrs = buildifier_attr_factory(test_rule = True),
toolchains = ["@buildifier_prebuilt//buildifier:toolchain"],
test = True,
)
def buildifier_test(**kwargs):
"""
Wrapper for the _buildifier_test rule. Optionally disables sandboxing and caching.
Args:
**kwargs: all parameters for _buildifier_test
"""
if kwargs.get("no_sandbox", False):
tags = kwargs.get("tags", [])
# Note: the "external" tag is a workaround for
# https://github.com/bazelbuild/bazel/issues/15516.
for t in ["no-sandbox", "no-cache", "external"]:
if t not in tags:
tags.append(t)
kwargs["tags"] = tags
_buildifier_test(**kwargs)