diff options
author | Bill Neubauer <wcn@google.com> | 2022-10-24 19:52:53 -0400 |
---|---|---|
committer | Tony Aiuto <aiuto@google.com> | 2022-11-01 00:32:59 -0400 |
commit | d8c455ebb46b0f489a4a83367e4833fda5a131db (patch) | |
tree | 15432eb15d61d926fadba52d89209698ea4bd324 /examples | |
parent | 84c8fe9fabbd149dff42f854c07fabbe286f93a8 (diff) | |
download | bazelbuild-rules_license-d8c455ebb46b0f489a4a83367e4833fda5a131db.tar.gz |
Mega merge from Google
The core of the PR is an expert from Google, but it applies
several changes to account for Bazel differences.
- deal with bazel 5.x 6.x @// handling
- restore package_url and package_version. This is temporary
they will move to other providers.
PiperOrigin-RevId: 483521567
Diffstat (limited to 'examples')
23 files changed, 525 insertions, 173 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..4469cce --- /dev/null +++ b/examples/manifest/main_golden.txt @@ -0,0 +1,204 @@ +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. + 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..f17bfa3 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 diff --git a/examples/src/BUILD b/examples/src/BUILD index 29b6803..ecab5da 100644 --- a/examples/src/BUILD +++ b/examples/src/BUILD @@ -1,17 +1,25 @@ +# 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//rules:compliance.bzl", "check_license", "licenses_used") 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") cc_binary( name = "my_server", srcs = ["server.cc"], - deps = [ - ":message", - "@rules_license//examples/vendor/libhhgttg", - ], + deps = [":message"], ) # Sample @@ -21,32 +29,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 +50,12 @@ 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", + ], ) 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..c7c30da --- /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/vendor/constant_gen:license_for_emitted_code" + ], + "/examples/src:message": [ + "/examples/vendor/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 index 6d322b1..8be07a0 100644 --- a/examples/src/server_report.golden +++ b/examples/src/server_report.golden @@ -1,3 +1,3 @@ -= @rules_license//examples/vendor/constant_gen:license_for_emitted_code - kind: @@rules_license//examples/my_org/licenses:unencumbered += //examples/vendor/constant_gen:license_for_emitted_code + kind: @//examples/my_org/licenses:unencumbered conditions: [] diff --git a/examples/vendor/acme/BUILD b/examples/vendor/acme/BUILD index 488af62..814957d 100644 --- a/examples/vendor/acme/BUILD +++ b/examples/vendor/acme/BUILD @@ -1,11 +1,21 @@ +# 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 = ["//visibility:public"], -) +package(default_applicable_licenses = [":license"]) # The default license for an entire package is typically named "license". license( diff --git a/examples/vendor/acme/coyote.cc b/examples/vendor/acme/coyote.cc index e1e8083..d637855 100644 --- a/examples/vendor/acme/coyote.cc +++ b/examples/vendor/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/vendor/constant_gen/BUILD index a81885c..e70f489 100644 --- a/examples/vendor/constant_gen/BUILD +++ b/examples/vendor/constant_gen/BUILD @@ -1,8 +1,21 @@ +# 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("@rules_license//rules:license.bzl", "license") load(":defs.bzl", "constant_gen") package( @@ -13,22 +26,20 @@ package( # 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 @@ -69,3 +80,4 @@ golden_test( golden = "generated_code_licenses.golden", subject = ":generated_code_licenses.json", ) + diff --git a/examples/vendor/constant_gen/constant_generator.py b/examples/vendor/constant_gen/constant_generator.py index 6bd92b2..432b6be 100644 --- a/examples/vendor/constant_gen/constant_generator.py +++ b/examples/vendor/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/vendor/constant_gen/defs.bzl index e54fcee..f3eb715 100644 --- a/examples/vendor/constant_gen/defs.bzl +++ b/examples/vendor/constant_gen/defs.bzl @@ -1,19 +1,5 @@ """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"); -# 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. - def _constant_gen_impl(ctx): # Turn text into a C++ constant. outputs = [ctx.outputs.src_out] diff --git a/examples/vendor/constant_gen/generated_code_licenses.golden b/examples/vendor/constant_gen/generated_code_licenses.golden index 6aef78a..c4c8ef1 100644 --- a/examples/vendor/constant_gen/generated_code_licenses.golden +++ b/examples/vendor/constant_gen/generated_code_licenses.golden @@ -1,17 +1,41 @@ [ { - "rule": "//examples/vendor/constant_gen:license_for_emitted_code", - "license_kinds": [ + "top_level_target": "//examples/vendor/constant_gen:libhello", + "dependencies": [ { - "target": "@//examples/my_org/licenses:unencumbered", - "name": "unencumbered", - "conditions": [] + "target_under_license": "//examples/vendor/constant_gen:libhello", + "licenses": [ + "//examples/vendor/constant_gen:license_for_emitted_code" + ] + }, + { + "target_under_license": "//examples/vendor/constant_gen:libhello_src_", + "licenses": [ + "//examples/vendor/constant_gen:license_for_emitted_code" + ] } ], - "copyright_notice": "", - "package_name": "Trivial Code Generator Output", - "package_url": null, - "package_version": null, - "license_text": "examples/vendor/constant_gen/LICENSE" + "licenses": [ + { + "label": "//examples/vendor/constant_gen:license_for_emitted_code", + "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": "", + "package_version": "", + "license_text": "examples/vendor/constant_gen/LICENSE.on_output", + "used_by": [ + "//examples/vendor/constant_gen:libhello", + "//examples/vendor/constant_gen:libhello_src_" + ] + } + ] } ] diff --git a/examples/vendor/constant_gen/generator_licenses.golden b/examples/vendor/constant_gen/generator_licenses.golden index f6fa349..4b2f175 100644 --- a/examples/vendor/constant_gen/generator_licenses.golden +++ b/examples/vendor/constant_gen/generator_licenses.golden @@ -1,17 +1,34 @@ [ { - "rule": "//examples/vendor/constant_gen:license", - "license_kinds": [ + "top_level_target": "//examples/vendor/constant_gen:constant_generator", + "dependencies": [ { - "target": "@//examples/my_org/licenses:generic_restricted", - "name": "generic_restricted", - "conditions": ["restricted"] + "target_under_license": "//examples/vendor/constant_gen:constant_generator", + "licenses": [ + "//examples/vendor/constant_gen:license" + ] } ], - "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" + "licenses": [ + { + "label": "//examples/vendor/constant_gen:license", + "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": "", + "package_version": "", + "license_text": "examples/vendor/constant_gen/LICENSE", + "used_by": [ + "//examples/vendor/constant_gen:constant_generator" + ] + } + ] } ] diff --git a/examples/vendor/libhhgttg/BUILD b/examples/vendor/libhhgttg/BUILD index c5da389..44d2d61 100644 --- a/examples/vendor/libhhgttg/BUILD +++ b/examples/vendor/libhhgttg/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. # A package with all code under a single license. This is the most common case # we expect to see. @@ -5,10 +18,7 @@ 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"], -) +package(default_applicable_licenses = [":license"]) # The default license for an entire package is typically named "license". license( diff --git a/examples/vendor/libhhgttg/answer.cc b/examples/vendor/libhhgttg/answer.cc index 8b78f90..440bc62 100644 --- a/examples/vendor/libhhgttg/answer.cc +++ b/examples/vendor/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. |