diff options
Diffstat (limited to 'examples/src')
-rw-r--r-- | examples/src/BUILD | 64 | ||||
-rw-r--r-- | examples/src/mobile.cc | 20 | ||||
-rw-r--r-- | examples/src/server.cc | 22 | ||||
-rw-r--r-- | examples/src/server_licenses.golden | 28 | ||||
-rw-r--r-- | examples/src/server_report.golden | 3 |
5 files changed, 137 insertions, 0 deletions
diff --git a/examples/src/BUILD b/examples/src/BUILD new file mode 100644 index 0000000..be415fc --- /dev/null +++ b/examples/src/BUILD @@ -0,0 +1,64 @@ +# Examples of applications and interactions with licenses + +load("@rules_license//examples/vendor/constant_gen:defs.bzl", "constant_gen") +load("@rules_license//rules:compliance.bzl", "check_license", "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", + ], +) + +# Sample +constant_gen( + name = "message", + text = "Hello, world.", + var = "server_message", +) + +license_policy_check( + name = "check_server", + policy = "@rules_license//examples/my_org/compliance:production_service", + target = ":my_server", +) + +cc_binary( + name = "my_violating_server", + srcs = ["server.cc"], + deps = [ + ":message", + "@rules_license//examples/vendor/acme", + "@rules_license//examples/vendor/libhhgttg", + ], +) + +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. + +licenses_used( + name = "server_licenses", + out = "server_licenses.json", + deps = [":my_server"], +) + +golden_test( + name = "verify_server_licenses_test", + golden = "server_licenses.golden", + subject = ":server_licenses.json", +) diff --git a/examples/src/mobile.cc b/examples/src/mobile.cc new file mode 100644 index 0000000..d15090f --- /dev/null +++ b/examples/src/mobile.cc @@ -0,0 +1,20 @@ +// 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 new file mode 100644 index 0000000..8f7990e --- /dev/null +++ b/examples/src/server.cc @@ -0,0 +1,22 @@ +// 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> + +extern const char* server_message; + +int main(int argc, char* argv[]) { + std::cout << server_message << std::endl; + return 0; +} diff --git a/examples/src/server_licenses.golden b/examples/src/server_licenses.golden new file mode 100644 index 0000000..a8f388b --- /dev/null +++ b/examples/src/server_licenses.golden @@ -0,0 +1,28 @@ +[ + { + "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", + "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": "", + "license_text": "examples/vendor/libhhgttg/LICENSE" + } +] diff --git a/examples/src/server_report.golden b/examples/src/server_report.golden new file mode 100644 index 0000000..6d322b1 --- /dev/null +++ b/examples/src/server_report.golden @@ -0,0 +1,3 @@ += @rules_license//examples/vendor/constant_gen:license_for_emitted_code + kind: @@rules_license//examples/my_org/licenses:unencumbered + conditions: [] |