diff options
author | Matt Schulte <matsch@google.com> | 2024-01-18 15:37:24 -0800 |
---|---|---|
committer | Matt Schulte <matsch@google.com> | 2024-01-18 15:37:24 -0800 |
commit | 67924d1dd02f91a6775f7c1f3d8f8c26decb833c (patch) | |
tree | 99e7a476cc5b65ad197dcaac2123f594db654a30 | |
parent | 61852053f28cc8fe6c40d2abd6f0e874ea68658d (diff) | |
download | development-67924d1dd02f91a6775f7c1f3d8f8c26decb833c.tar.gz |
add3prf.py: Add support for Boost license
Bug: 321067451
Test: Run against `ryu-1.0.15` crate and add unit test
Change-Id: Ie37e173e73bc0b3c75dd6d83f8c0ef48e428a395
-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 0d71f3eec..60dfcc101 100755 --- a/scripts/add3prf.py +++ b/scripts/add3prf.py @@ -45,6 +45,8 @@ YMD_LINE_MATCHER = re.compile(YMD_LINE_PATTERN) # patterns to match different licence types in LICENSE* APACHE_PATTERN = r"^.*Apache License.*$" APACHE_MATCHER = re.compile(APACHE_PATTERN) +BOOST_PATTERN = r"^.Boost Software License.*Version 1.0.*$" +BOOST_MATCHER = re.compile(BOOST_PATTERN) MIT_PATTERN = r"^.*MIT License.*$" MIT_MATCHER = re.compile(MIT_PATTERN) BSD_PATTERN = r"^.*BSD .*License.*$" @@ -139,6 +141,8 @@ def grep_license_keyword(license_file): for line in input_file: if APACHE_MATCHER.match(line): return License(LicenseType.APACHE2, LicenseGroup.NOTICE, license_file) + if BOOST_MATCHER.match(line): + return License(LicenseType.BOOST, LicenseGroup.NOTICE, license_file) if MIT_MATCHER.match(line): return License(LicenseType.MIT, LicenseGroup.NOTICE, license_file) if BSD_MATCHER.match(line): @@ -171,6 +175,7 @@ class LicenseType(enum.IntEnum): ZERO_BSD = 6 UNLICENSE = 7 ZLIB = 8 + BOOST = 9 class LicenseGroup(enum.Enum): """A group of license as defined by go/thirdpartylicenses#types @@ -202,6 +207,8 @@ def decide_license_type(cargo_license): lowered_name = os.path.splitext(license_file.lower())[0] if lowered_name == "license-apache": licenses.append(License(LicenseType.APACHE2, LicenseGroup.NOTICE, license_file)) + if lowered_name == "license-boost": + licenses.append(License(LicenseType.BOOST, LicenseGroup.NOTICE, license_file)) elif lowered_name == "license-mit": licenses.append(License(LicenseType.MIT, LicenseGroup.NOTICE, license_file)) elif lowered_name == "license-0bsd": @@ -219,6 +226,8 @@ def decide_license_type(cargo_license): # Cargo.toml. if "Apache" in cargo_license: return [License(LicenseType.APACHE2, LicenseGroup.NOTICE, license_file)] + if "BSL" in cargo_license: + return [License(LicenseType.BOOST, LicenseGroup.NOTICE, license_file)] if "MIT" in cargo_license: return [License(LicenseType.MIT, LicenseGroup.NOTICE, license_file)] if "0BSD" in cargo_license: @@ -271,7 +280,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", "ZLIB"]: + for suffix in ["MIT", "APACHE", "APACHE2", "BSD_LIKE", "MPL", "0BSD", "UNLICENSE", "ZLIB", "BOOST"]: 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 8389b6e75..ecaf5194a 100755 --- a/scripts/add3prf_test.py +++ b/scripts/add3prf_test.py @@ -136,6 +136,24 @@ class LicenseDetectionTestCase(fake_filesystem_unittest.TestCase): self.assertEqual(preferred_license.group, add3prf.LicenseGroup.NOTICE) self.assertEqual(preferred_license.filename, "LICENSE-ZLIB") + def test_boost_license(self): + self.fs.create_file("LICENSE") + licenses = add3prf.decide_license_type("BSL-1.0") + self.assertEqual(len(licenses), 1) + preferred_license = licenses[0] + self.assertEqual(preferred_license.type, add3prf.LicenseType.BOOST) + self.assertEqual(preferred_license.group, add3prf.LicenseGroup.NOTICE) + self.assertEqual(preferred_license.filename, "LICENSE") + + def test_boost_licensefile(self): + self.fs.create_file("LICENSE-BOOST") + licenses = add3prf.decide_license_type("") + self.assertEqual(len(licenses), 1) + preferred_license = licenses[0] + self.assertEqual(preferred_license.type, add3prf.LicenseType.BOOST) + self.assertEqual(preferred_license.group, add3prf.LicenseGroup.NOTICE) + self.assertEqual(preferred_license.filename, "LICENSE-BOOST") + class AddModuleLicenseTestCase(fake_filesystem_unittest.TestCase): def setUp(self): |