diff --git a/MODULE.bazel b/MODULE.bazel index 0fcd082..c29b781 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 = "1.0.0-supply-chain", # 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 diff --git a/README.md b/README.md index dd9d653..6a818c2 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 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 - 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..b20e297 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 = "1.0.0-supply-chain"