-
Notifications
You must be signed in to change notification settings - Fork 421
/
buildifier.bzl
59 lines (48 loc) · 1.44 KB
/
buildifier.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
52
53
54
55
56
57
58
59
"""
The module defines buildifier as a Bazel rule.
"""
load(
"//buildifier/internal:factory.bzl",
"buildifier_attr_factory",
"buildifier_impl_factory",
)
def _buildifier_impl(ctx):
return [buildifier_impl_factory(ctx)]
_buildifier = rule(
implementation = _buildifier_impl,
attrs = buildifier_attr_factory(),
executable = True,
)
def buildifier(**kwargs):
"""
Wrapper for the _buildifier rule. Adds 'manual' to the tags.
Args:
**kwargs: all parameters for _buildifier
"""
tags = kwargs.get("tags", [])
if "manual" not in tags:
tags.append("manual")
kwargs["tags"] = tags
_buildifier(**kwargs)
def _buildifier_test_impl(ctx):
return [buildifier_impl_factory(ctx, test_rule = True)]
_buildifier_test = rule(
implementation = _buildifier_test_impl,
attrs = buildifier_attr_factory(True),
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)