xref: /aosp_15_r20/external/bazelbuild-rules_license/examples/vndor/constant_gen/BUILD (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# An example of a code generator with a distinct license for the generated code.
15
16load("@rules_license//rules:compliance.bzl", "licenses_used")
17load("@rules_license//rules:license.bzl", "license")
18load(":defs.bzl", "constant_gen")
19
20package(
21    default_applicable_licenses = [":license"],
22    default_visibility = ["//examples:__subpackages__"],
23)
24
25# The default license for an entire package is typically named "license".
26license(
27    name = "license",
28    package_name = "Trivial Code Generator",
29    license_kinds = [
30        "@rules_license//examples/my_org/licenses:generic_restricted",
31    ],
32    license_text = "LICENSE",
33)
34
35license(
36    name = "license_for_emitted_code",
37    package_name = "Trivial Code Generator Output",
38    license_kinds = [
39        "@rules_license//examples/my_org/licenses:unencumbered",
40    ],
41    license_text = "LICENSE.on_output",
42)
43
44# The generator itself will be licensed under :license
45py_binary(
46    name = "constant_generator",
47    srcs = ["constant_generator.py"],
48    python_version = "PY3",
49)
50
51# Sample: This target will be licensed under :license_for_emitted_code
52constant_gen(
53    name = "libhello",
54    text = "Hello, world.",
55    var = "hello_world",
56)
57
58# Verify the licenses are what we expect
59licenses_used(
60    name = "generator_licenses",
61    out = "generator_licenses.json",
62    deps = [":constant_generator"],
63)
64
65licenses_used(
66    name = "generated_code_licenses",
67    # Note: using default output file name
68    deps = [":libhello"],
69)
70
71py_test(
72    name = "verify_licenses_test",
73    srcs = ["verify_licenses_test.py"],
74    data = [
75        ":generator_licenses.json",
76        ":generated_code_licenses.json",
77    ],
78    python_version = "PY3",
79    deps = [
80        "//tests:license_test_utils",
81    ],
82)
83