Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions doc_build/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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__",
Expand All @@ -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(
Expand Down Expand Up @@ -94,6 +94,7 @@ bzl_library(
"//:version.bzl",
"//rules:standard_package",
"//rules_gathering:standard_package",
"@package_metadata//:srcs",
],
visibility = ["//visibility:public"],
)
Expand Down
55 changes: 54 additions & 1 deletion rules/license_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
),
]
21 changes: 15 additions & 6 deletions rules/license_kind.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

#
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.
"""The version of rules_license."""

version = "1.0.0"
version = "1.0.0-supply-chain"