aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/README.md2
-rw-r--r--examples/manifest/BUILD41
-rw-r--r--examples/manifest/android_mock.bzl61
-rw-r--r--examples/manifest/license_display.sh7
-rwxr-xr-xexamples/manifest/main.sh10
-rw-r--r--examples/manifest/main_golden.txt406
-rw-r--r--examples/my_org/compliance/BUILD31
-rw-r--r--examples/my_org/licenses/BUILD15
-rw-r--r--examples/policy_checker/BUILD63
-rw-r--r--examples/policy_checker/license_policy.bzl56
-rw-r--r--examples/policy_checker/license_policy_check.bzl90
-rw-r--r--examples/policy_checker/license_policy_provider.bzl24
-rw-r--r--examples/sboms/BUILD13
-rw-r--r--examples/src/BUILD79
-rw-r--r--examples/src/mobile.cc20
-rw-r--r--examples/src/server.cc4
-rw-r--r--examples/src/server_licenses.golden32
-rw-r--r--examples/src/server_licenses_test.py46
-rw-r--r--examples/src/server_report.golden3
-rw-r--r--examples/vendor/acme/BUILD22
-rw-r--r--examples/vendor/constant_gen/generated_code_licenses.golden17
-rw-r--r--examples/vendor/constant_gen/generator_licenses.golden17
-rw-r--r--examples/vendor/libhhgttg/BUILD25
-rw-r--r--examples/vndor/README.md (renamed from examples/vendor/README.md)0
-rw-r--r--examples/vndor/acme/ACME_LICENSE (renamed from examples/vendor/acme/ACME_LICENSE)0
-rw-r--r--examples/vndor/acme/BUILD35
-rw-r--r--examples/vndor/acme/coyote.cc (renamed from examples/vendor/acme/coyote.cc)3
-rw-r--r--examples/vndor/constant_gen/BUILD (renamed from examples/vendor/constant_gen/BUILD)43
-rw-r--r--examples/vndor/constant_gen/LICENSE (renamed from examples/vendor/constant_gen/LICENSE)0
-rw-r--r--examples/vndor/constant_gen/LICENSE.on_output (renamed from examples/vendor/constant_gen/LICENSE.on_output)0
-rw-r--r--examples/vndor/constant_gen/constant_generator.py (renamed from examples/vendor/constant_gen/constant_generator.py)4
-rw-r--r--examples/vndor/constant_gen/defs.bzl (renamed from examples/vendor/constant_gen/defs.bzl)9
-rw-r--r--examples/vndor/constant_gen/verify_licenses_test.py40
-rw-r--r--examples/vndor/libhhgttg/BUILD38
-rw-r--r--examples/vndor/libhhgttg/LICENSE (renamed from examples/vendor/libhhgttg/LICENSE)0
-rw-r--r--examples/vndor/libhhgttg/answer.cc (renamed from examples/vendor/libhhgttg/answer.cc)2
36 files changed, 1027 insertions, 231 deletions
diff --git a/examples/README.md b/examples/README.md
index 0afb5ca..fede271 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -9,7 +9,7 @@ Terminology
- SCM: source code management system. These examples assume that
an organization has a SCM that can enforce ownership restrictions on
specific folder trees. Targets are divided into BUILD files that are
- reviewed by engineers vs. those that are reviewed by an organization's
+ reviewed by engineers vs. those that are reviewed by an organizations
compliance team.
## Overview
diff --git a/examples/manifest/BUILD b/examples/manifest/BUILD
new file mode 100644
index 0000000..d308a59
--- /dev/null
+++ b/examples/manifest/BUILD
@@ -0,0 +1,41 @@
+load(":android_mock.bzl", "android_binary", "android_library")
+load("@rules_license//tools:test_helpers.bzl", "golden_cmd_test")
+
+
+# These two rules today capture what an android_binary would look like.
+# This rule represents the Android specific code that displays licenses
+# on the display. Note that it does not depend on anything to get the
+# license contents; the implementation of these rules macros handle that
+# detail.
+android_library(
+ name = "licenses",
+ srcs = [
+ "license_display.sh",
+ ],
+ data = [
+ "@rules_license//distro:distro",
+ ],
+)
+
+# This captures how the application would be built. The dependencies of this
+# rule are crawled to identify third-party licenses in use. The macro definition
+# of this rule creates a graph to capture that process of identifying licenses,
+# building the licenses target, and finally invoking the "real" android_binary
+# rule to build the final output with the injected license content.
+android_binary(
+ name = "main",
+ srcs = ["main.sh"],
+ deps = [
+ ],
+ data = [
+ ":licenses",
+ ],
+)
+
+golden_cmd_test(
+ name = "main_test",
+ srcs = [],
+ cmd = "$(location :main)",
+ tools = [":main"],
+ golden = "main_golden.txt",
+)
diff --git a/examples/manifest/android_mock.bzl b/examples/manifest/android_mock.bzl
new file mode 100644
index 0000000..0dee3c9
--- /dev/null
+++ b/examples/manifest/android_mock.bzl
@@ -0,0 +1,61 @@
+load("@rules_license//rules:compliance.bzl", "manifest")
+
+"""This is a proof of concept to show how to modify a macro definition to
+create a sub-graph allowing for build time injection of license information. We
+use Android-inspired rule names since these are a likely candidate for this
+sort of injection."""
+
+def android_library(name, **kwargs):
+ # This is an approximation for demo purposes.
+
+ data = kwargs.pop("data", [])
+ native.filegroup(
+ name = name,
+ srcs = data + kwargs.get("srcs", []),
+ )
+
+ # Inject the data dependency into the library, preserving any other data it has.
+ native.sh_library(
+ name = name + "_w_licenses",
+ data = data + [name + "_manifest.txt"],
+ **kwargs
+ )
+
+def android_binary(name, **kwargs):
+ # Same observation about not being sloppy with mapping deps, but I think the only important attribute
+ # in android_binary is deps, but need to double-check.
+ native.filegroup(
+ name = name + "_no_licenses",
+ srcs = kwargs.get("data", []),
+ )
+
+ mf_name = name + "_manifest"
+ manifest(
+ name = mf_name,
+ deps = [":" + name + "_no_licenses"],
+ )
+
+ # This uses the conditions tool to generate an approximation of a compliance report
+ # to demonstrate how license data can be plumbed and made available at build time.
+ native.genrule(
+ name = "gen_" + name + "_manifest",
+ srcs = [":" + mf_name],
+ outs = ["licenses_manifest.txt"],
+ cmd = "cat $(locations :%s) > $@" % mf_name,
+ )
+
+ # Swap out the :licenses dep for our new :licenses_w_licenses dep
+ newdeps = []
+ deps = kwargs.get("data", [])
+ for dep in deps:
+ if dep == ":licenses":
+ newdeps.append(":licenses_w_licenses")
+ else:
+ newdeps.append(dep)
+ kwargs["data"] = newdeps
+
+ # Compile the executable with the user's originally supplied name, but with the new content.
+ native.sh_binary(
+ name = name,
+ **kwargs
+ )
diff --git a/examples/manifest/license_display.sh b/examples/manifest/license_display.sh
new file mode 100644
index 0000000..f96b3ba
--- /dev/null
+++ b/examples/manifest/license_display.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+function display_licenses {
+ echo -n "Licenses: "
+ cat "$0.runfiles/rules_license/examples/manifest/licenses_manifest.txt"
+ echo
+}
diff --git a/examples/manifest/main.sh b/examples/manifest/main.sh
new file mode 100755
index 0000000..4f80a5c
--- /dev/null
+++ b/examples/manifest/main.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+#source gbash.sh || exit
+
+#source "$RUNFILES/google3/tools/build_defs/license/examples/manifest/license_display.sh"
+source "$0.runfiles/rules_license/examples/manifest/license_display.sh"
+#source module google3/tools/build_defs/license/examples/manifest/license_display.sh
+
+echo "I am a program that uses open source code."
+display_licenses
diff --git a/examples/manifest/main_golden.txt b/examples/manifest/main_golden.txt
new file mode 100644
index 0000000..02a32de
--- /dev/null
+++ b/examples/manifest/main_golden.txt
@@ -0,0 +1,406 @@
+I am a program that uses open source code.
+Licenses:
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
diff --git a/examples/my_org/compliance/BUILD b/examples/my_org/compliance/BUILD
deleted file mode 100644
index 074b21e..0000000
--- a/examples/my_org/compliance/BUILD
+++ /dev/null
@@ -1,31 +0,0 @@
-# Example license policy definitions.
-
-load("@rules_license//rules:license_policy.bzl", "license_policy")
-
-package(default_visibility = ["//examples:__subpackages__"])
-
-# license_policy rules generally appear in a central location per workspace. They
-# are intermingled with normal target build rules
-license_policy(
- name = "production_service",
- conditions = [
- "notice",
- "restricted_if_statically_linked",
- ],
-)
-
-license_policy(
- name = "mobile_application",
- conditions = [
- "notice",
- ],
-)
-
-license_policy(
- name = "special_whitelisted_app",
- # There could be a whitelist of targets here.
- conditions = [
- "notice",
- "whitelist:acme_corp_paid",
- ],
-)
diff --git a/examples/my_org/licenses/BUILD b/examples/my_org/licenses/BUILD
index d9d5c25..c200d37 100644
--- a/examples/my_org/licenses/BUILD
+++ b/examples/my_org/licenses/BUILD
@@ -1,3 +1,16 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
# Example license kind definitions.
# We expect that all license_kind rules used by an organization exist in a
@@ -53,6 +66,6 @@ license_kind(
license_kind(
name = "acme_corp_paid",
conditions = [
- "whitelist:acme_corp_paid",
+ "allowlist:acme_corp_paid",
],
)
diff --git a/examples/policy_checker/BUILD b/examples/policy_checker/BUILD
new file mode 100644
index 0000000..49f77aa
--- /dev/null
+++ b/examples/policy_checker/BUILD
@@ -0,0 +1,63 @@
+# Example of automated license policy definitions.
+
+load("@rules_license//examples/policy_checker:license_policy.bzl", "license_policy")
+load("@rules_license//examples/policy_checker:license_policy_check.bzl", "license_policy_check")
+
+package(default_package_metadata = ["//:license", "//:package_info"])
+
+# license_policy rules generally appear in a central location per workspace. That
+# should be access controlled by the policy team.
+
+# A production service can use licenses with most conditions
+license_policy(
+ name = "production_service",
+ conditions = [
+ "notice",
+ "restricted_if_statically_linked",
+ ],
+)
+
+# A mobile application usually can not allow end-user replacable libraries.
+# So LGPL code (which is restricted_if_statically_linked) can not be used.
+license_policy(
+ name = "mobile_application",
+ conditions = [
+ "notice",
+ ],
+)
+
+license_policy(
+ name = "special_allowlisted_app",
+ # There could be a allowlist of targets here.
+ conditions = [
+ "notice",
+ "allowlist:acme_corp_paid",
+ ],
+)
+
+# Now we might build checks of critical applications against policies
+#
+# Questions to consider?
+# - Your organization migth want to fold these kinds of checks into
+# wrapper macros around the rules which generate services and apps
+# - You might want to distribute checks to rules alongside the products
+# - Or, you might want to consolidate them in a single place where your
+# compliance team owns them, as this example does
+
+license_policy_check(
+ name = "check_server",
+ policy = ":production_service",
+ target = "//examples/src:my_server",
+)
+
+
+# This is marked manual, so bazel test ... does not fail. Try it yourself with
+# bazel build :check_violating_server
+license_policy_check(
+ name = "check_violating_server",
+ policy = ":production_service",
+ tags = [
+ "manual",
+ ],
+ target = "//examples/src:my_violating_server",
+)
diff --git a/examples/policy_checker/license_policy.bzl b/examples/policy_checker/license_policy.bzl
new file mode 100644
index 0000000..51d6776
--- /dev/null
+++ b/examples/policy_checker/license_policy.bzl
@@ -0,0 +1,56 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""license_policy rule.
+
+A license_policy names a set of conditions allowed in the union of all
+license_kinds use by a target. The name of the rule is typically an
+application type (e.g. production_server, mobile_application, ...)
+
+"""
+
+load(
+ "@rules_license//examples/policy_checker:license_policy_provider.bzl",
+ "LicensePolicyInfo"
+)
+
+def _license_policy_impl(ctx):
+ provider = LicensePolicyInfo(
+ name = ctx.attr.name,
+ label = "@%s//%s:%s" % (
+ ctx.label.workspace_name,
+ ctx.label.package,
+ ctx.label.name,
+ ),
+ conditions = ctx.attr.conditions,
+ )
+ return [provider]
+
+_license_policy = rule(
+ implementation = _license_policy_impl,
+ attrs = {
+ "conditions": attr.string_list(
+ doc = "Conditions to be met when using software under this license." +
+ " Conditions are defined by the organization using this license.",
+ mandatory = True,
+ ),
+ },
+)
+
+def license_policy(name, conditions):
+ _license_policy(
+ name = name,
+ conditions = conditions,
+ applicable_licenses = [],
+ )
diff --git a/examples/policy_checker/license_policy_check.bzl b/examples/policy_checker/license_policy_check.bzl
new file mode 100644
index 0000000..bb35eee
--- /dev/null
+++ b/examples/policy_checker/license_policy_check.bzl
@@ -0,0 +1,90 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""License compliance checking at analysis time."""
+
+load(
+ "@rules_license//examples/policy_checker:license_policy_provider.bzl",
+ "LicensePolicyInfo",
+)
+load(
+ "@rules_license//rules:gather_licenses_info.bzl",
+ "gather_licenses_info",
+)
+load("@rules_license//rules:providers.bzl", "LicenseInfo")
+load("@rules_license//rules/private:gathering_providers.bzl", "TransitiveLicensesInfo")
+
+# This is a crude example of the kind of thing which can be done.
+def _license_policy_check_impl(ctx):
+ policy = ctx.attr.policy[LicensePolicyInfo]
+ allowed_conditions = policy.conditions
+ if TransitiveLicensesInfo in ctx.attr.target:
+ for license in ctx.attr.target[TransitiveLicensesInfo].licenses.to_list():
+ for kind in license.license_kinds:
+ # print(kind.conditions)
+ for condition in kind.conditions:
+ if condition not in allowed_conditions:
+ fail("Condition %s violates policy %s" % (
+ condition,
+ policy.label,
+ ))
+
+ if LicenseInfo in ctx.attr.target:
+ for license in ctx.attr.target[LicenseInfo].licenses.to_list():
+ for kind in license.license_kinds:
+ # print(kind.conditions)
+ for condition in kind.conditions:
+ if condition not in allowed_conditions:
+ fail("Condition %s violates policy %s" % (
+ condition,
+ policy.label,
+ ))
+ return [DefaultInfo()]
+
+_license_policy_check = rule(
+ implementation = _license_policy_check_impl,
+ doc = """Internal implementation method for license_policy_check().""",
+ attrs = {
+ "policy": attr.label(
+ doc = """Policy definition.""",
+ mandatory = True,
+ providers = [LicensePolicyInfo],
+ ),
+ "target": attr.label(
+ doc = """Target to collect LicenseInfo for.""",
+ aspects = [gather_licenses_info],
+ mandatory = True,
+ allow_single_file = True,
+ ),
+ },
+)
+
+def license_policy_check(name, target, policy, **kwargs):
+ """Checks a target against a policy.
+
+ Args:
+ name: The target.
+ target: A target to test for compliance with a policy
+ policy: A rule providing LicensePolicyInfo.
+ **kwargs: other args.
+
+ Usage:
+
+ license_policy_check(
+ name = "license_info",
+ target = ":my_app",
+ policy = "//my_org/compliance/policies:mobile_application",
+ )
+ """
+ _license_policy_check(name = name, target = target, policy = policy, **kwargs)
diff --git a/examples/policy_checker/license_policy_provider.bzl b/examples/policy_checker/license_policy_provider.bzl
new file mode 100644
index 0000000..caecce8
--- /dev/null
+++ b/examples/policy_checker/license_policy_provider.bzl
@@ -0,0 +1,24 @@
+# Copyright 2020 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""LicensePolicyProvider."""
+
+LicensePolicyInfo = provider(
+ doc = """Declares a policy name and the license conditions allowable under it.""",
+ fields = {
+ "conditions": "List of conditions to be met when using this software.",
+ "label": "The full path to the license policy definition.",
+ "name": "License policy name",
+ },
+)
diff --git a/examples/sboms/BUILD b/examples/sboms/BUILD
new file mode 100644
index 0000000..0c31a04
--- /dev/null
+++ b/examples/sboms/BUILD
@@ -0,0 +1,13 @@
+# Demonstrate the generate_sbom rule
+
+load("@rules_license//rules:sbom.bzl", "generate_sbom")
+
+# There are not a lot of targets in this rule set to build a SBOM from
+# so we will (in a very self-referential way) generate one for the tool
+# which generates the SBOMs
+# See the output in bazel-bin/examples/sboms/write_sbom.txt
+generate_sbom(
+ name = "write_sbom_sbom",
+ out = "write_sbom.txt",
+ deps = ["//tools:write_sbom"],
+)
diff --git a/examples/src/BUILD b/examples/src/BUILD
index 29b6803..cd5e985 100644
--- a/examples/src/BUILD
+++ b/examples/src/BUILD
@@ -1,17 +1,30 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
# Examples of applications and interactions with licenses
-load("@rules_license//examples/vendor/constant_gen:defs.bzl", "constant_gen")
-load("@rules_license//rules:compliance.bzl", "licenses_used")
-load("@rules_license//rules:license_policy_check.bzl", "license_policy_check")
-load("@rules_license//tools:test_helpers.bzl", "golden_test")
+load("@rules_license//rules:compliance.bzl", "check_license", "licenses_used")
+load("@rules_license//examples/vndor/constant_gen:defs.bzl", "constant_gen")
+
+package(
+ default_package_metadata = ["//:license", "//:package_info"],
+ default_visibility = ["//examples:__subpackages__"],
+)
cc_binary(
name = "my_server",
srcs = ["server.cc"],
- deps = [
- ":message",
- "@rules_license//examples/vendor/libhhgttg",
- ],
+ deps = [":message"],
)
# Sample
@@ -21,32 +34,17 @@ constant_gen(
var = "server_message",
)
-license_policy_check(
+# TODO(aiuto): Turn this strictly into a compliance test.
+check_license(
name = "check_server",
- policy = "@rules_license//examples/my_org/compliance:production_service",
- target = ":my_server",
-)
-
-cc_binary(
- name = "my_violating_server",
- srcs = ["server.cc"],
+ check_conditions = False,
+ license_texts = "server_licenses.txt",
+ report = "server_report.txt",
deps = [
- ":message",
- "@rules_license//examples/vendor/acme",
- "@rules_license//examples/vendor/libhhgttg",
+ ":my_server",
],
)
-license_policy_check(
- name = "check_violating_server",
- policy = "@rules_license//examples/my_org/compliance:production_service",
- tags = [
- "manual",
- "notap",
- ],
- target = ":my_violating_server",
-)
-
#
# Verify the licenses are what we expect. The golden output shows that
# :my_server only uses the unencumbered license type.
@@ -57,8 +55,23 @@ licenses_used(
deps = [":my_server"],
)
-golden_test(
- name = "verify_server_licenses_test",
- golden = "server_licenses.golden",
- subject = ":server_licenses.json",
+py_test(
+ name = "server_licenses_test",
+ srcs = ["server_licenses_test.py"],
+ data = [":server_licenses.json"],
+ python_version = "PY3",
+ deps = [
+ "@rules_license//tests:license_test_utils",
+ ],
+)
+
+# This server uses something under a restricted license
+cc_binary(
+ name = "my_violating_server",
+ srcs = ["server.cc"],
+ deps = [
+ ":message",
+ "@rules_license//examples/vndor/acme",
+ "@rules_license//examples/vndor/libhhgttg",
+ ],
)
diff --git a/examples/src/mobile.cc b/examples/src/mobile.cc
deleted file mode 100644
index d15090f..0000000
--- a/examples/src/mobile.cc
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2020 Google LLC
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-
-#include <iostream>
-
-int main(int argc, char* argv[]) {
- std::cout << "Hello world" << std::endl;
-}
diff --git a/examples/src/server.cc b/examples/src/server.cc
index 8f7990e..8229fc1 100644
--- a/examples/src/server.cc
+++ b/examples/src/server.cc
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -11,8 +11,8 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-
#include <iostream>
+#include <ostream>
extern const char* server_message;
diff --git a/examples/src/server_licenses.golden b/examples/src/server_licenses.golden
deleted file mode 100644
index 57df1b3..0000000
--- a/examples/src/server_licenses.golden
+++ /dev/null
@@ -1,32 +0,0 @@
-[
- {
- "rule": "//examples/vendor/constant_gen:license_for_emitted_code",
- "license_kinds": [
- {
- "target": "@//examples/my_org/licenses:unencumbered",
- "name": "unencumbered",
- "conditions": []
- }
- ],
- "copyright_notice": "",
- "package_name": "Trivial Code Generator Output",
- "package_url": null,
- "package_version": null,
- "license_text": "examples/vendor/constant_gen/LICENSE"
- },
- {
- "rule": "//examples/vendor/libhhgttg:license",
- "license_kinds": [
- {
- "target": "@//examples/my_org/licenses:generic_notice",
- "name": "generic_notice",
- "conditions": ["notice"]
- }
- ],
- "copyright_notice": "",
- "package_name": "",
- "package_url": null,
- "package_version": null,
- "license_text": "examples/vendor/libhhgttg/LICENSE"
- }
-]
diff --git a/examples/src/server_licenses_test.py b/examples/src/server_licenses_test.py
new file mode 100644
index 0000000..66a20a5
--- /dev/null
+++ b/examples/src/server_licenses_test.py
@@ -0,0 +1,46 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Tests for license/examples/src."""
+
+import os
+
+import unittest
+from tests import license_test_utils
+
+
+class ServerLicensesTest(unittest.TestCase):
+
+ def test_has_expected_licenses(self):
+ package_base = license_test_utils.LICENSE_PACKAGE_BASE
+ licenses_info = license_test_utils.load_licenses_info(
+ os.path.join(os.path.dirname(__file__), "server_licenses.json"))
+ licenses_info = license_test_utils.filter_dependencies(
+ licenses_info,
+ target_filter=lambda targ: targ.startswith(package_base),
+ licenses_filter=lambda lic: lic.startswith(package_base))
+
+ expected = {
+ "/examples/src:message_src_": [
+ "/examples/vndor/constant_gen:license_for_emitted_code"
+ ],
+ "/examples/src:message": [
+ "/examples/vndor/constant_gen:license_for_emitted_code"
+ ],
+ }
+ license_test_utils.check_licenses_of_dependencies(
+ self, licenses_info, expected)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/examples/src/server_report.golden b/examples/src/server_report.golden
deleted file mode 100644
index 6d322b1..0000000
--- a/examples/src/server_report.golden
+++ /dev/null
@@ -1,3 +0,0 @@
-= @rules_license//examples/vendor/constant_gen:license_for_emitted_code
- kind: @@rules_license//examples/my_org/licenses:unencumbered
- conditions: []
diff --git a/examples/vendor/acme/BUILD b/examples/vendor/acme/BUILD
deleted file mode 100644
index 488af62..0000000
--- a/examples/vendor/acme/BUILD
+++ /dev/null
@@ -1,22 +0,0 @@
-# A package with a commercial license.
-
-load("@rules_license//rules:license.bzl", "license")
-
-package(
- default_applicable_licenses = [":license"],
- default_visibility = ["//visibility:public"],
-)
-
-# The default license for an entire package is typically named "license".
-license(
- name = "license",
- license_kinds = [
- "@rules_license//examples/my_org/licenses:acme_corp_paid",
- ],
- license_text = "ACME_LICENSE",
-)
-
-cc_library(
- name = "acme",
- srcs = ["coyote.cc"],
-)
diff --git a/examples/vendor/constant_gen/generated_code_licenses.golden b/examples/vendor/constant_gen/generated_code_licenses.golden
deleted file mode 100644
index 6aef78a..0000000
--- a/examples/vendor/constant_gen/generated_code_licenses.golden
+++ /dev/null
@@ -1,17 +0,0 @@
-[
- {
- "rule": "//examples/vendor/constant_gen:license_for_emitted_code",
- "license_kinds": [
- {
- "target": "@//examples/my_org/licenses:unencumbered",
- "name": "unencumbered",
- "conditions": []
- }
- ],
- "copyright_notice": "",
- "package_name": "Trivial Code Generator Output",
- "package_url": null,
- "package_version": null,
- "license_text": "examples/vendor/constant_gen/LICENSE"
- }
-]
diff --git a/examples/vendor/constant_gen/generator_licenses.golden b/examples/vendor/constant_gen/generator_licenses.golden
deleted file mode 100644
index f6fa349..0000000
--- a/examples/vendor/constant_gen/generator_licenses.golden
+++ /dev/null
@@ -1,17 +0,0 @@
-[
- {
- "rule": "//examples/vendor/constant_gen:license",
- "license_kinds": [
- {
- "target": "@//examples/my_org/licenses:generic_restricted",
- "name": "generic_restricted",
- "conditions": ["restricted"]
- }
- ],
- "copyright_notice": "",
- "package_name": "Trivial Code Generator",
- "package_url": "http://github.com/tgc-fake/tgc.tgz",
- "package_version": "3.14",
- "license_text": "examples/vendor/constant_gen/LICENSE"
- }
-]
diff --git a/examples/vendor/libhhgttg/BUILD b/examples/vendor/libhhgttg/BUILD
deleted file mode 100644
index c5da389..0000000
--- a/examples/vendor/libhhgttg/BUILD
+++ /dev/null
@@ -1,25 +0,0 @@
-# A package with all code under a single license. This is the most common case
-# we expect to see.
-
-load("@rules_license//rules:license.bzl", "license")
-
-# Using a package wide default ensure that all targets are associated with the
-# license.
-package(
- default_applicable_licenses = [":license"],
- default_visibility = ["//visibility:public"],
-)
-
-# The default license for an entire package is typically named "license".
-license(
- name = "license",
- license_kinds = [
- "@rules_license//examples/my_org/licenses:generic_notice",
- ],
- license_text = "LICENSE",
-)
-
-cc_library(
- name = "libhhgttg",
- srcs = ["answer.cc"],
-)
diff --git a/examples/vendor/README.md b/examples/vndor/README.md
index 273dea6..273dea6 100644
--- a/examples/vendor/README.md
+++ b/examples/vndor/README.md
diff --git a/examples/vendor/acme/ACME_LICENSE b/examples/vndor/acme/ACME_LICENSE
index 53a5daf..53a5daf 100644
--- a/examples/vendor/acme/ACME_LICENSE
+++ b/examples/vndor/acme/ACME_LICENSE
diff --git a/examples/vndor/acme/BUILD b/examples/vndor/acme/BUILD
new file mode 100644
index 0000000..09da19d
--- /dev/null
+++ b/examples/vndor/acme/BUILD
@@ -0,0 +1,35 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# A package with a commercial license.
+
+load("@rules_license//rules:license.bzl", "license")
+
+package(
+ default_applicable_licenses = [":license"],
+ default_visibility = ["//examples:__subpackages__"],
+)
+
+# The default license for an entire package is typically named "license".
+license(
+ name = "license",
+ license_kinds = [
+ "@rules_license//examples/my_org/licenses:acme_corp_paid",
+ ],
+ license_text = "ACME_LICENSE",
+)
+
+cc_library(
+ name = "acme",
+ srcs = ["coyote.cc"],
+)
diff --git a/examples/vendor/acme/coyote.cc b/examples/vndor/acme/coyote.cc
index e1e8083..d637855 100644
--- a/examples/vendor/acme/coyote.cc
+++ b/examples/vndor/acme/coyote.cc
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -11,7 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-
bool caught_road_runner() {
return false;
}
diff --git a/examples/vendor/constant_gen/BUILD b/examples/vndor/constant_gen/BUILD
index a81885c..5f2ff43 100644
--- a/examples/vendor/constant_gen/BUILD
+++ b/examples/vndor/constant_gen/BUILD
@@ -1,34 +1,44 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
# An example of a code generator with a distinct license for the generated code.
load("@rules_license//rules:compliance.bzl", "licenses_used")
load("@rules_license//rules:license.bzl", "license")
-load("@rules_license//tools:test_helpers.bzl", "golden_test")
load(":defs.bzl", "constant_gen")
package(
default_applicable_licenses = [":license"],
- default_visibility = ["//visibility:public"],
+ default_visibility = ["//examples:__subpackages__"],
)
# The default license for an entire package is typically named "license".
license(
name = "license",
+ package_name = "Trivial Code Generator",
license_kinds = [
"@rules_license//examples/my_org/licenses:generic_restricted",
],
license_text = "LICENSE",
- package_name = "Trivial Code Generator",
- package_url = "http://github.com/tgc-fake/tgc.tgz",
- package_version = "3.14",
)
license(
name = "license_for_emitted_code",
package_name = "Trivial Code Generator Output",
- license = "LICENSE.on_output",
license_kinds = [
"@rules_license//examples/my_org/licenses:unencumbered",
],
+ license_text = "LICENSE.on_output",
)
# The generator itself will be licensed under :license
@@ -52,20 +62,21 @@ licenses_used(
deps = [":constant_generator"],
)
-golden_test(
- name = "verify_generator_licenses",
- golden = "generator_licenses.golden",
- subject = ":generator_licenses.json",
-)
-
licenses_used(
name = "generated_code_licenses",
# Note: using default output file name
deps = [":libhello"],
)
-golden_test(
- name = "verify_generated_code_licenses",
- golden = "generated_code_licenses.golden",
- subject = ":generated_code_licenses.json",
+py_test(
+ name = "verify_licenses_test",
+ srcs = ["verify_licenses_test.py"],
+ data = [
+ ":generator_licenses.json",
+ ":generated_code_licenses.json",
+ ],
+ python_version = "PY3",
+ deps = [
+ "//tests:license_test_utils",
+ ],
)
diff --git a/examples/vendor/constant_gen/LICENSE b/examples/vndor/constant_gen/LICENSE
index 861da0d..861da0d 100644
--- a/examples/vendor/constant_gen/LICENSE
+++ b/examples/vndor/constant_gen/LICENSE
diff --git a/examples/vendor/constant_gen/LICENSE.on_output b/examples/vndor/constant_gen/LICENSE.on_output
index b699638..b699638 100644
--- a/examples/vendor/constant_gen/LICENSE.on_output
+++ b/examples/vndor/constant_gen/LICENSE.on_output
diff --git a/examples/vendor/constant_gen/constant_generator.py b/examples/vndor/constant_gen/constant_generator.py
index 6bd92b2..432b6be 100644
--- a/examples/vendor/constant_gen/constant_generator.py
+++ b/examples/vndor/constant_gen/constant_generator.py
@@ -1,4 +1,4 @@
-# Copyright 2020 Google LLC
+# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -11,8 +11,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-
-# Lint as: python3
"""A trivial tool to turn a string into a C++ constant.
This is not meant to be useful. It is only to provide an example of a tool that
diff --git a/examples/vendor/constant_gen/defs.bzl b/examples/vndor/constant_gen/defs.bzl
index e54fcee..518437c 100644
--- a/examples/vendor/constant_gen/defs.bzl
+++ b/examples/vndor/constant_gen/defs.bzl
@@ -1,5 +1,3 @@
-"""A trivial rule to turn a string into a C++ constant."""
-
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+"""A trivial rule to turn a string into a C++ constant."""
def _constant_gen_impl(ctx):
# Turn text into a C++ constant.
@@ -33,7 +32,7 @@ _constant_gen = rule(
"text": attr.string(mandatory = True),
"var": attr.string(mandatory = False),
"_generator": attr.label(
- default = Label("@rules_license//examples/vendor/constant_gen:constant_generator"),
+ default = Label("@rules_license//examples/vndor/constant_gen:constant_generator"),
executable = True,
allow_files = True,
cfg = "exec",
@@ -48,12 +47,12 @@ def constant_gen(name, text, var):
src_out = name + "_src_.cc",
text = text,
var = var,
- applicable_licenses = ["@rules_license//examples/vendor/constant_gen:license_for_emitted_code"],
+ applicable_licenses = ["@rules_license//examples/vndor/constant_gen:license_for_emitted_code"],
)
# And turn it into a library we can link against
native.cc_library(
name = name,
srcs = [name + "_src_"],
- applicable_licenses = ["@rules_license//examples/vendor/constant_gen:license_for_emitted_code"],
+ applicable_licenses = ["@rules_license//examples/vndor/constant_gen:license_for_emitted_code"],
)
diff --git a/examples/vndor/constant_gen/verify_licenses_test.py b/examples/vndor/constant_gen/verify_licenses_test.py
new file mode 100644
index 0000000..917e600
--- /dev/null
+++ b/examples/vndor/constant_gen/verify_licenses_test.py
@@ -0,0 +1,40 @@
+"""Test that we see the expected licenses for some generated code."""
+
+import codecs
+import os
+
+import unittest
+from tests import license_test_utils
+
+class VerifyLicensesTest(unittest.TestCase):
+
+ def test_generater_license(self):
+ licenses_info = license_test_utils.load_licenses_info(
+ os.path.join(os.path.dirname(__file__), "generator_licenses.json"))
+
+ expected = {
+ "examples/vndor/constant_gen:constant_generator": [
+ "examples/vndor/constant_gen:license"
+ ],
+ }
+ license_test_utils.check_licenses_of_dependencies(
+ self, licenses_info, expected)
+
+ def test_generated_code_license(self):
+ licenses_info = license_test_utils.load_licenses_info(
+ os.path.join(os.path.dirname(__file__), "generated_code_licenses.json"))
+
+ expected = {
+ "examples/vndor/constant_gen:libhello": [
+ "/constant_gen:license_for_emitted_code",
+ ],
+ "examples/vndor/constant_gen:libhello_src_": [
+ "/constant_gen:license_for_emitted_code",
+ ],
+ }
+ license_test_utils.check_licenses_of_dependencies(
+ self, licenses_info, expected)
+
+if __name__ == "__main__":
+ unittest.main()
+
diff --git a/examples/vndor/libhhgttg/BUILD b/examples/vndor/libhhgttg/BUILD
new file mode 100644
index 0000000..b9e3991
--- /dev/null
+++ b/examples/vndor/libhhgttg/BUILD
@@ -0,0 +1,38 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# A package with all code under a single license. This is the most common case
+# we expect to see.
+
+load("@rules_license//rules:license.bzl", "license")
+
+# Using a package wide default ensure that all targets are associated with the
+# license.
+package(
+ default_applicable_licenses = [":license"],
+ default_visibility = ["//examples:__subpackages__"],
+)
+
+# The default license for an entire package is typically named "license".
+license(
+ name = "license",
+ license_kinds = [
+ "@rules_license//examples/my_org/licenses:generic_notice",
+ ],
+ license_text = "LICENSE",
+)
+
+cc_library(
+ name = "libhhgttg",
+ srcs = ["answer.cc"],
+)
diff --git a/examples/vendor/libhhgttg/LICENSE b/examples/vndor/libhhgttg/LICENSE
index 660e329..660e329 100644
--- a/examples/vendor/libhhgttg/LICENSE
+++ b/examples/vndor/libhhgttg/LICENSE
diff --git a/examples/vendor/libhhgttg/answer.cc b/examples/vndor/libhhgttg/answer.cc
index 8b78f90..440bc62 100644
--- a/examples/vendor/libhhgttg/answer.cc
+++ b/examples/vndor/libhhgttg/answer.cc
@@ -1,4 +1,4 @@
-// Copyright 2020 Google LLC
+// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.