Support excluding harness files from the unused includes check

This commit is contained in:
Ms2ger 2024-10-31 15:45:44 +01:00 committed by Philip Chimento
parent 6ec99623c2
commit 3468e6aa77
1 changed files with 8 additions and 1 deletions

View File

@ -22,10 +22,14 @@ class CheckIncludes(Check):
with open(os.path.join('harness', include_name), 'r') as f: with open(os.path.join('harness', include_name), 'r') as f:
source = f.read() source = f.read()
parsed = parse(source)
if not parsed:
raise Exception(f"Failed to parse {include_name}")
CheckIncludes._cache[include_name] = { CheckIncludes._cache[include_name] = {
'name': include_name, 'name': include_name,
'source': CheckIncludes._remove_frontmatter(source), 'source': CheckIncludes._remove_frontmatter(source),
'defines': parse(source)['defines'] 'defines': parsed['defines'],
'allow_unused': parsed.get('allow_unused', False),
} }
return CheckIncludes._cache.get(include_name) return CheckIncludes._cache.get(include_name)
@ -57,6 +61,9 @@ class CheckIncludes(Check):
without_frontmatter = self._remove_frontmatter(source) without_frontmatter = self._remove_frontmatter(source)
for harness_file in harness_files: for harness_file in harness_files:
if harness_file['allow_unused']:
continue
if self._has_reference(without_frontmatter, harness_file['defines']): if self._has_reference(without_frontmatter, harness_file['defines']):
continue continue