From 773826cabae88c79388e3cad25795a9801580dfe Mon Sep 17 00:00:00 2001 From: Adam Azarchs Date: Tue, 22 Oct 2024 11:43:34 -0700 Subject: [PATCH 1/2] test: add a test case for no license file This causes the build (or cquery) to fail with every rule of type _license implicitly depends upon the target '//rules:LICENSE', but this target could not be found because of: no such target '//rules:LICENSE' Relates-to #31 --- tests/BUILD | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/BUILD b/tests/BUILD index dc1bcfa..e6db493 100644 --- a/tests/BUILD +++ b/tests/BUILD @@ -49,6 +49,13 @@ license( license_text = "LICENSE.extra", ) +license( + name = "license_without_file", + package_name = "A test case package", + license_kinds = ["//licenses/spdx:Apache-2.0"], + license_text = None, +) + cc_binary( name = "hello", srcs = ["hello.cc"], @@ -89,6 +96,9 @@ java_binary( java_library( name = "j_bar", srcs = ["Bar.java"], + applicable_licenses = [ + ":license_without_file", + ], javacopts = ["-Xep:DefaultPackage:OFF"], ) @@ -113,8 +123,8 @@ py_test( name = "hello_licenses_test", srcs = ["hello_licenses_test.py"], data = [ - ":hello_licenses.json", ":hello_cc_copyrights.txt", + ":hello_licenses.json", ], python_version = "PY3", deps = [ @@ -139,11 +149,10 @@ check_license( ], ) - license( name = "license_with_generated_text", - license_text = ":created_license", license_kinds = [":generic_notice_license"], + license_text = ":created_license", ) genrule( @@ -151,4 +160,3 @@ genrule( outs = ["something.text"], cmd = "echo hello >$@", ) - From 10314dc4a50a7cf3ccf304e502f00687dbb4ad6b Mon Sep 17 00:00:00 2001 From: Adam Azarchs Date: Tue, 22 Oct 2024 11:46:15 -0700 Subject: [PATCH 2/2] fix: allow license_text=None in license declaration There are many situations where the license kind is known but no license file is available, e.g. some wheels downloaded from PyPi. There are good reasons why one might want to prohibit that from a policy perspective, but enforcing that policy is not the job of the license rule itself, and the provided error message is not especially helpful (and clearly not the intended outcome). This doesn't alter the macro wrapper. Any target that would be affected by this change would have already been failing to build. Closes #31 --- rules/license.bzl | 1 - 1 file changed, 1 deletion(-) diff --git a/rules/license.bzl b/rules/license.bzl index a5c0379..7c68fc9 100644 --- a/rules/license.bzl +++ b/rules/license.bzl @@ -50,7 +50,6 @@ _license = rule( ), "license_text": attr.label( allow_single_file = True, - default = "LICENSE", doc = "The license file.", ), "package_name": attr.string(