xref: /aosp_15_r20/external/bazelbuild-rules_license/rules/check_licenses_shim.bzl (revision f578df4fd057ffe2023728444759535685631548)
1# Copyright 2022 Google LLC
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# https://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"""This module provides a custom Starlark rule used to create wrappers for targets that
15can have blaze build --check_licenses executed against them."""
16
17def _shim_rule_impl(ctx):
18    # This rule doesn't need to return anything. It only exists to propagate the dependency supplied
19    # by the label_flag
20    return []
21
22shim_rule = rule(
23    doc = """This rule exists to configure a dependent target via label. An instantiation of this
24    rule is then used as a dependency for the legacy_check_target rule, which can be built with --check_licenses
25    to get the effect of running --check_licenses on an arbitrary target which may or may not have a distribs
26    attribute""",
27    implementation = _shim_rule_impl,
28    # The definition of this attribute creates a dependency relationship on the manually provided label.
29    attrs = {"target": attr.label(default = ":check_licenses_target")},
30)
31