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
|
# Test cases for license rules: Sample app
load("@rules_license//rules:compliance.bzl", "licenses_used")
package(default_visibility = ["//examples:__subpackages__"])
# Note that the app explicitly depends only on a library and some legacy
# style licensed code.
cc_binary(
name = "an_app",
srcs = ["an_app.cc"],
deps = [
":level4",
# "@rules_license//rules/tests/legacy:another_library_with_legacy_license_clause",
# "@rules_license//rules/tests/legacy:library_with_legacy_license_clause",
],
)
# pointless chain of libraries to show transitive rule gathering, culminating
# in a diamond dependency on a library under license.
# Note that the lowest level depends on some third party code
[
genrule(
name = "level_%d_src" % level,
outs = ["level_%d.cc" % level],
# Note to reviewers: This should use string format, but format
# is broken when
cmd = """cat >$@ <<END
#include <iostream>
extern void {lower}();
void lib_level_{level}() {{
std::cout << "This is level {level}" << std::endl;
{lower}();
}}
END
""".format(
level = level,
lower = "lib_level_%d" % (level - 1) if level > 0 else "new_lib_func",
),
)
for level in range(5)
]
[
cc_library(
name = "level%d" % level,
srcs = [":level_%d.cc" % level],
deps = [
(":level%d" % (level - 1) if level > 0 else "@rules_license//tests/thrdparty:new_style_lib"),
],
)
for level in range(5)
]
licenses_used(
name = "an_app_licenses",
out = "an_app_licenses.json",
deps = [":an_app"],
)
# Examining the golden file shows that we depend on both kinds of license.
py_test(
name = "an_app_licenses_test",
srcs = ["an_app_licenses_test.py"],
data = [":an_app_licenses.json"],
python_version = "PY3",
deps = [
"@rules_license//tests:license_test_utils",
],
)
|