#!/usr/bin/env python3 """Verify and record dependencies of this project's installed Linux binaries.""" import argparse import hashlib import json from pathlib import Path import re import subprocess import sys ROOT = Path(__file__).resolve().parents[1] parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--prefix', type=Path, default=ROOT / 'build/install') parser.add_argument('--output', type=Path, default=ROOT / 'tests/results/installed-dependencies.json') args = parser.parse_args() if not sys.platform.startswith('linux'): raise SystemExit('This records Linux development-host dependencies only.') report = {'scope': 'Linux development host; installed binaries use system dependencies; not a clean-OS distribution test', 'executables': {}} for name in ['docview', 'docview-pdf-worker', 'docview-archive-worker']: path = (args.prefix / 'bin' / name).resolve(strict=True) dependencies = subprocess.check_output(['ldd', str(path)], text=True) if 'not found' in dependencies: raise SystemExit(f'{name}: unresolved runtime dependency') dynamic = subprocess.check_output(['readelf', '-d', str(path)], text=True) needed = sorted(re.findall(r'\(NEEDED\).*?\[(.*?)\]', dynamic)) if name == 'docview' and any('pdfium' in value or 'qpdf' in value for value in needed): raise SystemExit('Main must not link either independent PDF parser.') if name == 'docview-pdf-worker' and not any('libqpdf' in value for value in needed): raise SystemExit('PDFWorker libqpdf dependency missing.') resolved = sorted({line.strip().split()[0] for line in dependencies.splitlines() if line.strip() and not line.strip().startswith('linux-vdso')}) report['executables'][name] = {'sha256': hashlib.file_digest(path.open('rb'), 'sha256').hexdigest(), 'resolvedLibraries': resolved, 'directDependencies': needed, 'missing': []} report['mainLinksPdfiumDirectly'] = False report['mainLinksQpdfDirectly'] = False report['qpdfVersion'] = subprocess.check_output(['pkg-config', '--modversion', 'libqpdf'], text=True).strip() license_path = args.prefix / 'share/doc/docview/licenses/qpdf/LICENSE.txt' report['installedQpdfLicenseSha256'] = hashlib.sha256(license_path.read_bytes()).hexdigest() args.output.write_text(json.dumps(report, indent=2) + '\n') print('Installed dependencies resolved; Main has no direct PDF parser linkage.')