aboutsummaryrefslogtreecommitdiff
path: root/tests/BUILD
blob: 6ceee9ab02ce9958b066377055a3fb937fc63fc1 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Test cases for license rules.

load("@rules_license//rules:compliance.bzl", "check_license", "licenses_used")
load("@rules_license//rules:license.bzl", "license")
load("@rules_license//rules:license_kind.bzl", "license_kind")

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

# license_kind rules generally appear in a central location per workspace. They
# are intermingled with normal target build rules
license_kind(
    name = "generic_notice_license",
    conditions = [
        "notice",
    ],
)

license_kind(
    name = "generic_restricted_license",
    conditions = [
        "restricted",
    ],
)

# The default license for an entire package is typically named "license".
license(
    name = "license",
    package_name = "A test case package",
    # Note the UTF-8 encoded copyright symbol.
    copyright_notice = "Copyright © 2019 Uncle Toasty",
    license_kinds = [":generic_notice_license"],
    # Note. This need not be precise. If a downloader creates the license
    # clause for you, then it should use the absolute download URL.
    package_url = "http://github.com/bazelbuild/rules_license",
    package_version = "0.0.4",
)

license(
    name = "license_for_extra_feature",
    package_name = "A test case package",
    license_kinds = [":generic_restricted_license"],
    license_text = "LICENSE.extra",
)

# This license is not in the "compliance" namespace and
# therefore should not show up in the report verified by
# :verify_cc_app_test
license(
    name = "internal_non_compliance_license",
    namespace = "test_namespace",
)

cc_binary(
    name = "hello",
    srcs = ["hello.cc"],
    deps = [
        ":c_bar",
    ],
)

cc_library(
    name = "c_bar",
    srcs = [
        "bar.cc",
    ],
    applicable_licenses = [
        ":license",
        ":license_for_extra_feature",
        ":internal_non_compliance_license",
    ],
    deps = [
        "@rules_license//tests/legacy:another_library_with_legacy_license_clause",
        "@rules_license//tests/legacy:library_with_legacy_license_clause",
    ],
)

java_binary(
    name = "hello_java",
    srcs = ["Hello.java"],
    # Add an addition license to this target, beyond what my deps have.
    applicable_licenses = [
        ":license_for_extra_feature",
    ],
    javacopts = ["-Xep:DefaultPackage:OFF"],
    main_class = "Hello",
    deps = [
        ":j_bar",
    ],
)

java_library(
    name = "j_bar",
    srcs = ["Bar.java"],
    javacopts = ["-Xep:DefaultPackage:OFF"],
)

check_license(
    name = "check_cc_app",
    check_conditions = False,
    copyright_notices = "hello_cc_copyrights.txt",
    license_texts = "hello_cc_licenses.txt",
    report = "hello_cc_report",
    deps = [
        ":hello",
    ],
)

licenses_used(
    name = "hello_licenses",
    out = "hello_licenses.json",
    deps = [":hello"],
)

py_test(
    name = "hello_licenses_test",
    srcs = ["hello_licenses_test.py"],
    data = [
        ":hello_licenses.json",
        ":hello_cc_copyrights.txt",
    ],
    python_version = "PY3",
    deps = [
        ":license_test_utils",
    ],
)

py_library(
    name = "license_test_utils",
    srcs = ["license_test_utils.py"],
    srcs_version = "PY3",
)

check_license(
    name = "check_java_app",
    check_conditions = False,
    copyright_notices = "hello_java_copyrights.txt",
    license_texts = "hello_java_licenses.txt",
    report = "hello_java_report",
    deps = [
        ":hello_java",
    ],
)


license(
    name = "license_with_generated_text",
    license_text = ":created_license",
    license_kinds = [":generic_notice_license"],
)

genrule(
    name = "created_license",
    outs = ["something.text"],
    cmd = "echo hello >$@",
)