1# Copyright 2022 Google LLC 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# Examples of applications and interactions with licenses 15 16load("@rules_license//rules:compliance.bzl", "check_license", "licenses_used") 17load("@rules_license//examples/vndor/constant_gen:defs.bzl", "constant_gen") 18 19package( 20 default_package_metadata = ["//:license", "//:package_info"], 21 default_visibility = ["//examples:__subpackages__"], 22) 23 24cc_binary( 25 name = "my_server", 26 srcs = ["server.cc"], 27 deps = [":message"], 28) 29 30# Sample 31constant_gen( 32 name = "message", 33 text = "Hello, world.", 34 var = "server_message", 35) 36 37# TODO(aiuto): Turn this strictly into a compliance test. 38check_license( 39 name = "check_server", 40 check_conditions = False, 41 license_texts = "server_licenses.txt", 42 report = "server_report.txt", 43 deps = [ 44 ":my_server", 45 ], 46) 47 48# 49# Verify the licenses are what we expect. The golden output shows that 50# :my_server only uses the unencumbered license type. 51 52licenses_used( 53 name = "server_licenses", 54 out = "server_licenses.json", 55 deps = [":my_server"], 56) 57 58py_test( 59 name = "server_licenses_test", 60 srcs = ["server_licenses_test.py"], 61 data = [":server_licenses.json"], 62 python_version = "PY3", 63 deps = [ 64 "@rules_license//tests:license_test_utils", 65 ], 66) 67 68# This server uses something under a restricted license 69cc_binary( 70 name = "my_violating_server", 71 srcs = ["server.cc"], 72 deps = [ 73 ":message", 74 "@rules_license//examples/vndor/acme", 75 "@rules_license//examples/vndor/libhhgttg", 76 ], 77) 78