xref: /aosp_15_r20/external/bazelbuild-rules_java/toolchains/fail_rule.bzl (revision abe8e1b943c923005d847f1e3cf6637de4ed1a1f)
1# Copyright 2020 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""A rule than fails during analysis."""
16
17def _fail_rule_impl(ctx):
18    if ctx.attr.header:
19        fail("%s %s" % (ctx.attr.header, ctx.attr.message))
20    else:
21        fail(ctx.attr.message)
22
23fail_rule = rule(
24    doc = "A rule that fails during analysis.",
25    implementation = _fail_rule_impl,
26    attrs = {
27        "header": attr.string(
28            doc = "Header of the message.",
29        ),
30        "message": attr.string(
31            mandatory = True,
32            doc = "Message to display.",
33        ),
34    },
35)
36