Files
shadowsocks-libev/tests/check_static_runtime.py
T
Max Lv 201e70c4bd Modernize C builds with offline dependencies and portable runtime helpers (#3050)
Bundle pinned offline dependencies, remove libcork/libipset and submodule requirements, and add portable runtime helpers with relocatable static/shared library installations.

Add Clang static build validation for Linux/musl, macOS and Windows, real TCP/UDP and SIP003 interoperability coverage, and recorded performance tradeoffs. All 21 hosted checks pass at the reviewed PR head 8d504e6218.
2026-09-11 13:42:11 +08:00

54 lines
2.0 KiB
Python

#!/usr/bin/env python3
"""Reject non-system runtime dependencies in static macOS/Windows outputs."""
import argparse
import platform
import re
import subprocess
from pathlib import Path
WINDOWS_SYSTEM_DLLS = {
'advapi32.dll', 'bcrypt.dll', 'crypt32.dll', 'dnsapi.dll', 'iphlpapi.dll',
'kernel32.dll', 'msvcrt.dll', 'ntdll.dll', 'ole32.dll', 'psapi.dll',
'rpcrt4.dll', 'secur32.dll', 'shell32.dll', 'ucrtbase.dll', 'user32.dll',
'userenv.dll', 'winmm.dll', 'ws2_32.dll',
}
def dependencies(binary, system):
if system == 'Darwin':
output = subprocess.check_output(['otool', '-L', str(binary)], text=True)
return [line.strip().split(' (compatibility version', 1)[0]
for line in output.splitlines() if line.startswith('\t')]
output = subprocess.check_output(
['llvm-readobj', '--coff-imports', str(binary)], text=True)
return re.findall(r'^\s+Name: (.+)$', output, re.MULTILINE)
def is_system_dependency(name, system):
if system == 'Darwin':
return name.startswith(('/usr/lib/', '/System/Library/'))
name = name.strip().lower()
return name in WINDOWS_SYSTEM_DLLS or (
name.startswith(('api-ms-win-', 'ext-ms-win-')) and name.endswith('.dll'))
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('binaries', type=Path, nargs='+')
args = parser.parse_args()
system = platform.system()
if system not in ('Darwin', 'Windows'):
parser.error('this check supports macOS and native Windows Python')
for binary in args.binaries:
names = dependencies(binary, system)
if not names:
raise SystemExit(f'{binary}: no OS imports found; check file format/tool output')
unexpected = [name for name in names if not is_system_dependency(name, system)]
if unexpected:
raise SystemExit(f'{binary}: non-system dependencies: {unexpected}')
print(f'PASS {binary}: {", ".join(names)}')
if __name__ == '__main__':
main()