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