WIP: add pinned public CMS runtime and versioned color state; renderer integration pending

这个提交包含在:
mac 于 2026-11-03 12:37:59 +08:00 提交
1 父节点 5b8ef04f7e
当前提交 70a50ab445
42 个文件已更改
+1317 -9

没有与搜索条件相匹配的文件

+98
查看文件
@@ -0,0 +1,98 @@
#!/usr/bin/env python3
"""Build the pinned color runtime offline; no Homebrew libraries or implicit downloads."""
from pathlib import Path
import fcntl, hashlib, json, os, re, shutil, subprocess, tarfile
ROOT = Path(__file__).resolve().parent.parent
VENDOR = ROOT / 'ThirdParty/ColorManagement'
CACHE = Path('/Users/mac/Library/Caches/CodexBuilds/com.dayu.color/cms-runtime')
def digest(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def extract(archive, destination):
with tarfile.open(archive) as tf:
for member in tf.getmembers():
path = (destination / member.name).resolve()
if destination not in path.parents or member.isdev():
raise ValueError('Unsafe source archive member')
if member.issym() or member.islnk():
target = ((path.parent if member.issym() else destination) / member.linkname).resolve()
if target != destination and destination not in target.parents:
raise ValueError('Unsafe source archive link')
# Python 3.9 on the supported build machine has no extraction filter API.
tf.extractall(destination)
def _build():
lock = json.loads((VENDOR / 'dependencies.lock.json').read_text())
archives = {}
for item in lock['sources']:
archive = VENDOR / 'sources' / item['archive']
if archive.stat().st_size != item['bytes'] or digest(archive) != item['sha256']:
raise ValueError('Source checksum mismatch: ' + item['name'])
archives[item['name']] = (archive, item['sha256'])
cmake = shutil.which('cmake') or '/opt/homebrew/bin/cmake'
compiler = subprocess.check_output(['xcrun', 'clang++', '--version'], text=True)
sdk = subprocess.check_output(['xcrun', '--show-sdk-version'], text=True).strip()
identity = hashlib.sha256((json.dumps(lock, sort_keys=True) + Path(__file__).read_text() + compiler + sdk).encode()).hexdigest()
CACHE.mkdir(parents=True, exist_ok=True)
stamp = CACHE / 'build.json'
if stamp.exists():
previous = json.loads(stamp.read_text())
if previous.get('identity') == identity and all(Path(p).is_file() and digest(Path(p)) == sha for p, sha in previous['libraries'].items()):
return previous
source_dir, build_dir, install = CACHE / 'source', CACHE / 'build', CACHE / 'install'
# These are dedicated generated directories; no product APP or user source lives here.
for path in (source_dir, build_dir, install):
if path.exists(): shutil.rmtree(path)
path.mkdir()
extract(archives['OpenColorIO'][0], source_dir)
source = source_dir / 'OpenColorIO-2.5.2'
modules = source / 'share/cmake/modules/install'
# Keep upstream's dependency options and target wiring, replacing only network retrieval.
for name, (archive, sha) in archives.items():
if name == 'OpenColorIO': continue
filename = modules / ('Install' + ('ZLIB' if name == 'zlib' else name) + '.cmake')
text = filename.read_text()
text, count = re.subn(r'(?m)^\s*GIT_REPOSITORY[^\n]*\n\s*GIT_TAG[^\n]*',
'\n URL "' + str(archive) + '"\n URL_HASH SHA256=' + sha + '\n DOWNLOAD_EXTRACT_TIMESTAMP TRUE', text)
if count != 1: raise ValueError('Upstream install recipe changed: ' + name)
text = re.sub(r'(?m)^\s*GIT_(CONFIG|SHALLOW)[^\n]*\n', '', text)
filename.write_text(text)
# This is a private, versioned runtime. A host's OCIO_OPTIMIZATION_FLAGS
# must not silently override the precision explicitly chosen by the product.
processor = source / 'src/OpenColorIO/Processor.cpp'
text = processor.read_text()
text, count = re.subn(r'OptimizationFlags EnvironmentOverride\(OptimizationFlags oFlags\)\n\{.*?\n\}',
'OptimizationFlags EnvironmentOverride(OptimizationFlags oFlags)\n{\n return oFlags; // Dayu: fixed per-processor precision; ignore process environment.\n}', text, flags=re.S)
if count != 1: raise ValueError('Upstream optimization override changed')
processor.write_text(text)
flags = ['-DCMAKE_BUILD_TYPE=Release', '-DCMAKE_OSX_ARCHITECTURES=arm64',
'-DCMAKE_OSX_DEPLOYMENT_TARGET=14.6', '-DBUILD_SHARED_LIBS=OFF',
'-DCMAKE_INSTALL_PREFIX=' + str(install), '-DCMAKE_INSTALL_LIBDIR=lib',
'-DOCIO_NAMESPACE=' + lock['namespace'], '-DOCIO_INSTALL_EXT_PACKAGES=ALL',
'-DOCIO_BUILD_APPS=OFF', '-DOCIO_BUILD_PYTHON=OFF', '-DOCIO_BUILD_TESTS=OFF',
'-DOCIO_BUILD_GPU_TESTS=OFF', '-DOCIO_BUILD_DOCS=OFF', '-DOCIO_BUILD_JAVA=OFF',
'-DOCIO_BUILD_NUKE=OFF', '-DOCIO_BUILD_OPENFX=OFF']
environment = dict(os.environ, CMAKE_BUILD_PARALLEL_LEVEL='6')
for args in ([cmake, '-S', source, '-B', build_dir] + flags,
[cmake, '--build', build_dir, '--parallel', '6'],
[cmake, '--install', build_dir]):
subprocess.run([str(x) for x in args], check=True, env=environment)
libraries = [install / 'lib/libOpenColorIO.a'] + sorted((build_dir / 'ext/dist/lib').glob('*.a'))
if len(libraries) != 7 or not all(p.is_file() for p in libraries):
raise ValueError('Expected OCIO and six pinned static dependencies')
result = dict(identity=identity, compiler=compiler, sdk=sdk, namespace=lock['namespace'],
include=str(install / 'include'), libraries={str(p): digest(p) for p in libraries},
builtin_config=lock['builtin_config'])
stamp.write_text(json.dumps(result, indent=2) + '\n')
return result
def build():
CACHE.mkdir(parents=True, exist_ok=True)
with (CACHE / 'build.lock').open('a') as guard:
fcntl.flock(guard, fcntl.LOCK_EX)
return _build()
if __name__ == '__main__':
print(json.dumps(build(), indent=2))