xref: /aosp_15_r20/external/bazelbuild-rules_license/tests/BUILD (revision f578df4fd057ffe2023728444759535685631548)
1# Test cases for license rules.
2
3load("@rules_license//rules:compliance.bzl", "check_license", "licenses_used")
4load("@rules_license//rules:license.bzl", "license")
5load("@rules_license//rules:license_kind.bzl", "license_kind")
6
7package(
8    default_applicable_licenses = [":license"],
9    default_visibility = [
10        "//examples:__subpackages__",
11        "//tests:__subpackages__",
12    ],
13)
14
15# license_kind rules generally appear in a central location per workspace. They
16# are intermingled with normal target build rules
17license_kind(
18    name = "generic_notice_license",
19    conditions = [
20        "notice",
21    ],
22)
23
24license_kind(
25    name = "generic_restricted_license",
26    conditions = [
27        "restricted",
28    ],
29)
30
31# The default license for an entire package is typically named "license".
32license(
33    name = "license",
34    package_name = "A test case package",
35    # Note the UTF-8 encoded copyright symbol.
36    copyright_notice = "Copyright © 2019 Uncle Toasty",
37    license_kinds = [":generic_notice_license"],
38    # Note. This need not be precise. If a downloader creates the license
39    # clause for you, then it should use the absolute download URL.
40    package_url = "http://github.com/bazelbuild/rules_license",
41    package_version = "0.0.4",
42)
43
44license(
45    name = "license_for_extra_feature",
46    package_name = "A test case package",
47    license_kinds = [":generic_restricted_license"],
48    license_text = "LICENSE.extra",
49)
50
51# This license is not in the "compliance" namespace and
52# therefore should not show up in the report verified by
53# :verify_cc_app_test
54license(
55    name = "internal_non_compliance_license",
56    namespace = "test_namespace",
57)
58
59cc_binary(
60    name = "hello",
61    srcs = ["hello.cc"],
62    deps = [
63        ":c_bar",
64    ],
65)
66
67cc_library(
68    name = "c_bar",
69    srcs = [
70        "bar.cc",
71    ],
72    applicable_licenses = [
73        ":license",
74        ":license_for_extra_feature",
75        ":internal_non_compliance_license",
76    ],
77    deps = [
78        "@rules_license//tests/legacy:another_library_with_legacy_license_clause",
79        "@rules_license//tests/legacy:library_with_legacy_license_clause",
80    ],
81)
82
83java_binary(
84    name = "hello_java",
85    srcs = ["Hello.java"],
86    # Add an addition license to this target, beyond what my deps have.
87    applicable_licenses = [
88        ":license_for_extra_feature",
89    ],
90    javacopts = ["-Xep:DefaultPackage:OFF"],
91    main_class = "Hello",
92    deps = [
93        ":j_bar",
94    ],
95)
96
97java_library(
98    name = "j_bar",
99    srcs = ["Bar.java"],
100    javacopts = ["-Xep:DefaultPackage:OFF"],
101)
102
103check_license(
104    name = "check_cc_app",
105    check_conditions = False,
106    copyright_notices = "hello_cc_copyrights.txt",
107    license_texts = "hello_cc_licenses.txt",
108    report = "hello_cc_report",
109    deps = [
110        ":hello",
111    ],
112)
113
114licenses_used(
115    name = "hello_licenses",
116    out = "hello_licenses.json",
117    deps = [":hello"],
118)
119
120py_test(
121    name = "hello_licenses_test",
122    srcs = ["hello_licenses_test.py"],
123    data = [
124        ":hello_licenses.json",
125        ":hello_cc_copyrights.txt",
126    ],
127    python_version = "PY3",
128    deps = [
129        ":license_test_utils",
130    ],
131)
132
133py_library(
134    name = "license_test_utils",
135    srcs = ["license_test_utils.py"],
136    srcs_version = "PY3",
137)
138
139check_license(
140    name = "check_java_app",
141    check_conditions = False,
142    copyright_notices = "hello_java_copyrights.txt",
143    license_texts = "hello_java_licenses.txt",
144    report = "hello_java_report",
145    deps = [
146        ":hello_java",
147    ],
148)
149
150
151license(
152    name = "license_with_generated_text",
153    license_text = ":created_license",
154    license_kinds = [":generic_notice_license"],
155)
156
157genrule(
158    name = "created_license",
159    outs = ["something.text"],
160    cmd = "echo hello >$@",
161)
162
163