diff options
author | Matt Schulte <matsch@google.com> | 2024-01-18 15:33:30 -0800 |
---|---|---|
committer | Matt Schulte <matsch@google.com> | 2024-01-18 15:35:16 -0800 |
commit | 61852053f28cc8fe6c40d2abd6f0e874ea68658d (patch) | |
tree | 7c34310e5602e23c372bfc134ec44f6f6ec0135f | |
parent | 52e1d5a7e4a372aaf0a04cc88bca1a46f93f61d7 (diff) | |
download | development-61852053f28cc8fe6c40d2abd6f0e874ea68658d.tar.gz |
add3prf.py: Add support for zlib license detection
Bug: 321066417
Test: Run add3prf.py against tinyvec-1.6.0 and added unit tests
Change-Id: I824f93a0335c8d8de13b11df9efe6775a02870f2
-rwxr-xr-x | scripts/add3prf.py | 11 | ||||
-rwxr-xr-x | scripts/add3prf_test.py | 18 |
2 files changed, 28 insertions, 1 deletions
diff --git a/scripts/add3prf.py b/scripts/add3prf.py index 44a8418ec..0d71f3eec 100755 --- a/scripts/add3prf.py +++ b/scripts/add3prf.py @@ -55,6 +55,8 @@ UNLICENSE_PATTERN = r"^.*unlicense\.org.*$" UNLICENSE_MATCHER = re.compile(UNLICENSE_PATTERN) ZERO_BSD_PATTERN = r"^.*Zero-Clause BSD.*$" ZERO_BSD_MATCHER = re.compile(ZERO_BSD_PATTERN) +ZLIB_PATTERN = r"^.*zlib License.$" +ZLIB_MATCHER = re.compile(ZLIB_PATTERN) MULTI_LICENSE_COMMENT = ("# Dual-licensed, using the least restrictive " "per go/thirdpartylicenses#same.\n ") @@ -147,6 +149,8 @@ def grep_license_keyword(license_file): return License(LicenseType.UNLICENSE, LicenseGroup.PERMISSIVE, license_file) if ZERO_BSD_MATCHER.match(line): return License(LicenseType.ZERO_BSD, LicenseGroup.PERMISSIVE, license_file) + if ZLIB_MATCHER.match(line): + return License(LicenseType.ZLIB, LicenseGroup.NOTICE, license_file) print("ERROR: cannot decide license type in", license_file, "assume BSD_LIKE") return License(LicenseType.BSD_LIKE, LicenseGroup.NOTICE, license_file) @@ -166,6 +170,7 @@ class LicenseType(enum.IntEnum): MPL = 5 ZERO_BSD = 6 UNLICENSE = 7 + ZLIB = 8 class LicenseGroup(enum.Enum): """A group of license as defined by go/thirdpartylicenses#types @@ -201,6 +206,8 @@ def decide_license_type(cargo_license): licenses.append(License(LicenseType.MIT, LicenseGroup.NOTICE, license_file)) elif lowered_name == "license-0bsd": licenses.append(License(LicenseType.ZERO_BSD, LicenseGroup.PERMISSIVE, license_file)) + elif lowered_name == "license-zlib": + licenses.append(License(LicenseType.ZLIB, LicenseGroup.NOTICE, license_file)) elif lowered_name == "unlicense": licenses.append(License(LicenseType.UNLICENSE, LicenseGroup.PERMISSIVE, license_file)) if licenses: @@ -224,6 +231,8 @@ def decide_license_type(cargo_license): return [License(LicenseType.MPL, LicenseGroup.RECIPROCAL, license_file)] if "Unlicense" in cargo_license: return [License(LicenseType.UNLICENSE, LicenseGroup.PERMISSIVE, license_file)] + if "Zlib" in cargo_license: + return [License(LicenseType.ZLIB, LicenseGroup.NOTICE, license_file)] return [grep_license_keyword(license_file)] @@ -262,7 +271,7 @@ def add_license(target): 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", "0BSD", "UNLICENSE"]: + for suffix in ["MIT", "APACHE", "APACHE2", "BSD_LIKE", "MPL", "0BSD", "UNLICENSE", "ZLIB"]: module_file = "MODULE_LICENSE_" + suffix if os.path.exists(module_file): if license_type.name != suffix: diff --git a/scripts/add3prf_test.py b/scripts/add3prf_test.py index a75b31f3a..8389b6e75 100755 --- a/scripts/add3prf_test.py +++ b/scripts/add3prf_test.py @@ -118,6 +118,24 @@ class LicenseDetectionTestCase(fake_filesystem_unittest.TestCase): self.assertEqual(preferred_license.group, add3prf.LicenseGroup.PERMISSIVE) self.assertEqual(preferred_license.filename, "UNLICENSE.txt") + def test_zlib_license(self): + self.fs.create_file("LICENSE") + licenses = add3prf.decide_license_type("Zlib") + self.assertEqual(len(licenses), 1) + preferred_license = licenses[0] + self.assertEqual(preferred_license.type, add3prf.LicenseType.ZLIB) + self.assertEqual(preferred_license.group, add3prf.LicenseGroup.NOTICE) + self.assertEqual(preferred_license.filename, "LICENSE") + + def test_zlib_licensefile(self): + self.fs.create_file("LICENSE-ZLIB") + licenses = add3prf.decide_license_type("") + self.assertEqual(len(licenses), 1) + preferred_license = licenses[0] + self.assertEqual(preferred_license.type, add3prf.LicenseType.ZLIB) + self.assertEqual(preferred_license.group, add3prf.LicenseGroup.NOTICE) + self.assertEqual(preferred_license.filename, "LICENSE-ZLIB") + class AddModuleLicenseTestCase(fake_filesystem_unittest.TestCase): def setUp(self): |