120 lines
6.5 KiB
Python
120 lines
6.5 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Check an exported source distribution without private inputs or network access."""
|
|
import hashlib
|
|
import ast
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import sqlite3
|
|
import re
|
|
import xml.etree.ElementTree as ET
|
|
from publication_urls import unapproved_app_links
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
|
def artwork_provenance_issues(name, data):
|
|
"""Inspect artwork descriptions and generator strings, preserving attribution."""
|
|
if name.endswith('.svg'):
|
|
root = ET.fromstring(data)
|
|
text = '\n'.join(''.join(node.itertext()) for node in root.iter()
|
|
if node.tag.rsplit('}', 1)[-1] in {'metadata', 'desc'})
|
|
elif name.startswith('platforms/macos/Tools/') and name.endswith(('.py', '.swift')):
|
|
source = data.decode('utf-8')
|
|
if name.endswith('.py'):
|
|
text = '\n'.join(node.value for node in ast.walk(ast.parse(source))
|
|
if isinstance(node, ast.Constant) and isinstance(node.value, str))
|
|
else:
|
|
text = source
|
|
else:
|
|
return []
|
|
patterns = [r'\buser[- ]supplied\b', r'\brequested by (?:the )?user\b',
|
|
r'\b(?:supplied|provided) by Brian\b', r'\bIMG_\d+\.(?:jpg|jpeg|png)\b',
|
|
r'\b\d{12,}_[\w]+_n\.jpg\b',
|
|
r'\b[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}\.(?:webp|jpg|png)\b',
|
|
r'\bapproved\s+(?:[\w-]+\s+){0,3}concept\b',
|
|
r'\brequested\s+(?:TANDY\s+)?branding\b',
|
|
r'\bno image-generation service\b']
|
|
return [name + ': private-reference or authoring-session metadata'
|
|
for pattern in patterns if re.search(pattern, text, re.I)]
|
|
|
|
|
|
def source_mode_matches(mode, expected):
|
|
"""Git preserves executable status; checkout write bits follow local umask."""
|
|
return bool(mode & 0o111) == bool(int(expected, 8) & 0o111)
|
|
|
|
|
|
def source_inventory():
|
|
result = set()
|
|
for target in ROOT.rglob('*'):
|
|
relative = target.relative_to(ROOT)
|
|
if '__pycache__' in relative.parts or target.name in {'.DS_Store'} or target.suffix == '.pyc':
|
|
continue
|
|
if relative.parts[0] in {'.git', '.build', 'build', 'dist'} or relative.parts[:3] == ('platforms', 'macos', 'LocalResources'):
|
|
continue
|
|
if relative.parts[0] == 'third_party' and len(relative.parts) > 1 and relative.parts[1] not in {'README.md', 'manifests'}:
|
|
continue
|
|
if target.is_symlink() or target.is_file():
|
|
result.add(relative.as_posix())
|
|
if (ROOT / '.git').exists():
|
|
result.update(subprocess.check_output(['git', '-C', str(ROOT), 'ls-files', '-z']).decode().strip('\0').split('\0'))
|
|
result.discard('')
|
|
return result
|
|
|
|
|
|
def main():
|
|
record = json.loads((ROOT / 'EXPORT.json').read_text())
|
|
expected_paths = set(record['files']) | {'EXPORT.json'}
|
|
if source_inventory() != expected_paths:
|
|
raise ValueError('Unexpected or missing distribution source: ' + str(sorted(source_inventory() ^ expected_paths)))
|
|
for relative, expected in record['files'].items():
|
|
path = ROOT / relative
|
|
if path.is_symlink() or not path.is_file():
|
|
raise ValueError('Missing or linked distribution file: ' + relative)
|
|
if hashlib.sha256(path.read_bytes()).hexdigest() != expected['sha256']:
|
|
raise ValueError('Distribution file changed: ' + relative)
|
|
if not source_mode_matches(path.stat().st_mode, expected['mode']):
|
|
raise ValueError('Distribution file mode changed: ' + relative)
|
|
# Check tracked/source files rather than generated, ignored build products.
|
|
for relative in record['files']:
|
|
path = ROOT / relative
|
|
if path.suffix.lower() in {'.rom', '.sqlite', '.sqlite3', '.db'}:
|
|
raise ValueError('Forbidden source payload: ' + relative)
|
|
if path.read_bytes().startswith(b'SQLite format 3\x00'):
|
|
raise ValueError('Database payload: ' + relative)
|
|
if unapproved_app_links(path.read_bytes().decode('utf-8', errors='ignore')):
|
|
raise ValueError('Unreviewed application repository link: ' + relative)
|
|
issues = artwork_provenance_issues(relative, path.read_bytes())
|
|
if issues:
|
|
raise ValueError('\n'.join(issues))
|
|
project = (ROOT / 'platforms/macos/VCC.xcodeproj/project.pbxproj').read_text()
|
|
if '"VCC_BUILD_CONTENT_PROFILE" = "normal";' in project or project.count('"VCC_BUILD_CONTENT_PROFILE" = "source";') != 6:
|
|
raise ValueError('Distribution must default to the shared source content profile')
|
|
if '"CODE_SIGN_STYLE" = "Automatic";' in project or '"DEVELOPMENT_TEAM" = "";' not in project:
|
|
raise ValueError('Distribution must use local ad-hoc signing without a developer team')
|
|
if project.count('"PRODUCT_NAME" = "VCC Plus OSS";') != 3 or '"PRODUCT_BUNDLE_IDENTIFIER" = "com.brianholman.vccplus.oss.mac";' not in project:
|
|
raise ValueError('OSS must have an independent app identity')
|
|
forbidden = {'platforms/macos/App/AppUpdateService.swift', 'platforms/macos/Tests/AppUpdateTests.swift'}
|
|
if forbidden.intersection(record['files']) or 'AppUpdate' in project or 'AppUpdate' in (ROOT / 'platforms/macos/App/VCCMacApp.swift').read_text():
|
|
raise ValueError('Commercial updater source, membership or hooks remain')
|
|
if 'static let bundleID = "com.brianholman.vccplus.oss.mac"' not in (ROOT / 'platforms/macos/App/StartupDefaults.swift').read_text():
|
|
raise ValueError('OSS must use an independent application-support directory')
|
|
with tempfile.TemporaryDirectory(prefix='vcc-oss-schema-') as folder:
|
|
for script, name, table in [('catalog/package.py', 'SoftwareLibrary/catalog.sqlite', 'release'),
|
|
('knowledge/package_archive.py', 'ArchiveLibrary/ArchiveLibrary.sqlite', 'document')]:
|
|
output = Path(folder) / name
|
|
subprocess.run([sys.executable, str(ROOT / 'tools' / script), '--output', str(output), '--content-profile', 'source'], check=True)
|
|
with sqlite3.connect(output.resolve().as_uri() + '?mode=ro', uri=True) as db:
|
|
if db.execute('PRAGMA integrity_check').fetchall() != [('ok',)]:
|
|
raise ValueError('Empty dataset is damaged')
|
|
if db.execute('SELECT count(*) FROM ' + table).fetchone() != (0,):
|
|
raise ValueError('Dataset unexpectedly contains content')
|
|
print(f"PASS: {len(record['files'])} source fingerprints; no ROM/database payload; both empty datasets valid")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|