Initial public OpenBMH 0.1 source (by Codex)

This commit is contained in:
Codex committed 2026-10-16 19:36:32 +02:00
commit 558fbf166b
613 files changed
+168029

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
"""Install the Runtime component and make an allowlisted release ZIP."""
# SPDX-License-Identifier: GPL-3.0-only
import argparse
from pathlib import Path
import re
import subprocess
import tempfile
import zipfile
def validate(directory, windows):
products = {'openbmh_play.exe', 'openbmh_cli.exe'} if windows else {'openbmh_play', 'openbmh_cli'}
documents = {'README.md', 'LICENSE', 'THIRD_PARTY_NOTICES.md', 'ACKNOWLEDGEMENTS.md', 'CONTRIBUTING.md'}
licenses = {'README.md', 'LGPL-2.1.txt', 'Nuked-OPL3-notices.txt', 'LZMA-SDK.txt', 'SDL2-HIDAPI-BSD.txt',
'SDL2-HIDAPI-options.txt', 'SDL2-HIDAPI-original.txt', 'SDL2-yuv2rgb.txt',
'SDL2.txt', 'miniz-source-notices.txt', 'miniz.txt', 'nativefiledialog-extended.txt'}
present = set()
for file in directory.rglob('*'):
if not file.is_file():
continue
relative = file.relative_to(directory)
present.add(relative.as_posix())
allowed = (len(relative.parts) == 1 and file.name in products | documents)
allowed |= len(relative.parts) == 3 and relative.parts[:2] == ('docs', 'licenses') and file.name in licenses
allowed |= (len(relative.parts) >= 2 and relative.parts[0] == 'docs' and
'licenses' not in relative.parts and file.suffix in {'.md', '.txt', '.csv'} and
all(part not in {'analyses', 'agents', 'manuals', 'validation'} for part in relative.parts))
allowed |= (windows and len(relative.parts) == 1 and
bool(re.fullmatch(r'(?:vcruntime\d+(?:_\d+)?|msvcp\d+(?:_\d+|_atomic_wait|_codecvt_ids)?|'
r'concrt\d+|ucrtbase|api-ms-win-crt-[a-z0-9-]+)\.dll', file.name, re.I)))
if not allowed:
raise RuntimeError('Unexpected package entry: ' + relative.as_posix())
required = products | documents | {'docs/licenses/' + name for name in licenses}
required.add('docs/release/0.1/RELEASE_NOTES.md')
if required - present:
raise RuntimeError('Missing package entries: ' + ', '.join(sorted(required - present)))
if windows and not {'vcruntime140.dll', 'msvcp140.dll'} <= present:
raise RuntimeError('App-local Microsoft runtime libraries missing')
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--build', required=True, type=Path)
parser.add_argument('--out', required=True, type=Path)
parser.add_argument('--platform', required=True, choices=['windows-x64', 'linux-x64', 'macos-arm64'])
parser.add_argument('--config', default='Release')
args = parser.parse_args()
args.out.mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix='openbmh-package-', dir=args.out) as temp:
stage = Path(temp) / 'runtime'
subprocess.run(['cmake', '--install', str(args.build), '--config', args.config,
'--component', 'Runtime', '--prefix', str(stage)], check=True)
windows = args.platform == 'windows-x64'
validate(stage, windows)
cli = stage / ('openbmh_cli.exe' if windows else 'openbmh_cli')
version = subprocess.check_output([str(cli.resolve()), '--version'], text=True).strip().split()[-1]
if not re.fullmatch(r'\d+\.\d+\.\d+(?:[-+][A-Za-z0-9.-]+)?', version):
raise RuntimeError('Invalid product version')
name = 'OpenBMH-' + version + '-' + args.platform
destination = args.out / (name + '.zip')
with zipfile.ZipFile(destination, 'w', compression=zipfile.ZIP_DEFLATED) as archive:
for file in sorted(stage.rglob('*')):
if file.is_file():
archive.write(file, Path(name) / file.relative_to(stage))
print(destination)
if __name__ == '__main__':
main()
+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-only
"""Package the audited public source and the dependency sources used by its build."""
import argparse
import hashlib
import json
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
import zipfile
COMPONENTS = {
'SDL2': ('release-2.32.10', 'https://github.com/libsdl-org/SDL', ['include/SDL.h', 'src/SDL.c', 'LICENSE.txt']),
'miniz': ('3.0.2', 'https://github.com/richgel999/miniz', ['miniz.c', 'miniz.h', 'LICENSE']),
'lzma_sdk': ('24.09', 'https://github.com/ip7z/7zip', ['C/7zDec.c', 'C/7z.h', 'DOC/License.txt']),
'nfd': ('v1.2.1', 'https://github.com/btzy/nativefiledialog-extended', ['CMakeLists.txt', 'src/nfd_cocoa.m', 'LICENSE']),
}
# Verified against the archive SHA256 pinned in CMakeLists.txt. These are free
# dependency source files, not game data. Refuse modified archive-cache inputs.
MINIZ_FILES = {
'miniz.c': '0fcdc9888cb3a29ca8f176bac087e5fe6c7258a6ab06b1c271c1e109a11d3740',
'miniz.h': '295d1a0041aea09609598c0f1f35c1977ca05ad662acbadcfdaac44c140af37b',
'LICENSE': '0115478d567121238cf6cc1c0c361926cf07a49d9e4c9e66da97fac6a01646b3',
'ChangeLog.md': '261c5cfb87942b5c47735b98ae2fa87ba5f3058d3c755838756b6117f3b0c0dd',
'readme.md': 'b4ea367be28a36e5386f65118b73962bc659a67936d248be68b7a7c03b8d359b',
}
def git(directory, *arguments):
return subprocess.check_output(['git', '-C', str(directory), *arguments])
def copy_files(source, destination, files, required=False):
manifest = {}
for relative in sorted(set(files)):
origin = source / relative
if not origin.is_file():
if required:
raise RuntimeError('Missing dependency source file: ' + relative.as_posix())
continue
if not origin.resolve().is_relative_to(source.resolve()):
raise RuntimeError('Source symlink leaves its component')
target = destination / relative
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(origin, target)
manifest[relative.as_posix()] = hashlib.sha256(target.read_bytes()).hexdigest()
return manifest
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--source', type=Path, default=Path(__file__).resolve().parents[2])
parser.add_argument('--build', required=True, type=Path)
parser.add_argument('--out', required=True, type=Path)
args = parser.parse_args()
source = args.source.resolve()
subprocess.run([sys.executable, str(source / 'tools/public_release/check_public_tree.py'),
'--root', str(source)], check=True)
cache = (args.build / 'CMakeCache.txt').read_text()
import re
version = re.search(r'^CMAKE_PROJECT_VERSION:STATIC=([^\n]+)$', cache, re.M).group(1)
if not re.fullmatch(r'\d+\.\d+\.\d+', version):
raise RuntimeError('Unexpected source version')
dependencies = json.loads((args.build / 'package-dependencies.json').read_text())
args.out.mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix='openbmh-source-', dir=args.out) as temporary:
stage = Path(temporary)
project_files = [Path(p.decode('utf-8')) for p in git(source, 'ls-files', '-z', '--cached', '--others', '--exclude-standard').split(b'\0') if p]
manifest = {'version': version, 'project_commit': git(source, 'rev-parse', 'HEAD').decode().strip(),
'project_files': copy_files(source, stage / 'project', project_files), 'dependencies': {}}
initial_cache = []
for name, (reference, url, markers) in COMPONENTS.items():
directory = Path(dependencies.get(name, ''))
if not dependencies.get(name) or not all((directory / marker).is_file() for marker in markers):
raise RuntimeError('Actual dependency source unavailable: ' + name)
commit = None
if (directory / '.git').exists():
commit = git(directory, 'rev-parse', 'HEAD').decode().strip()
tag = git(directory, 'rev-parse', reference + '^{commit}').decode().strip()
if commit != tag or git(directory, 'status', '--porcelain', '--untracked-files=no').strip():
raise RuntimeError('Dependency differs from its pinned source: ' + name)
if git(directory, 'ls-files', '--stage').find(b'160000 ') != -1:
raise RuntimeError('Dependency submodules require explicit packaging: ' + name)
if commit:
files = [Path(p.decode('utf-8')) for p in git(directory, 'ls-files', '-z').split(b'\0') if p]
if name == 'lzma_sdk':
files = [p for p in files if p.parts[0] == 'C' or p == Path('DOC/License.txt')]
else:
# The pinned miniz amalgamation is an archive rather than a Git checkout.
if name != 'miniz':
raise RuntimeError('Dependency revision cannot be verified: ' + name)
files = [Path(p) for p in MINIZ_FILES]
for filename, expected in MINIZ_FILES.items():
if hashlib.sha256((directory / filename).read_bytes()).hexdigest() != expected:
raise RuntimeError('Dependency differs from its pinned archive: ' + name)
hashes = copy_files(directory, stage / 'dependencies' / name, files, required=True)
manifest['dependencies'][name] = {'upstream': url, 'reference': reference,
'commit': commit, 'files': hashes}
initial_cache.append('set(FETCHCONTENT_SOURCE_DIR_' + name.upper() +
' "${CMAKE_CURRENT_LIST_DIR}/dependencies/' + name + '" CACHE PATH "" FORCE)')
(stage / 'dependencies.cmake').write_text('\n'.join(initial_cache) + '\n')
(stage / 'SOURCE_MANIFEST.json').write_text(json.dumps(manifest, indent=2) + '\n')
(stage / 'BUILD_SOURCE.md').write_text(
'# Corresponding source\n\nThe project contains its patches, build scripts and vendored Nuked OPL3. '
'The dependency folders contain the sources used by this build; the LZMA folder contains the C decoder tree and upstream license. '
'File hashes and upstream revisions are in SOURCE_MANIFEST.json. No game data or test references are included.\n\n'
'With the native compiler, CMake and platform development libraries described in project/README.md:\n\n'
'```sh\ncmake -S project -B build -C dependencies.cmake -DCMAKE_BUILD_TYPE=Release -DBMH_DATA=\n'
'cmake --build build --config Release --parallel 2\nctest --test-dir build -C Release --output-on-failure\n```\n\n'
'Modify the library/application sources and rebuild with these scripts to produce a relinked program. '
'The source package does not supply the compiler, operating-system SDK or system libraries.\n')
destination = args.out / ('OpenBMH-' + version + '-source.zip')
with zipfile.ZipFile(destination, 'w', compression=zipfile.ZIP_DEFLATED) as archive:
for file in sorted(stage.rglob('*')):
if file.is_file():
archive.write(file, Path(destination.stem) / file.relative_to(stage))
print(destination)
if __name__ == '__main__':
main()
+6
View File
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: GPL-3.0-only
# Compatibility entry point; CMake installs the app-local compiler runtime.
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
python3 "$ROOT/tools/package/make_package.py" --build "${1:-$ROOT/build}" --out "${2:-$ROOT/dist}" --platform windows-x64