Skip to content

Commit b39782f

Browse files
committed
sanity_checks: require LICENSE.build if patch dir has license blocks
Check the patch directories of ports for Meson- or Python-style header comment blocks that reference a license other than MIT. If found, require the port to include a LICENSE.build file describing the port's license, since otherwise create_release.py will add a default MIT LICENSE.build to the patch ZIP.
1 parent 39f46c4 commit b39782f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tools/sanity_checks.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
'icu': 'icu4c',
158158
'libtomcrypt': 'crypt',
159159
}
160+
MIT_LICENSE_BLOCKS = {'expat', 'freeglut', 'glew', 'google-brotli'}
160161
FORMAT_CHECK_FILES = {'meson.build', 'meson_options.txt', 'meson.options'}
161162
SUBPROJECTS_METADATA_FILES = {'subprojects/.gitignore'}
162163
PERMITTED_KEYS = {'versions', 'dependency_names', 'program_names'}
@@ -639,13 +640,16 @@ def get_default_options(self, project: dict[str, T.Any]) -> dict[str, str | None
639640
def check_files(self, subproject: str, patch_path: Path) -> None:
640641
not_permitted: list[Path] = []
641642
check_format: list[Path] = []
643+
license_blocks: list[Path] = []
642644
for f in patch_path.rglob('*'):
643645
if f.is_dir():
644646
continue
645647
if f.name in FORMAT_CHECK_FILES:
646648
check_format.append(f)
647649
if not self.is_permitted_file(subproject, f.name):
648650
not_permitted.append(f)
651+
if self.has_license_block(f):
652+
license_blocks.append(f)
649653
if not_permitted:
650654
not_permitted_str = ', '.join([str(f) for f in not_permitted])
651655
self.fail(f'Not permitted files found: {not_permitted_str}')
@@ -654,6 +658,23 @@ def check_files(self, subproject: str, patch_path: Path) -> None:
654658
format_wrap(subproject, check=True)
655659
except FormattingError:
656660
self.fail('Unformatted files found. Run tools/format.py to format these files.')
661+
if license_blocks and subproject not in MIT_LICENSE_BLOCKS and not (patch_path / 'LICENSE.build').exists():
662+
license_blocks_str = ', '.join(str(f) for f in license_blocks)
663+
self.fail(f"Found files {license_blocks_str} with license headers in a project without a LICENSE.build. The LICENSE.build file in the patch ZIP defaults to MIT unless the patch directory has its own LICENSE.build, which should state the license for the wrap's build files.")
664+
665+
def has_license_block(self, path: Path) -> bool:
666+
for line in path.read_text(encoding='utf-8').splitlines():
667+
lower = line.strip().lower()
668+
if lower and not lower.startswith('#'):
669+
# first non-comment line
670+
return False
671+
if 'spdx-license-identifier:' in lower:
672+
# allow pure MIT, matching the repo default
673+
if not lower.endswith('spdx-license-identifier: mit'):
674+
return True
675+
elif 'license' in lower:
676+
return True
677+
return False
657678

658679
@unittest.skipUnless('TEST_MESON_VERSION_DEPS' in os.environ, 'Run manually only')
659680
def test_meson_version_deps(self) -> None:

0 commit comments

Comments
 (0)