From 4983e1f6d9a3ef8cd9895a19b33fc8b7854209ff Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Thu, 16 Oct 2025 15:33:33 -0400 Subject: [PATCH 1/4] Create a version 2.x Version 2.xof this package is version 1 with the addition of providers that are compatible with `github.com/bazel-contrib/supply-chain`. This provides a slow migration path where you can use supply-chain tools to reason about your project, while still incorporating modules using rules_license. --- MODULE.bazel | 14 ++++++++--- README.md | 6 +++++ doc_build/BUILD | 19 ++++++++------- rules/license_impl.bzl | 55 +++++++++++++++++++++++++++++++++++++++++- rules/license_kind.bzl | 21 +++++++++++----- version.bzl | 2 +- 6 files changed, 96 insertions(+), 21 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 4783130..f376a81 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,11 +1,12 @@ module( name = "rules_license", - version = "1.0.0", # Keep in sync with version.bzl + version = "2.0.0", # Keep in sync with version.bzl compatibility_level = 1, ) -# NOTE: rules_license must not depend on any other repositories if you are -# just using basic rules under //rules/... and //licenses/... +# NOTE: rules_license must normaly not depend on any other repositories. +# This version allows for forwards compatibility to bazel-contrib/supply-chain +bazel_dep(name = "package_metadata", version = "0.0.5") # TODO(aiuto): Create an extension to enable the rules under //tools/... # That will require rules_python, which we do not want to force on people who @@ -14,6 +15,11 @@ module( # Only for development bazel_dep(name = "bazel_skylib", version = "1.7.1", dev_dependency = True) bazel_dep(name = "rules_pkg", version = "1.0.1", dev_dependency = True) -bazel_dep(name = "rules_python", version = "0.35.0", dev_dependency = True) +bazel_dep(name = "rules_python", version = "0.40.0", dev_dependency = True) bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True) + +local_path_override( + module_name = "package_metadata", + path = "../supply-chain/metadata", +) diff --git a/README.md b/README.md index dd9d653..c2d4683 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,12 @@ CI: [![Build status](https://badge.buildkite.com/e12f23186aa579f1e20fcb612a22cd7 |:----------------------------| | Active development has moved to https://github.com/bazel-contrib/supply-chain. Please look there for current status. If you wish to contribute, please consider doing your work there. | +:warning: WARNING +Version 2.0.0 of this package is version 1 with the addition of providers +that are compatible with `supply-chain`. This provides a slow migration +path where you can use supply-chain tools to reason about your project, +while still incorporating projects using rules_license. + This repository contains a set of rules and tools for - declaring metadata about packages, such as diff --git a/doc_build/BUILD b/doc_build/BUILD index e6d3862..ee28705 100644 --- a/doc_build/BUILD +++ b/doc_build/BUILD @@ -20,26 +20,26 @@ How to: """ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") +load("@rules_python//python:py_binary.bzl", "py_binary") load("@stardoc//stardoc:stardoc.bzl", "stardoc") -load("@rules_python//python:defs.bzl", "py_library") -load("//:version.bzl", "version") -package(default_package_metadata = ["//:license", "//:package_info"]) +package(default_package_metadata = [ + "//:license", + "//:package_info", +]) filegroup( name = "standard_package", srcs = [ "BUILD", - ] + glob([ - "*.bzl", - "*.py", - ]), + "merge.py", + ], visibility = ["//distro:__pkg__"], ) exports_files( glob([ - "*.bzl", + "**", ]), visibility = [ "//distro:__pkg__", @@ -62,7 +62,7 @@ ORDER = [ ("gather_metadata_info", "//rules_gathering:gather_metadata.bzl"), ("gather_metadata_info_and_write", "//rules_gathering:gather_metadata.bzl"), ("trace", "//rules_gathering:trace.bzl"), - ("current_module_package_info", "//rules:current_module_package_info.bzl"), + ("current_module_package_info", "//rules:current_module_package_info.bzl"), ] genrule( @@ -94,6 +94,7 @@ bzl_library( "//:version.bzl", "//rules:standard_package", "//rules_gathering:standard_package", + "@package_metadata//:srcs", ], visibility = ["//visibility:public"], ) diff --git a/rules/license_impl.bzl b/rules/license_impl.bzl index 18b8570..cb93ffe 100644 --- a/rules/license_impl.bzl +++ b/rules/license_impl.bzl @@ -15,6 +15,14 @@ """ +load( + "@package_metadata//licenses/providers:license_kind_info.bzl", + _newLicenseKindInfo = "LicenseKindInfo", +) +load( + "@package_metadata//providers:package_attribute_info.bzl", + "PackageAttributeInfo", +) load( "@rules_license//rules:providers.bzl", "LicenseInfo", @@ -43,4 +51,49 @@ def license_rule_impl(ctx): label = ctx.label, ) _debug(0, provider) - return [provider] + + # Also return new style + new_license_kinds = [k[_newLicenseKindInfo] for k in ctx.attr.license_kinds] + if new_license_kinds: + # This is a temporary hack. Just pick the first if there are multiple. + # Package metadata should change to allow for more than one. + kind = new_license_kinds[0] + else: + # This should not happen, because the override for license_kind should + # always synthesize a new LicenseKindInfo + kind = _newLicenseKindInfo(identifier = "", name = "") + + attribute = { + "kind": { + "identifier": kind.identifier, + "name": kind.name, + }, + "label": str(ctx.label), + } + files = [] + + if ctx.attr.license_text: + attribute["text"] = ctx.file.license_text.path + files.append(ctx.attr.license_text[DefaultInfo].files) + + output = ctx.actions.declare_file("{}.package-attribute.json".format(ctx.attr.name)) + ctx.actions.write( + output = output, + content = json.encode(attribute), + ) + + return [ + DefaultInfo( + files = depset( + direct = [ + output, + ], + ), + ), + provider, + PackageAttributeInfo( + kind = "build.bazel.attribute.license", + attributes = output, + files = files, + ), + ] diff --git a/rules/license_kind.bzl b/rules/license_kind.bzl index 7e6c024..2095e13 100644 --- a/rules/license_kind.bzl +++ b/rules/license_kind.bzl @@ -13,6 +13,10 @@ # limitations under the License. """Proof of concept. License restriction.""" +load( + "@package_metadata//licenses/providers:license_kind_info.bzl", + _newLicenseKindInfo = "LicenseKindInfo", +) load("@rules_license//rules:providers.bzl", "LicenseKindInfo") # @@ -22,17 +26,22 @@ load("@rules_license//rules:providers.bzl", "LicenseKindInfo") # def _license_kind_impl(ctx): + identifier = "@%s//%s:%s" % ( + ctx.label.workspace_name, + ctx.label.package, + ctx.label.name, + ) provider = LicenseKindInfo( name = ctx.attr.name, - label = "@%s//%s:%s" % ( - ctx.label.workspace_name, - ctx.label.package, - ctx.label.name, - ), + label = identifier, long_name = ctx.attr.long_name, conditions = ctx.attr.conditions, ) - return [provider] + new_provider = _newLicenseKindInfo( + identifier = identifier, + name = ctx.attr.long_name, + ) + return [provider, new_provider] _license_kind = rule( implementation = _license_kind_impl, diff --git a/version.bzl b/version.bzl index 8c7217c..8907863 100644 --- a/version.bzl +++ b/version.bzl @@ -13,4 +13,4 @@ # limitations under the License. """The version of rules_license.""" -version = "1.0.0" +version = "2.0.0" From 5c5bf294e41e33b168653c16e0c70d3ef9435779 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Mon, 20 Oct 2025 10:46:50 -0400 Subject: [PATCH 2/4] python --- MODULE.bazel | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MODULE.bazel b/MODULE.bazel index f376a81..a838cea 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -15,10 +15,11 @@ bazel_dep(name = "package_metadata", version = "0.0.5") # Only for development bazel_dep(name = "bazel_skylib", version = "1.7.1", dev_dependency = True) bazel_dep(name = "rules_pkg", version = "1.0.1", dev_dependency = True) -bazel_dep(name = "rules_python", version = "0.40.0", dev_dependency = True) +bazel_dep(name = "rules_python", version = "0.35.0", dev_dependency = True) bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True) +# DNS Remove before merge. local_path_override( module_name = "package_metadata", path = "../supply-chain/metadata", From 504fe089406e18f7e8a90fbbecd48dfe7b9389db Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Mon, 20 Oct 2025 10:51:27 -0400 Subject: [PATCH 3/4] other version --- MODULE.bazel | 2 +- README.md | 8 ++++---- version.bzl | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index a838cea..653e6ba 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,6 +1,6 @@ module( name = "rules_license", - version = "2.0.0", # Keep in sync with version.bzl + version = "1.0.0-supply-chain", # Keep in sync with version.bzl compatibility_level = 1, ) diff --git a/README.md b/README.md index c2d4683..6a818c2 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,10 @@ CI: [![Build status](https://badge.buildkite.com/e12f23186aa579f1e20fcb612a22cd7 | Active development has moved to https://github.com/bazel-contrib/supply-chain. Please look there for current status. If you wish to contribute, please consider doing your work there. | :warning: WARNING -Version 2.0.0 of this package is version 1 with the addition of providers -that are compatible with `supply-chain`. This provides a slow migration -path where you can use supply-chain tools to reason about your project, -while still incorporating projects using rules_license. +Version 1.0.0-supply-chain of this package is version 1 with the addition +of providers that are compatible with `supply-chain`. This provides a +slow migration path where you can use supply-chain tools to reason about +your project, while still incorporating projects using rules_license. This repository contains a set of rules and tools for diff --git a/version.bzl b/version.bzl index 8907863..b20e297 100644 --- a/version.bzl +++ b/version.bzl @@ -13,4 +13,4 @@ # limitations under the License. """The version of rules_license.""" -version = "2.0.0" +version = "1.0.0-supply-chain" From 7e9144a0f373a2a442a32b557d99541cf988c036 Mon Sep 17 00:00:00 2001 From: Tony Aiuto Date: Mon, 20 Oct 2025 10:57:46 -0400 Subject: [PATCH 4/4] remove local hack --- MODULE.bazel | 6 ------ 1 file changed, 6 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 653e6ba..49c7c30 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -18,9 +18,3 @@ bazel_dep(name = "rules_pkg", version = "1.0.1", dev_dependency = True) bazel_dep(name = "rules_python", version = "0.35.0", dev_dependency = True) bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True) bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True) - -# DNS Remove before merge. -local_path_override( - module_name = "package_metadata", - path = "../supply-chain/metadata", -)