aboutsummaryrefslogtreecommitdiff
path: root/examples/vndor/constant_gen/BUILD
blob: 5f2ff4346233178a91e6e8b688cc448ba5fa4825 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# An example of a code generator with a distinct license for the generated code.

load("@rules_license//rules:compliance.bzl", "licenses_used")
load("@rules_license//rules:license.bzl", "license")
load(":defs.bzl", "constant_gen")

package(
    default_applicable_licenses = [":license"],
    default_visibility = ["//examples:__subpackages__"],
)

# The default license for an entire package is typically named "license".
license(
    name = "license",
    package_name = "Trivial Code Generator",
    license_kinds = [
        "@rules_license//examples/my_org/licenses:generic_restricted",
    ],
    license_text = "LICENSE",
)

license(
    name = "license_for_emitted_code",
    package_name = "Trivial Code Generator Output",
    license_kinds = [
        "@rules_license//examples/my_org/licenses:unencumbered",
    ],
    license_text = "LICENSE.on_output",
)

# The generator itself will be licensed under :license
py_binary(
    name = "constant_generator",
    srcs = ["constant_generator.py"],
    python_version = "PY3",
)

# Sample: This target will be licensed under :license_for_emitted_code
constant_gen(
    name = "libhello",
    text = "Hello, world.",
    var = "hello_world",
)

# Verify the licenses are what we expect
licenses_used(
    name = "generator_licenses",
    out = "generator_licenses.json",
    deps = [":constant_generator"],
)

licenses_used(
    name = "generated_code_licenses",
    # Note: using default output file name
    deps = [":libhello"],
)

py_test(
    name = "verify_licenses_test",
    srcs = ["verify_licenses_test.py"],
    data = [
        ":generator_licenses.json",
        ":generated_code_licenses.json",
    ],
    python_version = "PY3",
    deps = [
        "//tests:license_test_utils",
    ],
)