diff options
author | aiuto <aiuto@google.com> | 2022-11-01 22:41:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-01 22:41:45 -0400 |
commit | 3b80554a610916e34d2cda79f77f0eb35a5c7b84 (patch) | |
tree | be4cf4e1a8051107f28ad4e9d33a060706c0d90c | |
parent | 84c8fe9fabbd149dff42f854c07fabbe286f93a8 (diff) | |
parent | 29224d1ef8a5cf58bb6b27747c421d3a647aef51 (diff) | |
download | bazelbuild-rules_license-3b80554a610916e34d2cda79f77f0eb35a5c7b84.tar.gz |
Merge pull request #52 from aiuto/fixt
Emit license data JSON file in a Bazel 5.x/6.x portable way
-rw-r--r-- | rules/gather_licenses_info.bzl | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/rules/gather_licenses_info.bzl b/rules/gather_licenses_info.bzl index d47a821..9a91229 100644 --- a/rules/gather_licenses_info.bzl +++ b/rules/gather_licenses_info.bzl @@ -27,6 +27,16 @@ def _debug(loglevel, msg): if _VERBOSITY > loglevel: print(msg) # buildifier: disable=print +def _strip_null_repo(label): + """Removes the null repo name (e.g. @//) from a string. + + The is to make str(label) compatible between bazel 5.x and 6.x + """ + s = str(label) + if s.startswith('@//'): + return s[1:] + return s + def _get_transitive_licenses(deps, licenses, trans): for dep in deps: if LicenseInfo in dep: @@ -122,7 +132,7 @@ def write_licenses_info(ctx, deps, json_out): kind_conditions = kind.conditions, )) licenses.append(rule_template.format( - rule = license.rule, + rule = _strip_null_repo(license.rule), copyright_notice = license.copyright_notice, package_name = license.package_name, package_url = _quotes_or_null(license.package_url), |