aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Aiuto <aiuto@google.com>2022-08-02 14:29:18 -0400
committerTony Aiuto <aiuto@google.com>2022-08-02 14:29:18 -0400
commit880c4fb5257791cde9ad27549eb39435e7faf8dc (patch)
treedd715beea9b65b84e993c4d8a558b5c449ec2126
parent21fcdc447645094aecec5f5cbe4f8cc5e4984aa0 (diff)
downloadbazelbuild-rules_license-880c4fb5257791cde9ad27549eb39435e7faf8dc.tar.gz
Add package_version and package_url.
These are needed for minimal SBOM creation. Also see #32
-rw-r--r--examples/src/server_licenses.golden4
-rw-r--r--examples/vendor/constant_gen/BUILD4
-rw-r--r--examples/vendor/constant_gen/generated_code_licenses.golden2
-rw-r--r--examples/vendor/constant_gen/generator_licenses.golden2
-rw-r--r--rules/gather_licenses_info.bzl4
-rw-r--r--rules/license.bzl27
-rw-r--r--rules/providers.bzl2
-rw-r--r--tests/BUILD4
-rw-r--r--version.bzl2
9 files changed, 45 insertions, 6 deletions
diff --git a/examples/src/server_licenses.golden b/examples/src/server_licenses.golden
index a8f388b..f33c852 100644
--- a/examples/src/server_licenses.golden
+++ b/examples/src/server_licenses.golden
@@ -10,6 +10,8 @@
],
"copyright_notice": "",
"package_name": "Trivial Code Generator Output",
+ "package_url": "<unknown>",
+ "package_version": "<unknown>",
"license_text": "examples/vendor/constant_gen/LICENSE"
},
{
@@ -23,6 +25,8 @@
],
"copyright_notice": "",
"package_name": "",
+ "package_url": "<unknown>",
+ "package_version": "<unknown>",
"license_text": "examples/vendor/libhhgttg/LICENSE"
}
]
diff --git a/examples/vendor/constant_gen/BUILD b/examples/vendor/constant_gen/BUILD
index c6d61a2..a81885c 100644
--- a/examples/vendor/constant_gen/BUILD
+++ b/examples/vendor/constant_gen/BUILD
@@ -13,11 +13,13 @@ package(
# The default license for an entire package is typically named "license".
license(
name = "license",
- package_name = "Trivial Code Generator",
license_kinds = [
"@rules_license//examples/my_org/licenses:generic_restricted",
],
license_text = "LICENSE",
+ package_name = "Trivial Code Generator",
+ package_url = "http://github.com/tgc-fake/tgc.tgz",
+ package_version = "3.14",
)
license(
diff --git a/examples/vendor/constant_gen/generated_code_licenses.golden b/examples/vendor/constant_gen/generated_code_licenses.golden
index a37723a..5df6c87 100644
--- a/examples/vendor/constant_gen/generated_code_licenses.golden
+++ b/examples/vendor/constant_gen/generated_code_licenses.golden
@@ -10,6 +10,8 @@
],
"copyright_notice": "",
"package_name": "Trivial Code Generator Output",
+ "package_url": "<unknown>",
+ "package_version": "<unknown>",
"license_text": "examples/vendor/constant_gen/LICENSE"
}
]
diff --git a/examples/vendor/constant_gen/generator_licenses.golden b/examples/vendor/constant_gen/generator_licenses.golden
index 164b00b..f6fa349 100644
--- a/examples/vendor/constant_gen/generator_licenses.golden
+++ b/examples/vendor/constant_gen/generator_licenses.golden
@@ -10,6 +10,8 @@
],
"copyright_notice": "",
"package_name": "Trivial Code Generator",
+ "package_url": "http://github.com/tgc-fake/tgc.tgz",
+ "package_version": "3.14",
"license_text": "examples/vendor/constant_gen/LICENSE"
}
]
diff --git a/rules/gather_licenses_info.bzl b/rules/gather_licenses_info.bzl
index b869314..1b95b45 100644
--- a/rules/gather_licenses_info.bzl
+++ b/rules/gather_licenses_info.bzl
@@ -93,6 +93,8 @@ def write_licenses_info(ctx, deps, json_out):
],
"copyright_notice": "{copyright_notice}",
"package_name": "{package_name}",
+ "package_url": "{package_url}",
+ "package_version": "{package_version}",
"license_text": "{license_text}"\n }}"""
kind_template = """
@@ -118,6 +120,8 @@ def write_licenses_info(ctx, deps, json_out):
rule = license.rule,
copyright_notice = license.copyright_notice,
package_name = license.package_name,
+ package_url = license.package_url or "<unknown>",
+ package_version = license.package_version or "<unknown>",
license_text = license.license_text.path,
kinds = ",\n".join(kinds),
))
diff --git a/rules/license.bzl b/rules/license.bzl
index 86e0307..320c91c 100644
--- a/rules/license.bzl
+++ b/rules/license.bzl
@@ -36,6 +36,8 @@ def _license_impl(ctx):
license_kinds = tuple([k[LicenseKindInfo] for k in ctx.attr.license_kinds]),
copyright_notice = ctx.attr.copyright_notice,
package_name = ctx.attr.package_name,
+ package_url = ctx.attr.package_url,
+ package_version = ctx.attr.package_version,
license_text = ctx.file.license_text,
rule = ctx.label,
)
@@ -67,11 +69,24 @@ _license = rule(
" This may be used to produce an index of OSS packages used by" +
" an applicatation.",
),
+ "package_url": attr.string(
+ doc = "The URL this instance of the package was download from." +
+ " This may be used to produce an index of OSS packages used by" +
+ " an applicatation.",
+ ),
+ "package_version": attr.string(
+ doc = "A human readable version string identifying this package." +
+ " This may be used to produce an index of OSS packages used by" +
+ " an applicatation.",
+ ),
},
)
# buildifier: disable=function-docstring-args
-def license(name, license_kinds = None, license_kind = None, copyright_notice = None, package_name = None, tags = None, **kwargs):
+def license(name, license_kinds = None, license_kind = None,
+ copyright_notice = None, package_name = None,
+ package_url = None, package_version = None,
+ tags = None, **kwargs):
"""Wrapper for license rule.
Args:
@@ -80,9 +95,11 @@ def license(name, license_kinds = None, license_kind = None, copyright_notice =
license_kind: label a single license_kind. Only one of license_kind or license_kinds may
be specified
copyright_notice: str Copyright notice associated with this package.
- package_name : str A human readable name identifying this package. This
- may be used to produce an index of OSS packages used by
- an applicatation.
+ package_name: str A human readable name identifying this package. This
+ may be used to produce an index of OSS packages used by
+ an applicatation.
+ package_url: The URL this instance was downloaded from.
+ package_version: The version number of this package.
"""
license_text_arg = kwargs.pop("license_text", default = None) or "LICENSE"
single_kind = kwargs.pop("license_kind", default = None)
@@ -97,6 +114,8 @@ def license(name, license_kinds = None, license_kind = None, copyright_notice =
license_text = license_text_arg,
copyright_notice = copyright_notice,
package_name = package_name,
+ package_url = package_url,
+ package_version = package_version,
applicable_licenses = [],
tags = tags,
visibility = ["//visibility:public"],
diff --git a/rules/providers.bzl b/rules/providers.bzl
index dd331e2..9e830ce 100644
--- a/rules/providers.bzl
+++ b/rules/providers.bzl
@@ -30,6 +30,8 @@ LicenseInfo = provider(
"license_kinds": "License kinds",
"license_text": "License file",
"package_name": "Human readable package name",
+ "package_url": "URL from which this package was downloaded.",
+ "package_version": "Human readable version string",
"rule": "From whence this came",
},
)
diff --git a/tests/BUILD b/tests/BUILD
index a6fd17d..f817cc4 100644
--- a/tests/BUILD
+++ b/tests/BUILD
@@ -30,6 +30,10 @@ license(
# Note the UTF-8 encoded copyright symbol.
copyright_notice = "Copyright © 2019 Uncle Toasty",
license_kinds = [":generic_notice_license"],
+ # Note. This need not be precise. If a downloader creates the license
+ # clause for you, then it should use the absolute download URL.
+ package_url = "http://github.com/bazelbuild/rules_license",
+ package_version = "0.0.4",
)
license(
diff --git a/version.bzl b/version.bzl
index a968fee..0acecb6 100644
--- a/version.bzl
+++ b/version.bzl
@@ -13,4 +13,4 @@
# limitations under the License.
"""The version of rules_license."""
-version = "0.0.3"
+version = "0.0.4"