Add 0BSD support to add3prf.py
This adds the ability to detect and generate the correct METADATA file
for 0BSD licensed crates.
Bug: 317214883
Test: atest --host add3prf_test; Ran against https://crates.io/crates/adler
Change-Id: I064297212dbbcf7f195cde5e0b345f43da9369df
diff --git a/scripts/add3prf.py b/scripts/add3prf.py
index 137a19e..985cfa5 100755
--- a/scripts/add3prf.py
+++ b/scripts/add3prf.py
@@ -42,7 +42,7 @@
YMD_LINE_PATTERN = r"^.* year: *([^ ]+) +month: *([^ ]+) +day: *([^ ]+).*$"
YMD_LINE_MATCHER = re.compile(YMD_LINE_PATTERN)
-# patterns to match Apache/MIT licence in LICENSE*
+# patterns to match different licence types in LICENSE*
APACHE_PATTERN = r"^.*Apache License.*$"
APACHE_MATCHER = re.compile(APACHE_PATTERN)
MIT_PATTERN = r"^.*MIT License.*$"
@@ -51,6 +51,8 @@
BSD_MATCHER = re.compile(BSD_PATTERN)
MPL_PATTERN = r"^.Mozilla Public License.*$"
MPL_MATCHER = re.compile(MPL_PATTERN)
+ZERO_BSD_PATTERN = r"^.*Zero-Clause BSD.*$"
+ZERO_BSD_MATCHER = re.compile(ZERO_BSD_PATTERN)
MULTI_LICENSE_COMMENT = ("# Dual-licensed, using the least restrictive "
"per go/thirdpartylicenses#same.\n ")
@@ -138,6 +140,8 @@
return License(LicenseType.BSD_LIKE, LicenseGroup.NOTICE, license_file)
if MPL_MATCHER.match(line):
return License(LicenseType.MPL, LicenseGroup.RECIPROCAL, license_file)
+ if ZERO_BSD_MATCHER.match(line):
+ return License(LicenseType.ZERO_BSD, LicenseGroup.PERMISSIVE, license_file)
print("ERROR: cannot decide license type in", license_file,
"assume BSD_LIKE")
return License(LicenseType.BSD_LIKE, LicenseGroup.NOTICE, license_file)
@@ -155,6 +159,7 @@
BSD_LIKE = 3
ISC = 4
MPL = 5
+ ZERO_BSD = 6
class LicenseGroup(enum.Enum):
"""A group of license as defined by go/thirdpartylicenses#types
@@ -188,6 +193,8 @@
licenses.append(License(LicenseType.APACHE2, LicenseGroup.NOTICE, license_file))
elif lowered_name == "license-mit":
licenses.append(License(LicenseType.MIT, LicenseGroup.NOTICE, license_file))
+ elif lowered_name == "license-0bsd":
+ licenses.append(License(LicenseType.ZERO_BSD, LicenseGroup.PERMISSIVE, license_file))
if licenses:
licenses.sort(key=lambda l: l.type)
return licenses
@@ -199,6 +206,8 @@
return [License(LicenseType.APACHE2, LicenseGroup.NOTICE, license_file)]
if "MIT" in cargo_license:
return [License(LicenseType.MIT, LicenseGroup.NOTICE, license_file)]
+ if "0BSD" in cargo_license:
+ return [License(LicenseType.ZERO_BSD, LicenseGroup.PERMISSIVE, license_file)]
if "BSD" in cargo_license:
return [License(LicenseType.BSD_LIKE, LicenseGroup.NOTICE, license_file)]
if "ISC" in cargo_license:
@@ -243,7 +252,7 @@
def add_module_license(license_type):
"""Touch MODULE_LICENSE_type file."""
# Do not change existing MODULE_* files.
- for suffix in ["MIT", "APACHE", "APACHE2", "BSD_LIKE", "MPL"]:
+ for suffix in ["MIT", "APACHE", "APACHE2", "BSD_LIKE", "MPL", "0BSD"]:
module_file = "MODULE_LICENSE_" + suffix
if os.path.exists(module_file):
if license_type.name != suffix: