Publish VCC Plus OSS source distribution for 3.6.2 build 60

This commit is contained in:
Brian Holman committed 2026-11-13 00:14:03 -07:00
commit c652a5276d
1192 files changed
+272368

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Build the reviewed CoCo Letters source and a DOS-bootable DSK without downloading."""
import argparse
import json
import os
from pathlib import Path
import shutil
import subprocess
ROOT=Path(__file__).resolve().parents[2]
def main():
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--toolchain', type=Path, required=True)
parser.add_argument('--output', type=Path, default=ROOT/'.build/coco-letters')
args=parser.parse_args()
prefix=args.toolchain.resolve();out=args.output.resolve()
features=json.loads((prefix/'VCC-toolchain.json').read_text())
if not features['standaloneDisk']:
raise SystemExit('CoCo Letters requires the optional private standalone disk source; see docs/development/TOOLCHAIN.md')
if out.exists(): raise SystemExit('Choose a fresh --output directory')
out.mkdir(parents=True)
env=dict(os.environ, PATH=str(prefix/'bin')+os.pathsep+os.environ['PATH'])
env.setdefault('DEVELOPER_DIR','/Applications/Xcode.app/Contents/Developer')
for name in ('decbfile','bcontrol','bsound'):
shutil.copytree(ROOT/'third_party/cmoc-libraries'/name,out/name)
subprocess.run(['make','-j4',f'lib{name}.a'],cwd=out/name,env=env,check=True)
game=out/'game';shutil.copytree(ROOT/'third_party/examples/coco-letters',game)
# Upstream generates two outputs in one rule; serial make avoids duplicate writes.
subprocess.run(['make','DECBFILE_LIB_DIR=../decbfile','BCONTROL_LIB_DIR=../bcontrol','BSOUND_LIB_DIR=../bsound'],cwd=game,env=env,check=True)
disk=game/'coco-letters-0.1.0.dsk'
if disk.stat().st_size!=35*18*256: raise SystemExit('Unexpected disk geometry')
print(f'Built disk: {disk}\nMount in FD0, select RGB, then type DOS. Requires CoCo 3, 128 KB or more.')
if __name__=='__main__': main()
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Build pinned Perl for Make recipes; no host Perl is required after packaging."""
import argparse
import os
from pathlib import Path
import shutil
import subprocess
ROOT = Path(__file__).resolve().parents[2]
VERSION = '5.44.0'
def build(output, architectures, jobs):
source = ROOT / 'third_party/perl'
env = dict(os.environ)
env.setdefault('DEVELOPER_DIR', '/Applications/Xcode.app/Contents/Developer')
prefixes = {}
for arch in architectures:
work = output / arch / 'work'
prefix = output / arch / 'install'
shutil.copytree(source, work)
flags = f'-arch {arch} -mmacosx-version-min=14.0'
commands = [
['sh', 'Configure', '-des', f'-Dprefix={prefix}', '-Dcc=clang',
f'-Dccflags={flags}', f'-Dldflags={flags}',
f'-Dlddlflags=-bundle -undefined dynamic_lookup {flags}',
'-Duserelocatableinc', '-Uuseshrplib', '-Uuseithreads',
'-Dman1dir=none', '-Dman3dir=none'],
['/usr/bin/make', f'-j{jobs}'], ['/usr/bin/make', 'install']]
for command in commands:
print('+', ' '.join(map(str, command)), flush=True)
subprocess.run(command, cwd=work, env=env, check=True)
prefixes[arch] = prefix
return prefixes
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--output', type=Path, required=True)
parser.add_argument('--architectures', nargs='+', choices=['arm64', 'x86_64'], default=['arm64', 'x86_64'])
parser.add_argument('--jobs', type=int, default=4)
args = parser.parse_args()
output = args.output.resolve()
if output.exists(): parser.error('Choose a fresh output directory')
output.mkdir(parents=True)
build(output, list(dict.fromkeys(args.architectures)), max(1, args.jobs))
if __name__ == '__main__': main()
+86
View File
@@ -0,0 +1,86 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Build a relocatable macOS CMOC runtime; host SDK tools are build-time only."""
import argparse
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
ROOT = Path(__file__).resolve().parents[2]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--output', type=Path, default=ROOT / '.build/cmoc-runtime')
parser.add_argument('--architectures', nargs='+', choices=['arm64', 'x86_64'], default=['arm64', 'x86_64'])
parser.add_argument('--jobs', type=int, default=4)
parser.add_argument('--standalone-disk-source', type=Path, help='Optional private DECB-derived disk driver; never downloaded automatically')
args = parser.parse_args()
output = args.output.resolve()
if output.exists(): parser.error('Choose a fresh output directory')
output.mkdir(parents=True)
architectures = list(dict.fromkeys(args.architectures))
base = dict(os.environ)
base.setdefault('DEVELOPER_DIR', '/Applications/Xcode.app/Contents/Developer')
def run(*command, cwd=ROOT, env=base):
print('+', ' '.join(map(str, command)), flush=True)
subprocess.run(list(map(str, command)), cwd=cwd, env=env, check=True)
run(sys.executable, ROOT / 'tools/toolchain/verify-sources.py')
roots = []
for architecture in architectures:
arch_root = output / architecture
run(sys.executable, ROOT / 'tools/toolchain/build.py', '--output', arch_root,
'--host-arch', architecture, '--jobs', args.jobs)
prefix = arch_root / 'install'
env = dict(base, CC='clang', CXX='clang++',
CFLAGS=f'-O2 -arch {architecture} -mmacosx-version-min=14.0 -Wno-error=implicit-function-declaration',
CXXFLAGS=f'-O2 -arch {architecture} -mmacosx-version-min=14.0',
LDFLAGS=f'-arch {architecture} -mmacosx-version-min=14.0')
for name in ('mcpp', 'make'):
source = arch_root / 'work' / name
shutil.copytree(ROOT / 'third_party' / name, source)
for file in source.rglob('*'):
if file.is_file(): os.utime(file, (946684800, 946684800))
options = [f'--host={architecture}-apple-darwin', '--without-guile', '--disable-dependency-tracking'] if name == 'make' else []
run('./configure', f'--prefix={prefix}', *options, cwd=source, env=env)
run('/usr/bin/make', f'-j{args.jobs}', cwd=source, env=env)
run('/usr/bin/make', 'install', cwd=source, env=env)
run('xcrun', 'clang', '-O2', '-arch', architecture, '-mmacosx-version-min=14.0',
ROOT / 'tools/toolchain/cpp-mcpp.c', '-o', prefix / 'bin/cpp')
roots.append(prefix)
bundle = output / 'Toolchain'
for name in ('bin', 'libexec', 'share', 'LICENSES'): (bundle / name).mkdir(parents=True)
shutil.copytree(roots[0] / 'share/cmoc', bundle / 'share/cmoc')
shutil.copyfile(ROOT / 'tools/toolchain/cmoc-runtime.sh', bundle / 'bin/cmoc')
(bundle / 'bin/cmoc').chmod(0o755)
for tool in ('cmoc', 'cpp', 'mcpp', 'make', 'lwasm', 'lwlink', 'lwar', 'writecocofile'):
target = bundle / ('libexec' if tool == 'cmoc' else 'bin') / tool
inputs = [prefix / 'bin' / tool for prefix in roots]
if len(inputs) > 1: run('xcrun', 'lipo', '-create', *inputs, '-output', target)
else: shutil.copyfile(inputs[0], target)
target.chmod(0o755)
notices = {'CMOC-COPYING.txt': 'cmoc/COPYING', 'CMOC-README.txt': 'cmoc/README',
'LWTools-COPYING.txt': 'lwtools/COPYING', 'LWTools-GPL3.txt': 'lwtools/GPL3',
'MCPP-LICENSE.txt': 'mcpp/LICENSE', 'MAKE-COPYING.txt': 'make/COPYING'}
for target, source in notices.items(): shutil.copyfile(ROOT / 'third_party' / source, bundle / 'LICENSES' / target)
shutil.copyfile(ROOT / 'tools/toolchain/patches/README.md', bundle / 'LICENSES/CMOC-VCC-EXTENSIONS.txt')
record = {'schemaVersion': 1, 'cmoc': '0.1.100', 'lwtools': '4.25', 'mcpp': '2.7.2',
'make': '4.4.1', 'vccDebugMetadata': 1, 'vccAddZeroFlagsFix': 1, 'vccIndexedByteSubtractionFix': 1, 'vccIndexedArgumentLoadFix': 1, 'vccWriteCoCoFileBeforeDir': 1, 'vccLWASMProjectInputs': 1, 'architectures': architectures, 'privateRuntimeInputs': False,
'minimumMacOS': '14.0', 'appleDeveloperToolsRequiredAtRuntime': False}
(bundle / 'manifest.json').write_text(json.dumps(record, indent=2) + '\n')
perl_output = output / 'perl'
run(sys.executable, ROOT / 'tools/toolchain/build-perl.py', '--output', perl_output,
'--architectures', *architectures, '--jobs', args.jobs)
perl_prefixes = [argument for arch in architectures
for argument in ('--prefix', f'{arch}={perl_output / arch / "install"}')]
run(sys.executable, ROOT / 'tools/toolchain/stage-perl.py', bundle, *perl_prefixes)
run(sys.executable, ROOT / 'tools/toolchain/stage-libraries.py', bundle, '--jobs', args.jobs)
run(sys.executable, ROOT / 'tools/toolchain/stage-decbfile.py', bundle, '--jobs', args.jobs)
if args.standalone_disk_source:
run(sys.executable, ROOT / 'tools/toolchain/stage-standalone-disk.py', bundle, '--source', args.standalone_disk_source)
run(sys.executable, ROOT / 'tools/toolchain/verify-runtime.py', bundle)
print(f'Runtime ready: {bundle}\nStage at platforms/macos/LocalResources/ToolchainBundle for app builds.')
if __name__ == '__main__': main()
+94
View File
@@ -0,0 +1,94 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Build the pinned host toolchain in ignored storage; never download or install globally."""
import argparse
import hashlib
import json
import sys
import os
from pathlib import Path
import shutil
import subprocess
ROOT = Path(__file__).resolve().parents[2]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--output', type=Path, default=ROOT / '.build/toolchain')
parser.add_argument('--mc6839-rom', type=Path, help='Optional private Float09.bin')
parser.add_argument('--standalone-disk-source', type=Path, help='Optional private upstream dskcon-standalone.c')
parser.add_argument('--jobs', type=int, default=4)
parser.add_argument('--host-arch', choices=['native', 'arm64', 'x86_64'], default='native')
args = parser.parse_args()
out = args.output.resolve()
if out == ROOT or ROOT / 'third_party' in out.parents or out == ROOT / 'third_party':
parser.error('Choose a separate build output directory')
subprocess.run([sys.executable, str(ROOT / 'tools/toolchain/verify-sources.py')], check=True)
prefix = out / 'install'
work = out / 'work'
work.mkdir(parents=True, exist_ok=True)
env = dict(os.environ)
env['PATH'] = str(prefix / 'bin') + os.pathsep + env['PATH']
env.setdefault('DEVELOPER_DIR', '/Applications/Xcode.app/Contents/Developer')
if args.host_arch != 'native':
if sys.platform != 'darwin':
parser.error('--host-arch is currently a macOS build option')
flags = f'-O2 -arch {args.host_arch} -mmacosx-version-min=14.0'
env.update(CC='clang', CXX='clang++', CFLAGS=flags, CXXFLAGS=flags, LDFLAGS=f'-arch {args.host_arch} -mmacosx-version-min=14.0')
def run(*command, cwd):
print('+', ' '.join(map(str, command)), flush=True)
subprocess.run(list(map(str, command)), cwd=cwd, env=env, check=True)
# Copies protect pristine vendored snapshots from generated makefiles/objects.
for name in ('lwtools', 'cmoc'):
target = work / name
if target.exists():
raise SystemExit(f'{target} already exists; choose a fresh --output for a reproducible build')
shutil.copytree(ROOT / 'third_party' / name, target)
# Git does not retain mtimes. Equal times keep shipped generated files
# from unnecessarily invoking version-specific Autotools generators.
for item in target.rglob('*'):
if item.is_file():
os.utime(item, (946684800, 946684800))
# Retain pristine upstream snapshots; apply the reviewed patches only to the build copies.
run('/usr/bin/patch', '-p1', '-i', ROOT / 'tools/toolchain/patches/cmoc-debug-metadata.patch', cwd=work / 'cmoc')
run('/usr/bin/patch', '-p1', '-i', ROOT / 'tools/toolchain/patches/cmoc-add-zero-flags.patch', cwd=work / 'cmoc')
run('/usr/bin/patch', '-p1', '-i', ROOT / 'tools/toolchain/patches/cmoc-indexed-byte-subtraction.patch', cwd=work / 'cmoc')
run('/usr/bin/patch', '-p1', '-i', ROOT / 'tools/toolchain/patches/cmoc-indexed-argument-load.patch', cwd=work / 'cmoc')
run('/usr/bin/patch', '-p1', '-i', ROOT / 'tools/toolchain/patches/writecocofile-before-dir.patch', cwd=work / 'cmoc')
run('/usr/bin/patch', '-p1', '-i', ROOT / 'tools/toolchain/patches/lwtools-project-inputs.patch', cwd=work / 'lwtools')
run('make', f'-j{args.jobs}', f'PREFIX={prefix}', cwd=work / 'lwtools')
run('make', f'PREFIX={prefix}', 'install', cwd=work / 'lwtools')
# Optional private inputs are checked against the reviewed upstream release.
record = json.loads((ROOT / 'third_party/manifests/cmoc.json').read_text())
for supplied, relative in ((args.mc6839_rom, 'src/float/Float09.bin'),
(args.standalone_disk_source, 'src/stdlib/dskcon-standalone.c')):
if supplied:
if hashlib.sha256(supplied.read_bytes()).hexdigest() != record['excludedFileSHA256'][relative]:
raise SystemExit(f'Private input does not match reviewed CMOC release: {supplied}')
shutil.copyfile(supplied, work / 'cmoc' / relative)
for extension in ('am', 'in'):
if args.mc6839_rom:
path = work / 'cmoc/src/float' / ('Makefile.' + extension)
text = path.read_text().replace('cmoclib_DATA = ', 'cmoclib_DATA = float-ctor.mc6839_o float-ctor.mc6839_os9_o libcmoc-float-mc6839.a libcmoc-float-mc6839_os9.a ')
path.write_text(text); os.utime(path, (946684800, 946684800))
if args.standalone_disk_source:
path = work / 'cmoc/src/stdlib' / ('Makefile.' + extension)
text = path.read_text()
# Restore the omitted implementation beside the other C runtime sources.
assert 'C_COCO_BASIC =' in text
text = text.replace('C_COCO_BASIC =', 'C_COCO_BASIC = dskcon-standalone.c')
path.write_text(text); os.utime(path, (946684800, 946684800))
if sys.platform == 'darwin':
wrapper = prefix / 'bin/cpp'
shutil.copyfile(ROOT / 'tools/toolchain/cpp-macos.sh', wrapper)
wrapper.chmod(0o755)
run('./configure', f'--prefix={prefix}', '--with-writecocofile', cwd=work / 'cmoc')
run('make', f'-j{args.jobs}', cwd=work / 'cmoc')
run('make', 'install', cwd=work / 'cmoc')
(prefix / 'VCC-toolchain.json').write_text(json.dumps({'mc6839': bool(args.mc6839_rom), 'standaloneDisk': bool(args.standalone_disk_source)}, indent=2) + '\n')
for tool in ('cmoc', 'lwasm', 'lwlink', 'lwar'):
run(prefix / 'bin' / tool, '--version', cwd=out)
print(f'Toolchain ready in {prefix}; no app or global installation changed.')
if __name__ == '__main__':
main()
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Compile the pinned libraries and a CoCo program; optionally execute it in VCC."""
import argparse
import os
import json
from pathlib import Path
import shutil
import subprocess
ROOT = Path(__file__).resolve().parents[2]
def main():
p = argparse.ArgumentParser(description=__doc__)
p.add_argument('--toolchain', type=Path, default=ROOT / '.build/toolchain/install')
p.add_argument('--output', type=Path, default=ROOT / '.build/toolchain-check')
p.add_argument('--rom', type=Path, help='Optional private 32 KiB CoCo 3 ROM; read only')
p.add_argument('--disk-rom', type=Path, help='Private Disk BASIC ROM for the optional game check')
p.add_argument('--game-disk', type=Path, help='Source-built CoCo Letters DSK; read only')
args = p.parse_args()
if (args.disk_rom or args.game_disk) and not (args.rom and args.disk_rom and args.game_disk):
p.error('The game check needs --rom, --disk-rom and --game-disk together')
out=args.output.resolve();out.mkdir(parents=True,exist_ok=True)
prefix=args.toolchain.resolve()
env=dict(os.environ, PATH=str(prefix/'bin')+os.pathsep+os.environ['PATH'])
env.setdefault('DEVELOPER_DIR','/Applications/Xcode.app/Contents/Developer')
def run(*command, cwd=out, **kw):
print('+', ' '.join(map(str,command)),flush=True)
return subprocess.run(list(map(str,command)),cwd=cwd,env=env,check=True,**kw)
run('python3',ROOT/'tools/toolchain/verify-sources.py')
for source in sorted((ROOT/'third_party/cmoc-libraries').iterdir()):
if not source.is_dir(): continue
dest=out/source.name
if dest.exists(): raise SystemExit(f'{dest} already exists; use a fresh --output')
shutil.copytree(source,dest)
run('make','-j4',f'lib{source.name}.a',cwd=dest)
assert (dest/f'lib{source.name}.a').stat().st_size > 0
run(prefix/'bin/cmoc','--coco','--intermediate','-o',out/'HELLO.BIN',ROOT/'tests/toolchain/hello.c')
data=(out/'HELLO.BIN').read_bytes()
offset=0;blocks=0
while offset<len(data) and data[offset]==0:
size=int.from_bytes(data[offset+1:offset+3],'big');offset+=5+size;blocks+=1
assert blocks and offset+5==len(data) and data[offset:offset+3]==b'\xff\0\0', 'Invalid DECB executable'
# A small known assembly result verifies the checked-in assembler independently.
(out/'known.asm').write_text(' org $4000\nstart lda #$42\n sta $0400\n rts\n end start\n')
run(prefix/'bin/lwasm','--format=raw','--output=known.bin','--list=known.lst','known.asm')
assert (out/'known.bin').read_bytes()==bytes.fromhex('8642b7040039')
features=json.loads((prefix/'VCC-toolchain.json').read_text())
if features['mc6839']:
run(prefix/'bin/cmoc','--coco','--mc6839','-o',out/'FLOAT.BIN',ROOT/'tests/toolchain/float.c')
if args.rom:
build=out/'xcode'
run('xcodebuild','-project',ROOT/'platforms/macos/VCC.xcodeproj','-scheme','VCCCoreChecks','-configuration','Release','-derivedDataPath',build,'build')
run('xcrun','clang++','-std=c++17','-O2','-mmacosx-version-min=14.0',ROOT/'tests/toolchain/run-compiled.cpp',build/'Build/Products/Release/libVCCCore.a','-o',out/'run-compiled')
run(out/'run-compiled',args.rom.resolve(),out/'HELLO.BIN')
for optimization in ('-O0', '-O2'):
binary = out / f'logical-negation{optimization}.bin'
run(prefix/'bin/cmoc', '--coco', '--org=2800', optimization, '-Werror', '-o', binary,
ROOT/'tests/toolchain/logical-negation.c')
run(out/'run-compiled', args.rom.resolve(), binary, 'NOT 010 1000 END')
run('python3', ROOT/'tests/toolchain/indexed-subtraction/check.py', prefix,
build/'Build/Products/Release/libVCCCore.a', args.rom.resolve())
run('python3', ROOT/'tests/toolchain/indexed-arguments/check.py', prefix,
build/'Build/Products/Release/libVCCCore.a', args.rom.resolve())
if features['mc6839']:
run(out/'run-compiled',args.rom.resolve(),out/'FLOAT.BIN','MC6839 MATH OK')
if args.game_disk:
run('xcrun','clang++','-std=c++17','-O2','-mmacosx-version-min=14.0',ROOT/'tests/toolchain/run-coco-letters.cpp',build/'Build/Products/Release/libVCCCore.a','-o',out/'run-coco-letters')
run(out/'run-coco-letters',args.rom.resolve(),args.disk_rom.resolve(),args.game_disk.resolve(),out/'captures')
print('PASS: nine library archives, CMOC compile/link, DECB format, assembler bytes; optional MC6839 arithmetic')
if __name__=='__main__': main()
+18
View File
@@ -0,0 +1,18 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
# The pinned CMOC release interpolates runtime-library paths into shell commands.
# A private, space-free alias makes a relocated 'VCC Plus.app' safe while
# dependency-file escaping is handled by the maintained compiler patch. Source/output names are supplied relative to
# the project's build directory by the prototype.
set -eu
runtime=$(CDPATH= cd -- "$(/usr/bin/dirname -- "$0")/.." && pwd -P)
alias_dir=$(/usr/bin/mktemp -d /tmp/vcc-cmoc.XXXXXXXX)
trap '/bin/rm -f "$alias_dir/cmoc"; /bin/rmdir "$alias_dir"' EXIT
/bin/ln -s "$runtime/share/cmoc" "$alias_dir/cmoc"
export CMOCPKGDATADIR="$alias_dir/cmoc"
export CMOCFLOATLIBDIR="$alias_dir/cmoc/lib"
export PATH="$runtime/bin:${PATH:-/usr/bin:/bin}"
if [ "${VCC_CMOC_COMPAT:-0}" = 1 ]; then
set -- "-I$alias_dir/cmoc/include/vcc/compat" "$@"
fi
"$runtime/libexec/cmoc" "$@"
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
# CMOC expects modern preprocessing. Apple's legacy cpp shim forces traditional
# mode, which misreads valid macros in hirestxt. Use Clang directly.
exec xcrun clang -E -Wno-builtin-macro-redefined "$@"
+174
View File
@@ -0,0 +1,174 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Adapt CMOC's GCC-style preprocessor invocation to bundled mcpp. Ordinary C
// keeps mcpp's standard token separation. Only explicit asm { ... } bodies use
// mcpp's documented assembler expansion, which preserves #MACRO and -MACRO,x.
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <mach-o/dyld.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
typedef struct { size_t start, end; } Block;
typedef struct { char *text; size_t size; Block *blocks; size_t count; } Output;
static int preprocess(const char *executable, char **args, Output *out) {
FILE *capture = tmpfile();
if (!capture) { perror("preprocessor capture"); return 1; }
pid_t child = fork();
if (child < 0) { perror("preprocessor fork"); fclose(capture); return 1; }
if (!child) {
if (dup2(fileno(capture), STDOUT_FILENO) < 0) _exit(126);
execv(executable, args); perror("bundled mcpp"); _exit(127);
}
int status;
while (waitpid(child, &status, 0) < 0) {
if (errno != EINTR) { fclose(capture); return 1; }
}
off_t length = ftello(capture);
// Guard malformed tools/unbounded inputs; no truncated source is compiled.
if (length < 0 || length > 64 * 1024 * 1024 || fseeko(capture, 0, SEEK_SET)) {
fputs("Preprocessor output is too large or unreadable\n", stderr);
fclose(capture); return 1;
}
out->size = (size_t)length;
out->text = malloc(out->size + 1);
if (!out->text || fread(out->text, 1, out->size, capture) != out->size) {
fclose(capture); return 1;
}
out->text[out->size] = 0;
fclose(capture);
return WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status);
}
static int identifier(char c) { return isalnum((unsigned char)c) || c == '_'; }
static size_t quote_end(const char *s, size_t i, size_t length) {
char quote = s[i++];
while (i < length) {
if (s[i] == '\\' && i + 1 < length) i += 2;
else if (s[i++] == quote) break;
}
return i;
}
static int find_blocks(Output *out) {
const char *s = out->text;
size_t i = 0;
while (i < out->size) {
// Line markers contain filenames and must never count as source tokens.
if ((i == 0 || s[i - 1] == '\n') && s[i] == '#') {
while (i < out->size && s[i] != '\n') ++i;
} else if (s[i] == '"' || s[i] == '\'') i = quote_end(s, i, out->size);
else if (s[i] == '/' && i + 1 < out->size && s[i + 1] == '/') {
while (i < out->size && s[i] != '\n') ++i;
} else if (s[i] == '/' && i + 1 < out->size && s[i + 1] == '*') {
i += 2;
while (i + 1 < out->size && !(s[i] == '*' && s[i + 1] == '/')) ++i;
i = i + 2 < out->size ? i + 2 : out->size;
} else if (i + 3 <= out->size && !memcmp(s + i, "asm", 3)
&& (i == 0 || !identifier(s[i - 1]))
&& (i + 3 == out->size || !identifier(s[i + 3]))) {
i += 3;
while (i < out->size && isspace((unsigned char)s[i])) ++i;
if (i == out->size || s[i] != '{') continue;
size_t start = ++i;
unsigned depth = 1;
while (i < out->size && depth) {
// Match CMOC's balanced-brace inline-assembly token, retaining
// line markers and assembler comments byte for byte.
if (s[i] == '{') ++depth;
else if (s[i] == '}') --depth;
++i;
}
if (depth) return 0;
Block *grown = realloc(out->blocks, (out->count + 1) * sizeof(Block));
if (!grown) return 0;
out->blocks = grown;
out->blocks[out->count++] = (Block){ start, i - 1 };
} else ++i;
}
return 1;
}
static void emit(const char *text, size_t length) {
size_t start = 0;
while (start < length) {
size_t end = start;
while (end < length && text[end] != '\n') ++end;
if (end < length) ++end;
// mcpp's cur_file() prints raw path bytes inside quotes. Escape them
// for CMOC's C-style marker parser; paths may themselves contain quotes.
// CMOC accepts GCC markers (# NUMBER), not mcpp's #line NUMBER.
size_t number = start;
if (end - start >= 6 && !memcmp(text + start, "#line ", 6)) number += 6;
else if (end - start >= 2 && text[start] == '#' && text[start + 1] == ' ') number += 2;
size_t p = number;
while (p < end && isdigit((unsigned char)text[p])) ++p;
while (p < end && text[p] == ' ') ++p;
size_t last = end;
while (last > p && text[last - 1] != '"') --last;
if (number != start && p < end && text[p] == '"' && last > p + 1) {
fputs("# ", stdout);
fwrite(text + number, 1, p + 1 - number, stdout);
for (size_t i = p + 1; i < last - 1; ++i) {
if (text[i] == '"' || text[i] == '\\') fputc('\\', stdout);
fputc(text[i], stdout);
}
fwrite(text + last - 1, 1, end - last + 1, stdout);
} else fwrite(text + start, 1, end - start, stdout);
start = end;
}
}
int main(int argc, char **argv) {
char executable[PATH_MAX], resolved[PATH_MAX];
uint32_t size = sizeof executable;
if (_NSGetExecutablePath(executable, &size) || !realpath(executable, resolved)) {
perror("Cannot locate bundled preprocessor"); return 1;
}
char *last = strrchr(resolved, '/');
if (!last || (size_t)(last - resolved) + sizeof "/mcpp" > sizeof resolved) return 1;
strcpy(last + 1, "mcpp");
char **args = calloc((size_t)argc + 9, sizeof *args);
if (!args) return 1;
int count = 0;
args[count++] = resolved;
args[count++] = "-e"; args[count++] = "utf8";
args[count++] = "-W0";
for (int i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-xc++")) args[count++] = "-+";
else if (!strcmp(argv[i], "-nostdinc")) args[count++] = "-I-";
else if (!strcmp(argv[i], "-undef")) args[count++] = "-N";
else if (!strcmp(argv[i], "-Wno-builtin-macro-redefined")) continue;
else args[count++] = argv[i];
}
Output standard = {0}, assembly = {0};
int result = preprocess(resolved, args, &standard);
if (!result && !find_blocks(&standard)) {
fputs("Cannot identify CMOC inline assembly blocks\n", stderr); result = 1;
}
if (!result && standard.count) {
args[count++] = "-a";
result = preprocess(resolved, args, &assembly);
if (!result && (!find_blocks(&assembly) || assembly.count != standard.count)) {
fputs("CMOC inline assembly differs between preprocessing modes\n", stderr); result = 1;
}
if (!result) {
size_t offset = 0;
for (size_t i = 0; i < standard.count; ++i) {
Block a = standard.blocks[i], b = assembly.blocks[i];
emit(standard.text + offset, a.start - offset);
emit(assembly.text + b.start, b.end - b.start);
offset = a.end;
}
emit(standard.text + offset, standard.size - offset);
}
} else if (standard.text) emit(standard.text, standard.size);
free(standard.text); free(standard.blocks);
free(assembly.text); free(assembly.blocks); free(args);
if (ferror(stdout) || fflush(stdout)) return 1;
return result;
}
+104
View File
@@ -0,0 +1,104 @@
# Local CMOC compiler patches
`cmoc-debug-metadata.patch` is an original VCC Plus extension to CMOC 0.1.100,
modified November 3, 2026 and licensed GPL-3.0-or-later. It is applied to the ignored build copy by
`tools/toolchain/build.py`; the pinned upstream snapshot and its checksums stay
unchanged.
With `-fno-omit-frame-pointer`, the compiler writes `* VCCDBG1 {…}` JSON comments
into retained assembly/listings. Metadata comes from resolved compiler types and
declarations, not a C-source text parser. It contains:
- function entry, frame-ready body and epilogue boundaries;
- lexical block ranges, including `for`-statement scopes;
- signedness, storage size, array dimensions, member offsets and pointer types;
- explicit `floatingFormat` tags: `coco-basic-40` for Color BASIC/native 5-byte floats and `ieee754-binary32-be` for MC6839 single precision;
- linker symbols for globals/static locals and U-relative offsets for parameters
and ordinary locals.
The boundaries are zero-byte assembler labels. They can inhibit some assembly
optimizations in debug builds; default/release compiler invocations emit neither
the comments nor these labels. No instructions or data bytes are introduced by
the metadata. The compiler runtime manifest records `vccDebugMetadata: 1`.
The app accepts metadata only from objects/listings/linker maps verified against
the same frozen sources and final executable. Inspection additionally checks
live mapped code and uses the debugger's atomic, non-I/O memory snapshot. Frame
locals require `-O0` as well as the preserved frame pointer and are unavailable in assembly-only functions, alternative calling
conventions, prologues/epilogues, or builds without a preserved U frame. Unsupported
floating-point formats and recursively truncated types remain explicitly
unavailable. Legacy metadata without `floatingFormat` is accepted but not decoded by guessing from storage size. Known format tags must agree with storage size; a genuine double-precision type is not tagged as supported. CMOC 0.1.100 currently lowers source-level `double` to `float`, so that alias carries the selected single-precision format. Expressions do not execute guest code or modify memory.
To regenerate the patch, edit a separate copy of the upstream source and produce
a unified diff with `a/src/…` and `b/src/…` paths. Verify that applying it to a fresh
copy succeeds and that ordinary optimized builds retain their original bytes.
## Indexed byte arithmetic and comparisons
`cmoc-indexed-byte-subtraction.patch` corrects three peephole rules in the build copy of CMOC 0.1.100 (modified November 7, 2026, GPL-3.0-or-later). On the 6809, B is the low byte of D. A byte load or negation can change the effective address of a later B- or D-indexed operand, including an indirect one. The subtraction and comparison rules now keep the original instruction order in those cases. The rules that remove a stack push also guard operands whose address would change with the stack pointer or an index side effect. Ordinary immediate substitutions remain available.
The [guest regression](../../../tests/toolchain/indexed-subtraction/qualification.c) exercises `184 - heights[i]` with runtime indices, variable bases, byte wraparound, both operand orders and equality/inequality against an array element. The [runner](../../../tests/toolchain/indexed-subtraction/check.py) checks the output against host-calculated expectations on MC6809 and HD6309 at `-O0` and `-O2`. It also runs as part of `tools/toolchain/check.py --rom`. Packaged runtimes identify the change with `vccIndexedByteSubtractionFix: 1` in their manifest.
## Indexed byte loads in function arguments
`cmoc-indexed-argument-load.patch` (November 11, 2026, GPL-3.0-or-later)
corrects `removeUselessLdaOrLdb` in the CMOC 0.1.100 build copy. The rule used
to remove an index reload from `LDB index; LDX #array; LDB D,X`, although B is
the low byte of D and is needed to select the loaded byte. Consecutive indexed
function arguments could therefore use the preceding argument's value as an
array subscript. The rule now uses the existing instruction-effects analysis
to preserve B dependencies in both intervening and final loads, including
indirect B/D-indexed operands. It also checks the actual operand for
predecrement/postincrement side effects. Independent overwritten loads remain
eligible for removal.
The [target regression](../../../tests/toolchain/indexed-arguments/qualification.c)
passes adjacent elements from two arrays at runtime indices 0 and 2, using
byte indices, word indices and pointer bases, with distinct surrounding
sentinels. Its [runner](../../../tests/toolchain/indexed-arguments/check.py)
executes `--coco --no-relocate --switch=jump` binaries at `-O0` and `-O2` on
MC6809 and HD6309; it is included in `tools/toolchain/check.py --rom`.
The [rule check](../../../tests/toolchain/indexed-arguments/check-rule.py)
links the actual built compiler objects and checks dependency/side-effect guards
as well as safe removals. See the [qualification record](../../../docs/development/CMOC_INDEXED_ARGUMENT_LOAD.md).
Packaged runtimes identify the change with `vccIndexedArgumentLoadFix: 1`.
## Logical negation of integer results
`cmoc-add-zero-flags.patch` (November 7, 2026, GPL-3.0-or-later) corrects CMOC 0.1.100's general peephole optimizer. CMOC emits `ADDD #0` to set the flags for a word-sized comparison with zero. A function can return 1 in D with Z still set from clearing A. Removing the add before the `tfrZtoB` helper made `!getReady()` return 1 in that case. The patch removes the general rule's unproven add-zero deletions and byte-test substitutions. The separate optimizations for recognized load/compare/branch sequences still run.
The [guest regression](../../../tests/toolchain/logical-negation.c) prints actual results for zero, widened unsigned bytes and 16-bit values. Run `tools/toolchain/check.py --rom` with a local CoCo 3 ROM to check those results at `-O0` and `-O2` on MC6809 and HD6309. Rebuilt app toolchains record `vccAddZeroFlagsFix: 1` in the manifest.
## Explicit before-directory disk allocation
`writecocofile-before-dir.patch` (November 4, 2026, GPL-3.0-or-later) adds
`--allocate-before-dir` as an explicit choice of the existing forward allocator.
It starts at granule zero, skips occupied granules, and continues above the
directory track if necessary. It does not imply a strict below-directory limit.
The last allocation option wins, as with the existing choices.
`build.py` applies it only to the build copy. `build-runtime.py` records
`vccWriteCoCoFileBeforeDir: 1`. The original CoCo Letters Makefile uses this option;
its former recipe-removal patch is retired and the vendored game matches upstream.
Runtime verification checks allocation order, byte-identical default behavior,
file readback, and spillover beyond the lower half of the disk.
## LWASM project input boundary
The native Assembly workspace passes `--project-inputs` when invoking LWASM.
`lwtools-project-inputs.patch` (November 5, 2026, GPL-3.0-or-later) constrains
source and binary input reads to regular files inside the physical working
directory. It checks each open, including binary data reopened during emission.
The companion `--project-map=FILE` records physical source paths, physical
one-based lines, sections, offsets and original instruction bytes. Macro
expansions, data directives, synthesized 6800/convenience operations and
OS-9 calls cannot become source breakpoints. The Swift client verifies final
DECB bytes after relocation. A project map requested with `--6809` also
rejects source pragmas that change that target.
The app supplies an isolated, symlink-free copy of the source snapshot. Other
invocations retain ordinary LWASM path behavior. Custom Make recipes execute
as user-supplied build commands and have a separate trust boundary.
Rebuild and stage the native runtime with `build-runtime.py` before packaging
the workspace. The runtime manifest records `vccLWASMProjectInputs: 1`;
older assemblers reject the required option.
@@ -0,0 +1,57 @@
--- a/src/ASMText2.cpp
+++ b/src/ASMText2.cpp
@@ -1517,8 +1517,9 @@
}
-// Remove AND, OR, MUL or ADD operations if we can show that
-// they will not change performance of the program.
+// ADD #0 can be an explicit condition-code test. Leave it to rules that
+// prove which flags the surrounding instructions produce and consume.
+// In particular, a called runtime helper may read the flags on entry.
bool
ASMText::removeAndOrMulAddSub(size_t index)
{
@@ -1588,42 +1589,6 @@
commentOut(index, "optim: removeAndOrMulAddSub case 5");
madeChanges = true;
}
- } else if ((instr == "ADDA") || (instr == "ADDB") || (instr == "ADDD")) {
- if ((instr[3] == 'A' && simulator.regs.accum.a.known && simulator.regs.accum.a.val == 0) &&
- (instr[3] == 'B' && simulator.regs.accum.b.known && simulator.regs.accum.b.val == 0) &&
- (instr[3] == 'D' && simulator.regs.accum.dknown() && simulator.regs.accum.dval() == 0)) {
- // We know that A, B or D are zero, so change to a LD
- const Element &e1 = elements[index + 1];
- if (e1.type != INSTR || !isBasicBlockEndingInstruction(e1)) {
- char newInstr[8];
- snprintf(newInstr, sizeof(newInstr), "LD%s", instr.c_str() + 3);
- replaceWithInstr(index, newInstr, oper, "optim: removeAndOrMulAddSub case 6");
- madeChanges = true;
- }
- } else if (extractConstantLiteral(e.fields[1], val)) {
- // We know that the operand is a constant 0 and the side effects are not valued,
- // so we can comment it out
- const Element &e1 = elements[index + 1];
- if (val == 0 && (e1.type == INSTR && !isBasicBlockEndingInstruction(e1))) {
- InsEffects effects(e1);
- if (!(effects.read & CC)) {
- commentOut(index, "optim: removeAndOrMulAddSub case 7");
- madeChanges = true;
- }
- } else if (val == 0 && e1.type == INSTR && isBasicBlockEndingInstruction(e1) &&
- (((instr[3] == 'D') && (simulator.regs.accum.a.known && simulator.regs.accum.a.val == 0)) ||
- (instr[3] == 'B'))) {
- // ADDD #0 and A is definitely zero or ADDB #0 so replace with TSTB
- replaceWithInstr(index, "TSTB", "", "optim: removeAndOrMulAddSub case 8");
- madeChanges = true;
- } else if (val == 0 && e1.type == INSTR && isBasicBlockEndingInstruction(e1) &&
- (((instr[3] == 'D') && (simulator.regs.accum.b.known && simulator.regs.accum.b.val == 0)) ||
- (instr[3] == 'A'))) {
- // ADDD #0 and B is definitely zero or ADDA #0 so replace with TSTA
- replaceWithInstr(index, "TSTA", "", "optim: removeAndOrMulAddSub case 9");
- madeChanges = true;
- }
- }
} else if ((instr == "LEAX") && (oper == "D,X")) {
if (simulator.regs.accum.dknown() && simulator.regs.accum.dval() == 0) {
commentOut(index, "optim: removeAndOrMulAddSub case 10");
@@ -0,0 +1,230 @@
--- a/src/Declaration.cpp
+++ b/src/Declaration.cpp
@@ -15,6 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "VCCDebug.h"
#include "Declaration.h"
#include "TranslationUnit.h"
@@ -334,6 +335,8 @@
bool canBeStaticInit = (initializationExpr && initializationExpr->isStaticallyInitializable(*getTypeDesc()));
if (canBeStaticInit != withStaticInitializer)
return true; // nothing to do
+
+ if (isGlobal()) VCCDebug::variable(out, *this, "", "");
if (withStaticInitializer)
{
--- a/src/ForStmt.cpp
+++ b/src/ForStmt.cpp
@@ -15,6 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "VCCDebug.h"
#include "ForStmt.h"
#include "TranslationUnit.h"
@@ -115,6 +116,8 @@
//cerr << "pushing ForStmt scope:\n";
pushScopeIfExists();
+ const string debugBegin = getScope() && VCCDebug::enabled() ? VCCDebug::label() : "", debugEnd = getScope() && VCCDebug::enabled() ? VCCDebug::label() : "";
+ VCCDebug::scope(out, getScope(), debugBegin, debugEnd);
TranslationUnit &tu = TranslationUnit::instance();
string bodyLabel = TranslationUnit::instance().generateLabel('L');
@@ -128,6 +131,7 @@
tu.popBreakableLabels();
//cerr << "popping ForStmt scope:\n";
+ if (getScope() && VCCDebug::enabled()) out.emitLabel(debugEnd);
popScopeIfExists();
return cs;
}
--- a/src/FunctionDef.cpp
+++ b/src/FunctionDef.cpp
@@ -15,6 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "VCCDebug.h"
#include "FunctionDef.h"
#include "Scope.h"
@@ -853,11 +854,23 @@
functor.emitComments(out);
}
+ // VCC Plus: exact compiler-resolved body/scope boundaries, before epilogue.
+ const string debugBody = VCCDebug::enabled() ? VCCDebug::label() : "", debugEnd = VCCDebug::enabled() ? VCCDebug::label() : "";
+ if (VCCDebug::enabled()) out.emitComment("VCCDBG1 {\"kind\":\"function\",\"name\":" + VCCDebug::quote(functionId)
+ + ",\"location\":" + VCCDebug::quote(getLineNo())
+ + ",\"symbol\":" + VCCDebug::quote(functionLabel)
+ + ",\"begin\":" + VCCDebug::quote(debugBody) + ",\"end\":" + VCCDebug::quote(debugEnd)
+ + ",\"frame\":" + (needStackFrame && !isAssemblyOnly() && callConvention == DEFAULT_CMOC_CALL_CONV
+ && TranslationUnit::instance().getFramePointerOption() == FramePointerOption::KEEP_ALL
+ && TranslationUnit::instance().hasUnoptimizedDebugStorage() ? "true" : "false") + "}");
+
// Generate code for the body:
TranslationUnit::instance().setCurrentFunctionEndLabel(endLabel);
TranslationUnit::instance().pushScope(const_cast<Scope *>(getScope())); // const_cast should be removed...
+ VCCDebug::scope(out, getScope(), debugBody, debugEnd);
bool success = bodyStmts->emitCode(out, false);
+ if (VCCDebug::enabled()) out.emitLabel(debugEnd);
out.emitLabel(endLabel, "end of " + functionId + "()");
if (!asmOnly && callConvention == GCC6809_CALL_CONV && getTypeSize() == 2)
--- a/src/TranslationUnit.cpp
+++ b/src/TranslationUnit.cpp
@@ -2573,3 +2573,6 @@
irFile << "}\n"; // main JSON object
return true;
}
+
+// VCC Plus: optimized stores/register reuse cannot claim stable C locals.
+bool TranslationUnit::hasUnoptimizedDebugStorage() const { return params.optimizationLevel == 0; }
--- a/src/TranslationUnit.h
+++ b/src/TranslationUnit.h
@@ -194,6 +194,7 @@
bool isRelocatabilitySupported() const;
FramePointerOption getFramePointerOption() const;
+ bool hasUnoptimizedDebugStorage() const;
// Called during parsing, right after the parser recognized the #pragma directive.
// May change some fields of this TranslationUnit object.
--- a/src/TreeSequence.cpp
+++ b/src/TreeSequence.cpp
@@ -15,6 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "VCCDebug.h"
#include "TreeSequence.h"
#include "TranslationUnit.h"
@@ -141,6 +142,8 @@
const bool isCommaExpr = !!dynamic_cast<const CommaExpr *>(this);
pushScopeIfExists();
+ const string debugBegin = getScope() && VCCDebug::enabled() ? VCCDebug::label() : "", debugEnd = getScope() && VCCDebug::enabled() ? VCCDebug::label() : "";
+ VCCDebug::scope(out, getScope(), debugBegin, debugEnd);
bool success = true;
for (vector<Tree *>::const_iterator it = sequence.begin(); it != sequence.end(); it++)
@@ -178,6 +181,7 @@
}
}
+ if (getScope() && VCCDebug::enabled()) out.emitLabel(debugEnd);
popScopeIfExists();
return success;
--- /dev/null
+++ b/src/VCCDebug.h
@@ -0,0 +1,101 @@
+// VCC Plus compiler debug extension. SPDX-License-Identifier: GPL-3.0-or-later
+// Metadata comments and labels occupy no guest memory. Never infer C storage
+// or type layout from source text: use the compiler's resolved declarations.
+#ifndef VCC_DEBUG_H
+#define VCC_DEBUG_H
+#include "ASMText.h"
+#include "Declaration.h"
+#include "Scope.h"
+#include "TranslationUnit.h"
+#include "ClassDef.h"
+#include <sstream>
+#include <iomanip>
+namespace VCCDebug {
+inline bool enabled() { return TranslationUnit::instance().getFramePointerOption() == FramePointerOption::KEEP_ALL; }
+inline std::string arrayType(const TypeDesc *, const std::vector<uint16_t> &, unsigned);
+inline std::string quote(const std::string &s) {
+ std::ostringstream o; o << '"';
+ for (unsigned char c : s) {
+ if (c == '"' || c == '\\') o << '\\' << c;
+ else if (c < 32) o << "\\u00" << std::hex << std::setw(2) << std::setfill('0') << unsigned(c) << std::dec;
+ else o << c;
+ }
+ o << '"'; return o.str();
+}
+inline std::string type(const TypeDesc *td, unsigned depth = 0) {
+ std::ostringstream o;
+ const int size = td->type == FUNCTION_TYPE || td->type == VOID_TYPE || (td->type == ARRAY_TYPE && td->numArrayElements == TypeDesc::NO_DIMENSION) ? 0 : TranslationUnit::instance().getTypeSize(*td);
+ o << "{\"name\":" << quote(td->toString()) << ",\"size\":" << (size < 0 ? 0 : size);
+ if (depth > 5) o << ",\"kind\":\"unsupported\"";
+ else if (td->type == BYTE_TYPE || td->type == WORD_TYPE || td->isLong())
+ o << ",\"kind\":\"integer\",\"signed\":" << (td->isSigned ? "true" : "false");
+ else if (td->isReal()) {
+ auto &tu = TranslationUnit::instance();
+ const char *format = "unsupported";
+ if (!td->isDouble() && tu.isFloatingPointSupported()) {
+ if (tu.getFloatingPointLibrary() == FloatingPointLibrary::MC6839_LIB && size == 4)
+ format = "ieee754-binary32-be";
+ else if (size == 5 && (tu.getFloatingPointLibrary() == FloatingPointLibrary::NATIVE_LIB
+ || tu.getTargetPlatform() == COCO_BASIC || tu.getTargetPlatform() == DRAGON))
+ format = "coco-basic-40";
+ }
+ o << ",\"kind\":\"floating\",\"floatingFormat\":" << quote(format);
+ }
+ else if (td->type == POINTER_TYPE)
+ o << ",\"kind\":\"pointer\",\"element\":" << type(td->pointedTypeDesc, depth + 1);
+ else if (td->type == ARRAY_TYPE && td->numArrayElements != TypeDesc::NO_DIMENSION)
+ o << ",\"kind\":\"array\",\"count\":" << td->numArrayElements << ",\"element\":" << type(td->pointedTypeDesc, depth + 1);
+ else if (td->type == CLASS_TYPE) {
+ const ClassDef *cl = TranslationUnit::instance().getClassDef(td->className);
+ o << ",\"kind\":\"aggregate\",\"members\":[";
+ if (cl) for (size_t i=0;i<cl->getNumDataMembers();++i) {
+ auto m = cl->getDataMember(i);
+ if (i) o << ',';
+ auto dims = m->getArrayDimensions(); m->getTypeDesc()->appendDimensions(dims);
+ o << "{\"name\":" << quote(m->getName()) << ",\"offset\":" << cl->getDataMemberOffset(i, NULL)
+ << ",\"type\":" << (dims.empty() ? type(m->getTypeDesc(), depth+1) : arrayType(m->getTypeDesc(), dims, depth+1)) << '}';
+ }
+ o << ']';
+ } else o << ",\"kind\":\"unsupported\"";
+ o << '}'; return o.str();
+}
+inline std::string arrayType(const TypeDesc *original, const std::vector<uint16_t> &dims, unsigned depth) {
+ const TypeDesc *td=original;
+ while (td->type == ARRAY_TYPE) td=td->pointedTypeDesc;
+ std::string result=type(td, depth+1);
+ size_t size=TranslationUnit::instance().getTypeSize(*td);
+ for (auto it=dims.rbegin();it!=dims.rend();++it) {
+ size *= *it;
+ std::ostringstream o; o << "{\"name\":" << quote(original->toString())
+ << ",\"kind\":\"array\",\"size\":" << size << ",\"count\":" << *it << ",\"element\":" << result << '}';
+ result=o.str();
+ }
+ return result;
+}
+inline std::string declarationType(const Declaration &decl) {
+ return decl.getTypeDesc()->type == ARRAY_TYPE ? arrayType(decl.getTypeDesc(), decl.arrayDimensions, 0) : type(decl.getTypeDesc());
+}
+inline std::string label() { return ".vcc.debug." + TranslationUnit::instance().generateLabel('L'); }
+inline void variable(ASMText &out, const Declaration &d, const std::string &begin, const std::string &end) {
+ if (!enabled() || d.isExtern || d.getVariableId().empty() || d.getVariableId()[0] == '$') return;
+ uint16_t size=0; if (!d.getVariableSizeInBytes(size) || !size) return;
+ std::ostringstream o; o << "VCCDBG1 {\"kind\":\"variable\",\"name\":" << quote(d.getVariableId())
+ << ",\"location\":" << quote(d.getLineNo()) << ",\"type\":" << declarationType(d)
+ << ",\"begin\":" << quote(begin) << ",\"end\":" << quote(end)
+ << ",\"static\":" << (d.isStatic() ? "true" : "false");
+ if (d.isGlobal() || d.isLocalStatic()) o << ",\"symbol\":" << quote(d.getLabel());
+ else o << ",\"offset\":" << d.getFrameDisplacement();
+ o << '}'; out.emitComment(o.str());
+}
+inline void scope(ASMText &out, const Scope *s, const std::string &begin, const std::string &end) {
+ if (!enabled() || !s) return;
+ class Visitor : public Scope::DeclarationFunctor {
+ ASMText &out; const std::string &begin, &end;
+ public:
+ Visitor(ASMText &o, const std::string &b, const std::string &e):out(o),begin(b),end(e){}
+ bool operator()(Declaration &d) override { variable(out,d,begin,end); return true; }
+ } visit(out,begin,end);
+ out.emitLabel(begin); s->iterateDeclarations(visit,false);
+}
+}
+#endif
@@ -0,0 +1,45 @@
--- a/src/ASMText2.cpp
+++ b/src/ASMText2.cpp
@@ -4952,29 +4952,31 @@
// Look for this:
-// LDB {foo} ; {bar} involves not pre/post-increment, e.g., LDB ,S+
-// LDX/LEAX {bar} ; {bar} does not involve B, e.g., LDX B,U
-// LDB {baz}
-// Remove the first LDB.
+// LDB {foo} ; no pre/post-increment side effects
+// LDX/LEAX {bar} ; must not read B, including D-indexed operands
+// LDB {baz} ; must not read the previous B in its effective address
+// Remove the first LDB only when its value and side effects are unused.
//
bool
ASMText::removeUselessLdaOrLdb(size_t index)
{
if (! isInstrAnyArg(index, "LDB"))
return false;
- const string &arg = elements[index].fields[0];
- if (startsWith(arg, ",-") || endsWith(arg, "+")) // if pre/post increment
- return false;
+ if (isInstrWithPreDecrOrPostIncr(index))
+ return false; // Removing the load must not remove an index/stack update.
size_t otherLoad = findNextInstrBeforeLabel(index + 1);
if (! isInstrAnyArg(otherLoad, "LDX") && ! isInstrAnyArg(otherLoad, "LEAX"))
return false;
- const string &otherLoadArg = elements[otherLoad].fields[1];
- if (startsWith(otherLoadArg, "B,"))
- return false; // we have "B,reg" as the arg to LDX/LEAX, so previous LDB is useful
+ // B is also the low byte of D. Use the common instruction-effects
+ // analysis for both direct and indirect accumulator-indexed operands.
+ if (InsEffects(elements[otherLoad]).read & B)
+ return false;
size_t secondLdAcc = findNextInstrBeforeLabel(otherLoad + 1);
if (! isInstrAnyArg(secondLdAcc, "LDB"))
return false;
-
+ if (InsEffects(elements[secondLdAcc]).read & B)
+ return false; // The overwritten value may still select the byte to load.
+
// Apply the optimization.
commentOut(index, "optim: removeUselessLdaOrLdb (removed LDB b/c later LDB)");
return true;
@@ -0,0 +1,68 @@
--- a/src/ASMText2.cpp
+++ b/src/ASMText2.cpp
@@ -4159,16 +4159,27 @@
}
+// B is the low half of D. Both direct and indirect accumulator-indexed
+// addresses can therefore depend on the value of B before a rewrite.
+static bool
+usesBInAddress(const string &operand)
+{
+ return startsWith(operand, "B,") || startsWith(operand, "D,")
+ || startsWith(operand, "[B,") || startsWith(operand, "[D,");
+}
+
+
// Look for: LDB foo; PSHS B; LDB bar; CMPB ,S+.
// Change to: LDB bar; CMPB foo.
-// LDB args must not involve S.
+// Swapping the two reads must preserve their offsets and index registers.
//
bool
ASMText::removePushBFromLdbPushLdbCmp(size_t index)
{
if (!isInstrAnyArg(index, "LDB"))
return false;
- if (elements[index].fields[1].find(",S") != string::npos)
+ if (usesBInAddress(elements[index].fields[1]) || isInstrWithPreDecrOrPostIncr(index)
+ || elements[index].fields[1].find(",S") != string::npos)
return false;
size_t pushIndex = findNextInstrBeforeLabel(index + 1);
@@ -4178,7 +4189,8 @@
size_t secondLoadIndex = findNextInstrBeforeLabel(pushIndex + 1);
if (!isInstrAnyArg(secondLoadIndex, "LDB"))
return false;
- if (elements[secondLoadIndex].fields[1].find(",S") != string::npos)
+ if (usesBInAddress(elements[secondLoadIndex].fields[1]) || isInstrWithPreDecrOrPostIncr(secondLoadIndex)
+ || elements[secondLoadIndex].fields[1].find(",S") != string::npos)
return false;
size_t cmpIndex = findNextInstrBeforeLabel(secondLoadIndex + 1);
@@ -4440,6 +4452,13 @@
if (!isInstr(subIndex, "SUBB", ",S+"))
return false;
+ // NEGB changes B before the load's address is used, and removing the
+ // push changes S. Keep the original sequence when either matters.
+ const string &operand = elements[ldbIndex].fields[1];
+ if (usesBInAddress(operand) || operand.find(",S") != string::npos
+ || isInstrWithPreDecrOrPostIncr(ldbIndex))
+ return false;
+
// Apply the optimization.
commentOut(index, "optim: removePushBBeforeSubB"); // remove PSHS
elements[subIndex].fields[0] = "ADDB";
@@ -4833,6 +4852,11 @@
if (isInstrWithPreDecrOrPostIncr(addb))
return false;
+ // Swapping the operands also changes which value of B is available
+ // when each effective address is evaluated.
+ if (usesBInAddress(elements[index].fields[1]) || usesBInAddress(elements[addb].fields[1]))
+ return false;
+
// Apply the optimization.
const string ldbArg = elements[index].fields[1];
elements[index].fields[1] = elements[addb].fields[1];
@@ -0,0 +1,362 @@
--- a/lwasm/input.c
+++ b/lwasm/input.c
@@ -26,6 +26,9 @@
*/
#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
@@ -65,8 +68,40 @@
void *data;
int data2;
char *filespec;
+ const char *source_path;
+ int source_line;
struct input_stack_node *stack;
};
+
+/* VCC Plus native assembly builds run in a private, immutable snapshot.
+ * Resolve the target before opening it, including the second binary-include
+ * read during emission. Ordinary LWASM invocations retain upstream behavior. */
+static char *project_root;
+
+void input_restrict_to_project(void)
+{
+ project_root = realpath(".", NULL);
+ if (!project_root)
+ lw_error("Cannot resolve assembly project folder.\n");
+}
+
+FILE *input_fopen(const char *path)
+{
+ if (project_root)
+ {
+ char resolved[PATH_MAX];
+ struct stat info;
+ size_t length = strlen(project_root);
+ if (!realpath(path, resolved))
+ return NULL;
+ if (strncmp(project_root, resolved, length) || resolved[length] != '/')
+ lw_error("Assembly input leaves the project snapshot: %s\n", path);
+ if (stat(resolved, &info) != 0 || !S_ISREG(info.st_mode))
+ lw_error("Assembly input is not a regular file: %s\n", path);
+ return fopen(resolved, "rb");
+ }
+ return fopen(path, "rb");
+}
static char *make_filename(char *p, char *f)
{
@@ -110,7 +145,7 @@
}
/* this adds real filenames that were opened to a list */
-void input_add_to_resource_list(asmstate_t *as, const char *s)
+static const char *input_add_to_resource_list(asmstate_t *as, const char *s)
{
struct ifl *ifl;
@@ -127,6 +162,7 @@
ifl_head = ifl;
ifl -> fn = lw_strdup(s);
}
+ return ifl -> fn;
}
void input_init(asmstate_t *as)
@@ -155,6 +191,12 @@
char *dn, *dp;
// int o;
+ if (as->project_map_file && project_root)
+ {
+ char resolved[PATH_MAX];
+ if (realpath(fn, resolved))
+ IS->source_path = input_add_to_resource_list(as, resolved + strlen(project_root) + 1);
+ }
dn = lw_strdup(fn);
lw_stack_push(as -> includelist, dn);
@@ -186,6 +228,8 @@
struct input_stack *t;
t = lw_alloc(sizeof(struct input_stack));
+ t -> source_path = NULL;
+ t -> source_line = 0;
t -> filespec = lw_strdup(s);
t -> type = input_type_string;
@@ -204,6 +248,8 @@
char *p, *p2;
t = lw_alloc(sizeof(struct input_stack));
+ t -> source_path = NULL;
+ t -> source_line = 0;
t -> filespec = lw_strdup(s);
for (s2 = s; *s2 && (*s2 != ':'); s2++)
@@ -238,7 +284,7 @@
if (input_isabsolute(s))
{
/* absolute path */
- IS -> data = fopen(s, "rb");
+ IS -> data = input_fopen(s);
debug_message(as, 1, "Opening (abs) %s", s);
if (!IS -> data && !IGNOREERROR)
{
@@ -257,7 +303,7 @@
p = lw_stack_top(as -> file_dir);
p2 = make_filename(p, s);
debug_message(as, 1, "Open: (cd) %s\n", p2);
- IS -> data = fopen(p2, "rb");
+ IS -> data = input_fopen(p2);
if (IS -> data)
{
input_pushpath(as, p2);
@@ -274,7 +320,7 @@
{
p2 = make_filename(p, s);
debug_message(as, 1, "Open (sp): %s\n", p2);
- IS -> data = fopen(p2, "rb");
+ IS -> data = input_fopen(p2);
if (IS -> data)
{
input_pushpath(as, p2);
@@ -300,7 +346,7 @@
if (s[0] == '-' && s[1] == '\0')
IS -> data = stdin;
else
- IS -> data = fopen(s, "rb");
+ IS -> data = input_fopen(s);
if (!IS -> data)
{
@@ -328,7 +374,7 @@
debug_message(as, 2, "Open file (st abs) %s", s);
if (as -> flags & FLAG_DEPEND)
printf("%s\n", s);
- fp = fopen(s, "rb");
+ fp = input_fopen(s);
if (!fp)
{
return NULL;
@@ -343,7 +389,7 @@
p = lw_stack_top(as -> file_dir);
p2 = make_filename(p ? p : "", s);
debug_message(as, 2, "Open file (st cd) %s", p2);
- fp = fopen(p2, "rb");
+ fp = input_fopen(p2);
if (fp)
{
if (as -> flags & FLAG_DEPEND)
@@ -362,7 +408,7 @@
{
p2 = make_filename(p, s);
debug_message(as, 2, "Open file (st ip) %s", p2);
- fp = fopen(p2, "rb");
+ fp = input_fopen(p2);
if (fp)
{
if (as -> flags & FLAG_DEPEND)
@@ -471,6 +517,7 @@
if (eol)
{
s = lw_strdup(linebuff);
+ IS->source_line++;
return s;
}
}
@@ -537,6 +584,15 @@
default:
lw_error("Problem reading from unknown input type\n");
return NULL;
+ }
+}
+
+void input_project_location(asmstate_t *as, line_t *line)
+{
+ if (IS && IS->type != input_type_string)
+ {
+ line->project_source = IS->source_path;
+ line->project_line = IS->source_line;
}
}
--- a/lwasm/input.h
+++ b/lwasm/input.h
@@ -32,6 +32,9 @@
void input_stack_push(asmstate_t *as, input_stack_entry *se);
input_stack_entry *input_stack_pop(asmstate_t *as, int magic, int (*fn)(input_stack_entry *e, void *data), void *data);
+void input_restrict_to_project(void);
+FILE *input_fopen(const char *path);
+void input_project_location(asmstate_t *as, line_t *line);
void input_init(asmstate_t *as);
void input_openstring(asmstate_t *as, char *s, char *str);
void input_open(asmstate_t *as, char *s);
--- a/lwasm/list.c
+++ b/lwasm/list.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <lw_alloc.h>
+#include <lw_error.h>
#include <lw_string.h>
#include "lwasm.h"
@@ -489,3 +490,43 @@
if (of && of != stdout)
fclose(of);
}
+
+/* VCC Plus project source map. Keep the normal human-readable listing intact.
+ * Physical file lines are captured at input; macro strings have no file identity.
+ * The client still validates original object bytes, link relocations and the BIN. */
+void do_project_map(asmstate_t *as)
+{
+ FILE *out = fopen(as->project_map_file, "w");
+ line_t *line;
+ const int synthetic = lwasm_insn_is6800 | lwasm_insn_is6809conv |
+ lwasm_insn_is6309conv | lwasm_insn_isemuext;
+ if (!out) lw_error("Cannot write project instruction map.\n");
+ for (line = as->line_head; line; line = line->next)
+ {
+ const char *section = line->csect ? line->csect->name : "";
+ lw_expr_t address;
+ int i;
+ if (!line->project_source || !line->emitted_opcode || line->insn < 0 ||
+ (instab[line->insn].flags & synthetic) || !strcmp(instab[line->insn].opcode, "os9") ||
+ line->outputl < 1 || line->outputl > 8 || line->outputl != line->len ||
+ strpbrk(line->project_source, "\t\r\n") || strpbrk(section, "\t\r\n"))
+ continue;
+ address = lw_expr_copy(line->addr);
+ as->exportcheck = 1;
+ as->csect = line->csect;
+ lwasm_reduce_expr(as, address);
+ as->exportcheck = 0;
+ if (lw_expr_istype(address, lw_expr_type_int))
+ {
+ int value = lw_expr_intval(address);
+ if (value >= 0 && value <= 65535)
+ {
+ fprintf(out, "%s\t%d\t%s\t%04X\t", line->project_source, line->project_line, section, value);
+ for (i = 0; i < line->outputl; ++i) fprintf(out, "%02X", line->output[i]);
+ fputc('\n', out);
+ }
+ }
+ lw_expr_destroy(address);
+ }
+ if (fclose(out)) lw_error("Cannot finish writing project instruction map.\n");
+}
--- a/lwasm/lwasm.c
+++ b/lwasm/lwasm.c
@@ -504,6 +504,7 @@
void lwasm_emitop(line_t *cl, int opc)
{
+ cl->emitted_opcode = 1;
if (cl->cycle_base == 0)
lwasm_cycle_update_count(cl, opc); /* only call first time, never on postbyte */
--- a/lwasm/lwasm.h
+++ b/lwasm/lwasm.h
@@ -278,6 +278,9 @@
struct line_s
{
+ const char *project_source;
+ int project_line;
+ int emitted_opcode;
lw_expr_t addr; // assembly address of the line
lw_expr_t daddr; // data address of the line (os9 only)
lw_expr_t phase; // the "phase" setting (assumed address for assembly)
@@ -440,6 +443,8 @@
sectiontab_t *sections; // section table
exportlist_t *exportlist; // list of exported symbols
importlist_t *importlist; // list of imported symbols
+ char *project_map_file;
+ int project_6809_only;
char *list_file; // name of file to list to
char *symbol_dump_file; // name of file to dump symbol table to
int tabwidth; // tab width in list file
--- a/lwasm/main.c
+++ b/lwasm/main.c
@@ -71,6 +71,8 @@
{ "6800compat", 0x200, 0, 0, "Enable 6800 compatibility instructions, equivalent to --pragma=6800compat" },
{ "no-output", 0x105, 0, 0, "Inhibit creation of output file" },
{ "no-warn", 0x109, "FLAG", 0, "Suppress warnings of the specified type" },
+ { "project-map", 0x10d, "FILE", 0, "Write physical source instruction locations for a project snapshot" },
+ { "project-inputs", 0x10c, 0, 0, "Restrict all assembly inputs to the current project folder" },
{ "error-format", 0x10b, "STYLE", 0, "Error output style: lwasm (default), gcc, vs" },
{ 0 }
};
@@ -82,6 +84,12 @@
switch (key)
{
+ case 0x10d:
+ as->project_map_file = lw_strdup(arg);
+ break;
+ case 0x10c:
+ input_restrict_to_project();
+ break;
case 'I':
lw_stringlist_addstring(as -> include_list, arg);
break;
@@ -333,6 +341,7 @@
void do_output(asmstate_t *as);
void do_symdump(asmstate_t *as);
void do_list(asmstate_t *as);
+void do_project_map(asmstate_t *as);
void do_map(asmstate_t *as);
lw_expr_t lwasm_evaluate_special(int t, void *ptr, void *priv);
lw_expr_t lwasm_evaluate_var(char *var, void *priv);
@@ -391,6 +400,7 @@
asmstate.output_file = lw_strdup("a.out");
}
+ asmstate.project_6809_only = asmstate.project_map_file && (asmstate.pragmas & PRAGMA_6809);
input_init(&asmstate);
for (passnum = 0; passlist[passnum].fn; passnum++)
@@ -450,6 +460,7 @@
}
do_symdump(&asmstate);
do_list(&asmstate);
+ if (asmstate.project_map_file) do_project_map(&asmstate);
do_map(&asmstate);
if (asmstate.testmode_errorcount > 0) exit(1);
--- a/lwasm/pass1.c
+++ b/lwasm/pass1.c
@@ -115,12 +115,15 @@
memset(cl, 0, sizeof(line_t));
cl -> outputl = -1;
cl -> linespec = lw_strdup(input_curspec(as));
+ if (as->project_map_file) input_project_location(as, cl);
cl -> prev = as -> line_tail;
cl -> insn = -1;
cl -> as = as;
cl -> inmod = as -> inmod;
cl -> csect = as -> csect;
cl -> pragmas = as -> pragmas;
+ if (as->project_6809_only && !(cl->pragmas & PRAGMA_6809))
+ lwasm_register_error2(as, cl, E_6309_INVALID, "Source changes the selected 6809 project target.");
cl -> context = as -> context;
cl -> hasoperand = 1; // default: assume operand present; cleared by inherent insns
cl -> ltext = lw_strdup(line);
--- a/lwasm/pseudo.c
+++ b/lwasm/pseudo.c
@@ -1662,7 +1662,7 @@
FILE *fp;
int c, i;
- fp = fopen(l -> lstr, "rb");
+ fp = input_fopen(l -> lstr);
if (!fp)
{
lwasm_register_error2(as, l, E_FILE_OPEN, "%s", "(emit)!");
@@ -0,0 +1,32 @@
--- a/src/writecocofile.cpp
+++ b/src/writecocofile.cpp
@@ -1,3 +1,8 @@
+/* VCC Plus modification, November 4, 2026: support an explicit
+ --allocate-before-dir option using the existing forward allocator.
+ This modification is licensed GPL-3.0-or-later.
+*/
+
/* writecocofile.cpp - A tool to write native files to a CoCo DECB disk image.
Copyright (C) 2003-2026 Pierre Sarrazin <http://sarrazip.com/>
@@ -874,6 +879,8 @@
"--kill|-k Kill the designated file.\n"
"--read|-r Read instead of writing. Refuses to overwrite existing native file.\n"
"--stdout|-s Like --read, but print file contents on standard out.\n"
+ "--allocate-before-dir Allocate from granule zero (the default), preferring space\n"
+ " before the directory, then continuing above it if needed.\n"
"--allocate-after-dir When adding a file, allocate granules after the directory track,\n"
" then continue allocating below that track if needed.\n"
"--allocate-from-end When adding a file, allocate granules from the end.\n"
@@ -1376,6 +1383,11 @@
granuleAllocator.reset(new BackwardGranuleAllocator());
continue;
}
+ if (curopt == "--allocate-before-dir")
+ {
+ granuleAllocator.reset(new ForwardGranuleAllocator());
+ continue;
+ }
if (curopt == "--allocate-after-dir")
{
granuleAllocator.reset(new PostDirTrackGranuleAllocator());
+30
View File
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Select the matching relocatable Perl installation. Architecture-specific
// Config.pm and XS modules remain paired with the interpreter that built them.
#include <mach-o/dyld.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv) {
(void)argc;
char path[PATH_MAX], resolved[PATH_MAX]; uint32_t size = sizeof path;
if (_NSGetExecutablePath(path, &size) || !realpath(path, resolved)) {
perror("Cannot locate bundled Perl"); return 1;
}
char *last = strrchr(resolved, '/'); if (!last) return 1; *last = 0;
last = strrchr(resolved, '/'); if (!last) return 1; *last = 0;
#if defined(__aarch64__)
const char *relative = "/libexec/perl/arm64/bin/perl";
#elif defined(__x86_64__)
const char *relative = "/libexec/perl/x86_64/bin/perl";
#else
#error Unsupported Perl host architecture
#endif
if (strlen(resolved) + strlen(relative) >= sizeof path) return 1;
snprintf(path, sizeof path, "%s%s", resolved, relative);
argv[0] = path;
execv(path, argv);
perror("Cannot execute bundled Perl"); return 1;
}
@@ -0,0 +1,94 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Prepare the real CoCo Letters Make project for local VCC Plus qualification.
This is a test fixture, not an application resource. The explicitly supplied
private standalone disk source and generated game stay in the chosen local
output folder and are never copied into the public toolchain or Git snapshot.
"""
import argparse
import hashlib
import json
from pathlib import Path
import shutil
import subprocess
import sys
ROOT = Path(__file__).resolve().parents[2]
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--output', type=Path, required=True)
parser.add_argument('--standalone-disk-source', type=Path, required=True)
args = parser.parse_args()
output = args.output.resolve()
if output.exists(): parser.error('Choose a fresh project directory')
if output == ROOT or ROOT / 'third_party' == output or ROOT / 'third_party' in output.parents:
parser.error('Choose local test storage outside the source snapshots')
record = json.loads((ROOT / 'third_party/manifests/cmoc.json').read_text())
expected = record['excludedFileSHA256']['src/stdlib/dskcon-standalone.c']
if hashlib.sha256(args.standalone_disk_source.read_bytes()).hexdigest() != expected:
parser.error('Private disk source does not match the reviewed CMOC release')
subprocess.run([sys.executable, ROOT / 'tools/toolchain/verify-sources.py'], check=True)
shutil.copytree(ROOT / 'third_party/examples/coco-letters', output)
# A grouped target makes the upstream two-output dictionary recipe safe when
# GNU Make runs in parallel. The vendored source itself remains unchanged.
upstream = (output / 'Makefile').read_text()
original = '$(DATA_FILENAME) $(WORD_LENGTH_FILENAME): $(BUILD_DATA)'
if upstream.count(original) != 1: raise SystemExit('Review updated dictionary generation rule')
upstream = upstream.replace(original, '$(DATA_FILENAME) $(WORD_LENGTH_FILENAME) &: $(BUILD_DATA)')
(output / 'Game.mk').write_text(upstream)
for name in ('decbfile', 'bcontrol', 'bsound'):
shutil.copytree(ROOT / 'third_party/cmoc-libraries' / name, output / 'libraries' / name)
(output / 'private').mkdir()
shutil.copyfile(args.standalone_disk_source, output / 'private/dskcon-standalone.c')
(output / 'Makefile').write_text('''# VCC Plus local qualification wrapper. GPL-3.0-or-later.
# Game.mk is the upstream game Makefile, with its dictionary recipe grouped.
override DECBFILE_LIB_DIR = libraries/decbfile
override BCONTROL_LIB_DIR = libraries/bcontrol
override BSOUND_LIB_DIR = libraries/bsound
include Game.mk
.DEFAULT_GOAL := all
INTERMEDIATE = --intermediate
LIBS += private/dskcon-standalone.o
$(BIN): private/dskcon-standalone.o
private/dskcon-standalone.o: private/dskcon-standalone.c
\t$(CMOC) --coco --intermediate -O2 -c -o $@ $<
libraries/decbfile/libdecbfile.a: $(wildcard libraries/decbfile/*.c libraries/decbfile/*.h) libraries/decbfile/Makefile
\t$(MAKE) -C libraries/decbfile libdecbfile.a
libraries/bcontrol/libbcontrol.a: $(wildcard libraries/bcontrol/*.c libraries/bcontrol/*.h) libraries/bcontrol/Makefile
\t$(MAKE) -C libraries/bcontrol libbcontrol.a
libraries/bsound/libbsound.a: $(wildcard libraries/bsound/*.c libraries/bsound/*.h) libraries/bsound/Makefile
\t$(MAKE) -C libraries/bsound libbsound.a
.PHONY: clean-libraries
clean: clean-libraries
clean-libraries:
\t$(MAKE) -C libraries/decbfile clean
\t$(MAKE) -C libraries/bcontrol clean
\t$(MAKE) -C libraries/bsound clean
\trm -f private/*.o private/*.s private/*.lst $(DSK)
''')
(output / 'vccplus-project.json').write_text(json.dumps({
'entrySource': 'main.c', 'makefile': 'Makefile', 'buildTarget': 'all',
'cleanTarget': 'clean', 'diskTarget': 'all', 'binary': 'letters.bin',
'diskImage': 'coco-letters-0.1.0.dsk', 'launchMode': 'disk',
'launchCommands': ['DOS'], 'jobs': 4,
'configurations': [{'name': 'Debug', 'makeArguments': ['INTERMEDIATE=--intermediate']},
{'name': 'Release', 'makeArguments': []}]
}, indent=2) + '\n')
(output / '.gitignore').write_text('private/\n*.bin\n*.dsk\n*.dat\n*.o\n*.s\n*.lst\n*.map\n*.link\n*.d\nword-length-index.c\n')
(output / 'VCC-QUALIFICATION.txt').write_text(
'Local qualification fixture. Includes separately supplied private disk source.\n'
'Do not distribute this folder as part of VCC Plus or its public toolchain.\n'
'Open the folder in C Development, build the all target, then mount/boot its disk.\n'
'Requires CoCo 3, at least 128 KB, floppy controller with Disk BASIC, and RGB video.\n'
'The original optimization flags are retained to fit its memory map.\n'
'Source breakpoints are available only where exact executable mappings are verified.\n')
print('Prepared local Make project:', output)
if __name__ == '__main__': main()
+32
View File
@@ -0,0 +1,32 @@
# SPDX-License-Identifier: GPL-3.0-or-later
"""Validate the explicitly staged private disk-driver extension."""
import hashlib
STANDALONE_FILES = {
'share/cmoc/lib/libdskcon-standalone.a',
'share/cmoc/include/dskcon-standalone.h',
'LICENSES/DSKCON-STANDALONE-NOTICE.txt',
}
def validate_private_inputs(runtime, record):
disk = record.get('standaloneDisk')
if disk is None:
if record.get('privateRuntimeInputs') is not False:
raise ValueError('Private runtime input declaration is missing')
if any((runtime / path).exists() for path in STANDALONE_FILES - {'share/cmoc/include/dskcon-standalone.h'}):
raise ValueError('Undeclared standalone disk payload')
return
if record.get('privateRuntimeInputs') is not True or disk.get('profile') != 'decb-derived-standalone':
raise ValueError('Unsupported private runtime profile')
hashes = disk.get('filesSHA256', {})
if set(hashes) != STANDALONE_FILES:
raise ValueError('Incomplete standalone disk payload declaration')
if disk.get('license') != 'public-domain-except-DECB-derived-portions':
raise ValueError('Missing standalone disk license distinction')
if not isinstance(disk.get('sourceSHA256'), str) or len(disk['sourceSHA256']) != 64:
raise ValueError('Missing standalone disk source identity')
for relative, expected in hashes.items():
path = runtime / relative
if path.is_symlink() or not path.is_file() or hashlib.sha256(path.read_bytes()).hexdigest() != expected:
raise ValueError('Standalone disk payload does not match its manifest: ' + relative)
+100
View File
@@ -0,0 +1,100 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Prebuild the public-domain, ROM-backed DECB file API into an existing runtime.
The same bundled compiler/preprocessor builds libraries and end-user programs;
Apple developer tools are not required for this staging operation.
"""
import argparse
from concurrent.futures import ThreadPoolExecutor
import hashlib
import json
import os
from pathlib import Path
import re
import shutil
import subprocess
import sys
import tempfile
from runtime_inputs import validate_private_inputs
ROOT = Path(__file__).resolve().parents[2]
SOURCE = ROOT / 'third_party/cmoc-libraries/decbfile'
VERSION = '0.1.13'
EXCLUDED = {
'drivewire.c', 'dwReadBeckerPort.c', 'dwWriteBeckerPort.c',
'dwReadBitBangerSerialPort.c', 'dwWriteBitBangerSerialPort.c',
'FileChoiceDialog.c', 'runDOSLoader.c', 'binfile.c', 'writeMemoryToFile.c',
'readFileToMemory.c', 'readFileToDynamicMemory.c', 'decbutil.c', 'crc16.c',
}
def sha(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('runtime', type=Path)
parser.add_argument('--jobs', type=int, default=4)
args = parser.parse_args()
runtime = args.runtime.resolve()
manifest_path = runtime / 'manifest.json'
manifest = json.loads(manifest_path.read_text())
validate_private_inputs(runtime, manifest)
source_manifest = ROOT / 'third_party/manifests/decbfile.json'
source_record = json.loads(source_manifest.read_text())
if source_record['version'] != VERSION:
parser.error('Review the ROM-backed library selection before changing upstream version')
subprocess.run([sys.executable, ROOT / 'tools/toolchain/verify-sources.py'], check=True)
source_list = re.search(r'^LIBSRC = \\\n(.*?)\n\nLIBHEADERS', (SOURCE / 'Makefile').read_text(), re.M | re.S)
if not source_list:
parser.error('Unexpected upstream source list')
sources = source_list.group(1).replace('\\', '').split()
if not EXCLUDED.issubset(sources):
parser.error('Unexpected upstream optional components')
selected = [name for name in sources if name not in EXCLUDED]
env = dict(os.environ, PATH=str(runtime / 'bin') + ':/usr/bin:/bin')
env['DEVELOPER_DIR'] = '/VCC-no-developer-tools'
env['SDKROOT'] = '/VCC-no-sdk'
# A simple temporary path also avoids upstream CMOC's shell-quoting limits.
with tempfile.TemporaryDirectory(prefix='vcc-decbfile-', dir='/tmp') as folder:
work = Path(folder)
for name in selected + ['decbfile.h', 'decbfile_private.h']:
shutil.copyfile(SOURCE / name, work / name)
def compile_source(name):
subprocess.run([str(runtime / 'bin/cmoc'), '--coco', '-O2',
'-DNDEBUG', '-Wfor-condition-sizes', '-Werror', '-I.', '-c',
'-o', name[:-2] + '.o', name], cwd=work, env=env, check=True)
with ThreadPoolExecutor(max_workers=max(1, args.jobs)) as pool:
list(pool.map(compile_source, selected))
archive = work / 'libdecbfile.a'
subprocess.run([str(runtime / 'bin/lwar'), '--create', str(archive),
*[name[:-2] + '.o' for name in selected]], cwd=work, env=env, check=True)
archive_listing = subprocess.check_output([str(runtime / 'bin/lwar'), '--list', str(archive)], text=True)
for name in EXCLUDED:
if name[:-2] + '.o' in archive_listing:
raise SystemExit('Unexpected excluded archive member: ' + name)
target_archive = runtime / 'share/cmoc/lib/libdecbfile.a'
target_header = runtime / 'share/cmoc/include/decbfile.h'
shutil.copyfile(archive, target_archive)
shutil.copyfile(SOURCE / 'decbfile.h', target_header)
# Retain the original declaration verbatim instead of assigning a GPL label
# to a component whose author explicitly released it into the public domain.
header_notice = (SOURCE / 'decbfile.h').read_text().split('*/', 1)[0] + '*/\n'
notice = ('DECB File Library ' + VERSION + ' — ROM-backed core\n\n' + header_notice +
'\nUses the Disk BASIC ROM already mapped in the emulated machine.\n'
'No Disk BASIC ROM bytes or standalone Disk BASIC-derived driver are included in this archive.\n'
'Optional standalone, DriveWire, UI and binary-loader extensions are not included.\n\n'
'Included upstream source files:\n' + ''.join(' ' + name + '\n' for name in selected))
(runtime / 'LICENSES/DECBFILE-NOTICE.txt').write_text(notice)
manifest['decbfile'] = {'version': VERSION, 'profile': 'rom-backed-core',
'license': 'public-domain', 'requiresDiskBASICROM': True,
'standaloneDriverIncluded': False, 'sourceFiles': selected,
'sourceManifestSHA256': sha(source_manifest),
'archiveSHA256': sha(target_archive), 'headerSHA256': sha(target_header)}
manifest_path.write_text(json.dumps(manifest, indent=2) + '\n')
print(f'PASS: staged {len(selected)} public-domain DECB core objects; link with -ldecbfile')
if __name__ == '__main__': main()
+87
View File
@@ -0,0 +1,87 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Compile the original VCC Plus guest libraries with the installed CMOC."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
ROOT = Path(__file__).resolve().parents[2]
SDK = ROOT / "sdk/cmoc"
LIBRARIES = {"ssc": "ssc", "orch90": "orch90", "gime": "gime", "input": "input", "bank": "bank", "sdc": "sdc", "vcccompat": "compat"}
def stage(runtime):
manifest_file = runtime / "manifest.json"
manifest = json.loads(manifest_file.read_text())
env = dict(os.environ, PATH=str(runtime / "bin") + ":/usr/bin:/bin", LC_ALL="C",
VCC_CMOC_COMPAT="0")
with tempfile.TemporaryDirectory(dir="/tmp", prefix="vcc-sdk-") as tmp:
work = Path(tmp)
include = work / "include"
shutil.copytree(SDK / "include", include)
shutil.copytree(SDK / "compat/include", include / "vcc/compat")
# Build against the pinned public header even when the ROM library has
# not yet been staged in a fresh runtime. Only SDK headers ship here.
shutil.copyfile(ROOT / "third_party/cmoc-libraries/decbfile/decbfile.h", include / "decbfile.h")
payload = {}
for name, source in LIBRARIES.items():
folder = work / source
folder.mkdir()
objects = []
flags = ["-I" + str(include)]
if name == "vcccompat":
flags.insert(0, "-I" + str(include / "vcc/compat"))
for header in (SDK / source).glob("*.h"):
shutil.copyfile(header, folder / header.name)
for unit in sorted((SDK / source).glob("*.c")):
shutil.copyfile(unit, folder / unit.name)
obj = unit.stem + ".o"
subprocess.run([runtime / "bin/cmoc", "--coco", "-O2", "-Werror",
*flags, "-c", "-o", obj, unit.name],
cwd=folder, env=env, check=True)
objects.append(obj)
if not objects:
raise ValueError("No compilation units for " + name)
archive = folder / ("lib" + name + ".a")
subprocess.run([runtime / "bin/lwar", "--create", archive.name, *objects],
cwd=folder, env=env, check=True)
if name == "vcccompat":
headers = [*sorted((include / "vcc/compat").glob("*.h")),
include / "vcc/printer.h", include / "vcc/cassette.h", include / "vcc/decimal.h"]
else:
headers = [include / ("vcc/" + name + ".h")]
files = {"share/cmoc/lib/" + archive.name: archive, "LICENSES/VCC-Guest-SDK.txt": ROOT / "COPYING"}
files.update({"share/cmoc/include/" + h.relative_to(include).as_posix(): h for h in headers})
version = {"vcccompat": "0.14.0", "ssc": "0.2.0", "orch90": "0.2.0"}.get(name, "0.1.0")
manifest.setdefault("libraries", {})[name] = dict(version=version, profile="coco",
license="GPL-3.0-or-later", filesSHA256={k: hashlib.sha256(p.read_bytes()).hexdigest() for k, p in files.items()})
if name == "vcccompat":
manifest["libraries"][name].update(diskReadStreams=True, diskWriteStreams=True, diskStreamPositioning=True,
boundedHeap=True, integerConversions=True, reentrantTokenizer=True,
diskUpdateStreams=True, createAppendUpdateStreams=True, diskFormattedOutput=True,
diskStreamClearError=True, printerFormattedOutput=True,
cassetteTextFiles=True, diskFileManagement=True, fixedDecimal=True)
if name == "ssc":
manifest["libraries"][name]["storedSpeechAndEffects"] = True
if name == "orch90":
manifest["libraries"][name]["backgroundPlayback"] = True
payload.update(files)
for path, original in payload.items():
target = runtime / path
target.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(original, target)
shutil.copyfile(ROOT / "tools/toolchain/cmoc-runtime.sh", runtime / "bin/cmoc")
temporary = manifest_file.with_suffix(".json.new")
temporary.write_text(json.dumps(manifest, indent=2) + "\n")
temporary.replace(manifest_file)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("runtime", type=Path)
stage(parser.parse_args().runtime.resolve())
+89
View File
@@ -0,0 +1,89 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Build and package reviewed CMOC libraries with the standalone compiler chain."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
from runtime_inputs import validate_private_inputs
ROOT = Path(__file__).resolve().parents[2]
LIBRARIES = ('astar', 'bcontrol', 'bgraph', 'bsound', 'cardgame', 'ebitor', 'hirestxt', 'wydealloc')
def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest()
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('runtime', type=Path)
parser.add_argument('--jobs', type=int, default=4)
args = parser.parse_args()
runtime = args.runtime.resolve()
manifest_path = runtime / 'manifest.json'
manifest = json.loads(manifest_path.read_text())
validate_private_inputs(runtime, manifest)
subprocess.run([sys.executable, ROOT / 'tools/toolchain/verify-sources.py'], check=True)
env = dict(os.environ, PATH=str(runtime / 'bin') + ':/usr/bin:/bin', LC_ALL='C',
DEVELOPER_DIR='/VCC-no-developer-tools', SDKROOT='/VCC-no-sdk')
records = {}
with tempfile.TemporaryDirectory(prefix='vcc-cmoc-libraries-', dir='/tmp') as folder:
for name in LIBRARIES:
source = ROOT / 'third_party/cmoc-libraries' / name
work = Path(folder) / name
shutil.copytree(source, work)
subprocess.run([str(runtime / 'bin/make'), f'-j{max(1, args.jobs)}', f'lib{name}.a'],
cwd=work, env=env, check=True)
output = subprocess.check_output([str(runtime / 'bin/make'), '--no-print-directory',
'--eval', 'vcc-list-headers:;@echo VCC_HEADERS $(LIBHEADERS)', 'vcc-list-headers'],
cwd=work, env=env, text=True)
matches = [line for line in output.splitlines() if line.startswith('VCC_HEADERS ')]
if len(matches) != 1: raise SystemExit('Cannot determine library headers: ' + name)
headers = matches[0].split()[1:]
archive = runtime / 'share/cmoc/lib' / f'lib{name}.a'
shutil.copyfile(work / f'lib{name}.a', archive)
files = {archive.relative_to(runtime).as_posix(): sha(archive)}
for header in headers:
if Path(header).name != header or not header.endswith('.h'):
raise SystemExit('Unexpected library header: ' + header)
target = runtime / 'share/cmoc/include' / header
if target.exists() and target.read_bytes() != (source / header).read_bytes():
raise SystemExit('Conflicting library header: ' + header)
shutil.copyfile(source / header, target)
files[target.relative_to(runtime).as_posix()] = sha(target)
record = json.loads((ROOT / 'third_party/manifests' / (name + '.json')).read_text())
notice = runtime / 'LICENSES' / (name.upper() + '-NOTICE.txt')
text = f"{name} {record['version']}\n\n{record['license']}\n\n"
# Keep declarations/acknowledgments from every compiled source and
# public header. Full corresponding source remains in third_party.
for file in sorted(source.glob('*')):
if not file.is_file(): continue
if file.name in ('COPYING', 'README.md'):
text += '\n--- ' + file.name + ' ---\n' + file.read_text()
elif file.suffix in ('.c', '.h'):
content = file.read_text()
if content.startswith('/*'):
notice_end = content.find('*/')
excerpt = content[:notice_end + 2] if notice_end >= 0 else ''
else:
lines = []
for line in content.splitlines():
if line.startswith('//') or not line.strip(): lines.append(line)
else: break
excerpt = '\n'.join(lines).strip()
if excerpt: text += '\n--- ' + file.name + ' ---\n' + excerpt + '\n'
notice.write_text(text)
records[name] = {'version': record['version'], 'license': record['license'],
'profile': 'coco', 'filesSHA256': files}
manifest['libraries'] = records
manifest_path.write_text(json.dumps(manifest, indent=2) + '\n')
subprocess.run([sys.executable, ROOT / 'tools/toolchain/stage-guest-sdk.py', runtime], check=True)
print('PASS: guest SDK and eight optional library archives and headers built with bundled tools')
if __name__ == '__main__': main()
+105
View File
@@ -0,0 +1,105 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Package locally built Perl, preserving separate architecture-dependent cores."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
ROOT = Path(__file__).resolve().parents[2]
VERSION = '5.44.0'
MACHO_MAGIC = {b'\xcf\xfa\xed\xfe', b'\xfe\xed\xfa\xcf', b'\xca\xfe\xba\xbe', b'\xbe\xba\xfe\xca'}
def native(path):
with path.open('rb') as stream: return stream.read(4) in MACHO_MAGIC
def stage(runtime, prefixes):
manifest_path = runtime / 'manifest.json'
manifest = json.loads(manifest_path.read_text())
if set(prefixes) != set(manifest['architectures']):
raise SystemExit('Perl builds must cover every declared runtime architecture')
helpers = {p: arches for p, arches in manifest.get('nativeHelpers', {}).items()
if not p.startswith('libexec/perl/') and p != 'bin/perl'}
target = runtime / 'libexec/perl'
if target.exists(): shutil.rmtree(target)
for arch, prefix in prefixes.items():
actual = subprocess.check_output([str(prefix / 'bin/perl'), '-e', 'print $^V'], text=True)
if actual != 'v' + VERSION: raise SystemExit('Unexpected Perl version: ' + actual)
installation = target / arch
(installation / 'bin').mkdir(parents=True)
shutil.copyfile(prefix / 'bin/perl', installation / 'bin/perl')
(installation / 'bin/perl').chmod(0o755)
# Core modules and their data/XS binaries, without SDK headers, static
# development archives, manuals, command-line maintenance tools or CPAN
# download caches. Original module notices remain in their source text.
def ignored(folder, names):
return [name for name in names if name == 'CORE' or name == 'pods'
or name.endswith(('.pod', '.a', '.h')) or name == '.packlist']
shutil.copytree(prefix / 'lib', installation / 'lib', ignore=ignored)
for path in installation.rglob('*'):
if path.is_symlink(): raise SystemExit('Unexpected symlink in Perl runtime: ' + str(path))
if path.is_file() and native(path):
slices = subprocess.check_output(['/usr/bin/lipo', '-archs', str(path)], text=True).split()
if arch not in slices: raise SystemExit('Incorrect Perl architecture: ' + str(path))
helpers[path.relative_to(runtime).as_posix()] = [arch]
env = dict(os.environ)
env.setdefault('DEVELOPER_DIR', '/Applications/Xcode.app/Contents/Developer')
with tempfile.TemporaryDirectory(prefix='vcc-perl-launcher-') as folder:
slices = []
for arch in prefixes:
binary = Path(folder) / arch
subprocess.run(['xcrun', 'clang', '-O2', '-arch', arch, '-mmacosx-version-min=14.0',
str(ROOT / 'tools/toolchain/perl-launcher.c'), '-o', str(binary)], env=env, check=True)
slices.append(binary)
launcher = runtime / 'bin/perl'
if len(slices) == 1: shutil.copyfile(slices[0], launcher)
else: subprocess.run(['/usr/bin/lipo', '-create', *map(str, slices), '-output', str(launcher)], check=True)
launcher.chmod(0o755)
helpers['bin/perl'] = list(prefixes)
# Upstream script's /usr/bin/perl shebang would bypass our bundled runtime.
# Preserve the script unchanged behind a relocatable wrapper instead.
shutil.copyfile(ROOT / 'third_party/cmoc/src/install-coco-boot-loader',
runtime / 'libexec/install-coco-boot-loader.pl')
wrapper = runtime / 'bin/install-coco-boot-loader'
wrapper.write_text('#!/bin/sh\n# SPDX-License-Identifier: GPL-3.0-or-later\n'
'set -eu\nruntime=$(CDPATH= cd -- "$(/usr/bin/dirname -- "$0")/.." && pwd -P)\n'
'exec "$runtime/bin/perl" "$runtime/libexec/install-coco-boot-loader.pl" "$@"\n')
wrapper.chmod(0o755)
notices = runtime / 'LICENSES'
for source, name in [('README', 'PERL-README.txt'), ('Copying', 'PERL-COPYING.txt'),
('Artistic', 'PERL-ARTISTIC.txt'),
('cpan/Compress-Raw-Bzip2/bzip2-src/LICENSE', 'PERL-BZIP2-LICENSE.txt')]:
shutil.copyfile(ROOT / 'third_party/perl' / source, notices / name)
manifest['nativeHelpers'] = dict(sorted(helpers.items()))
manifest['perl'] = {'version': VERSION, 'license': 'GPL-1.0-or-later OR Artistic-1.0-Perl',
'profile': 'interpreter-and-core-modules', 'architectures': list(prefixes),
'sourceManifestSHA256': hashlib.sha256((ROOT / 'third_party/manifests/perl.json').read_bytes()).hexdigest()}
manifest_path.write_text(json.dumps(manifest, indent=2) + '\n')
for arch in prefixes:
subprocess.run(['/usr/bin/arch', '-' + arch, str(runtime / 'bin/perl'), '-MGetopt::Long',
'-MFile::Spec', '-MDigest::SHA', '-e',
'use strict; use warnings; print "Bundled Perl $^V OK\\n";'], check=True)
print('PASS: staged independent Perl/core-module runtime for ' + ', '.join(prefixes))
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('runtime', type=Path)
parser.add_argument('--prefix', action='append', required=True, help='ARCH=installed-prefix (repeat per architecture)')
args = parser.parse_args()
prefixes = {}
for item in args.prefix:
arch, separator, value = item.partition('=')
if not separator or arch not in ('arm64', 'x86_64') or arch in prefixes:
parser.error('Expected one ARCH=prefix per architecture')
prefixes[arch] = Path(value).resolve()
stage(args.runtime.resolve(), prefixes)
if __name__ == '__main__': main()
+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Build an explicitly supplied, private DECB-derived driver as an optional library.
The source remains outside Git. The ROM-backed decbfile archive is unchanged.
"""
import argparse
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
from runtime_inputs import validate_private_inputs
ROOT = Path(__file__).resolve().parents[2]
def sha(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('runtime', type=Path)
parser.add_argument('--source', type=Path, required=True)
args = parser.parse_args()
runtime = args.runtime.resolve()
manifest = runtime / 'manifest.json'
record = json.loads(manifest.read_text())
validate_private_inputs(runtime, record)
cmoc = json.loads((ROOT / 'third_party/manifests/cmoc.json').read_text())
expected = cmoc['excludedFileSHA256']['src/stdlib/dskcon-standalone.c']
if sha(args.source) != expected:
parser.error('Private driver must match the reviewed CMOC source release')
header = ROOT / 'third_party/cmoc/src/stdlib/dskcon-standalone.h'
if sha(header) != cmoc['upstreamFileSHA256']['src/stdlib/dskcon-standalone.h']:
parser.error('Standalone header differs from the reviewed source')
env = dict(os.environ, PATH=str(runtime / 'bin') + ':/usr/bin:/bin',
DEVELOPER_DIR='/VCC-no-developer-tools', SDKROOT='/VCC-no-sdk')
with tempfile.TemporaryDirectory(prefix='vcc-dskcon-', dir='/tmp') as folder:
work = Path(folder)
shutil.copyfile(args.source, work / 'dskcon-standalone.c')
shutil.copyfile(header, work / header.name)
subprocess.run([str(runtime / 'bin/cmoc'), '--coco', '-O2', '-I.', '-c',
'-o', 'dskcon-standalone.o', 'dskcon-standalone.c'], cwd=work, env=env, check=True)
subprocess.run([str(runtime / 'bin/lwar'), '--create', 'libdskcon-standalone.a',
'dskcon-standalone.o'], cwd=work, env=env, check=True)
shutil.copyfile(work / 'libdskcon-standalone.a', runtime / 'share/cmoc/lib/libdskcon-standalone.a')
shutil.copyfile(header, runtime / 'share/cmoc/include/dskcon-standalone.h')
upstream_notice = args.source.read_text().split('*/', 1)[0] + '*/\n'
notice = ('Standalone CoCo floppy disk driver — optional linked library\n\n' + upstream_notice +
'\nThis library contains portions taken from Disk Extended Color BASIC (DECB).\n'
'Those portions are separate third-party code, not covered by Pierre Sarrazin\'s\n'
'public-domain dedication or VCC Plus\'s GPL license. Original rights remain\n'
'with their respective owners; this notice grants no additional rights.\n\n'
'The ROM-backed decbfile core remains a separate public-domain library.\n'
'Use -ldskcon-standalone to explicitly link this driver into a CoCo program.\n'
'Its code runs from RAM and accesses the emulated floppy controller.\n'
'It does not require Disk BASIC to remain mapped during disk operations.\n\n'
'Rights-holder inquiries or removal requests: [email protected]\n')
(runtime / 'LICENSES/DSKCON-STANDALONE-NOTICE.txt').write_text(notice)
paths = ['share/cmoc/lib/libdskcon-standalone.a', 'share/cmoc/include/dskcon-standalone.h',
'LICENSES/DSKCON-STANDALONE-NOTICE.txt']
record['privateRuntimeInputs'] = True
record['standaloneDisk'] = {
'profile': 'decb-derived-standalone', 'cmocVersion': cmoc['version'],
'license': 'public-domain-except-DECB-derived-portions', 'sourceSHA256': expected,
'filesSHA256': {p: sha(runtime / p) for p in paths},
}
validate_private_inputs(runtime, record)
manifest.write_text(json.dumps(record, indent=2) + '\n')
print('Staged optional standalone disk API; explicitly link with -ldskcon-standalone.')
if __name__ == '__main__':
main()
+295
View File
@@ -0,0 +1,295 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Audit a staged runtime and compile through Make without Apple developer tools."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
from runtime_inputs import validate_private_inputs
TOOLS = ('libexec/cmoc', 'bin/cpp', 'bin/mcpp', 'bin/make', 'bin/lwasm', 'bin/lwlink', 'bin/lwar', 'bin/writecocofile')
def check_assembly(runtime, folder):
"""Both native slices must resolve source identity and reject escaping inputs."""
folder.mkdir()
assembler = str(runtime / 'bin/lwasm')
(folder / 'part.inc').write_text(' lda #$8f\n fcb $86,$8f\n')
source = folder / 'main.asm'
source.write_text(' org $3f00\n include "part.inc"\n end $3f00\n')
command = [assembler, '--project-inputs', '--project-map=lines.tsv', '--6809', '--decb', '-o', 'first.bin', 'main.asm']
subprocess.run(command, cwd=folder, check=True)
if (folder / 'lines.tsv').read_text() != 'part.inc\t1\t\t3F00\t868F\n':
raise SystemExit('LWASM physical source map is missing or includes data')
if (folder / 'first.bin').read_bytes() != bytes.fromhex('00 0004 3f00 868f 868f ff 0000 3f00'):
raise SystemExit('LWASM project image differs')
outside = folder.with_suffix('.inc')
outside.write_text(' nop\n')
(folder / 'linked.inc').symlink_to(outside)
for directive, path in [('include', str(outside)), ('include', 'linked.inc'), ('includebin', '../' + outside.name)]:
source.write_text(f" org $3f00\n {directive} '{path}'\n end $3f00\n")
failure = subprocess.run(command, cwd=folder, capture_output=True, text=True)
if failure.returncode == 0 or 'leaves the project snapshot' not in failure.stderr:
raise SystemExit('Unexpected LWASM result for escaping ' + directive + ': ' + failure.stderr)
def check_disk_allocation(runtime, folder):
"""The explicit before-dir option must match the existing forward allocator."""
folder.mkdir()
tool = str(runtime / 'bin/writecocofile')
payload = folder / 'DATA.DAT'
payload.write_bytes(bytes(range(256)) * (35 * 9)) # 35 granules: spills above track 17.
images = []
for name, options, first in [('default', [], 0), ('before', ['--allocate-before-dir'], 0),
('after', ['--allocate-after-dir'], 34),
('last-option', ['--allocate-after-dir', '--allocate-before-dir'], 0)]:
image = folder / (name + '.dsk')
image.write_bytes(b'\xff' * (35 * 18 * 256))
subprocess.run([tool, *options, str(image), str(payload)], check=True, stdout=subprocess.DEVNULL)
content = image.read_bytes()
entry = 17 * 18 * 256 + 2 * 256
if content[entry + 13] != first:
raise SystemExit('Incorrect disk allocation start: ' + name)
restored = subprocess.check_output([tool, '--stdout', str(image), 'DATA.DAT'])
if restored != payload.read_bytes():
raise SystemExit('Disk allocation readback mismatch: ' + name)
images.append(content)
if images[0] != images[1] or images[0] != images[3]:
raise SystemExit('Before-directory option changed default allocation semantics')
def check_guest_example(runtime, env, folder, project_name, payloads):
"""Build an editable example and compare its guest disk files with the build outputs."""
source = Path(__file__).resolve().parents[2] / "examples/cmoc" / project_name
shutil.copytree(source, folder, ignore=shutil.ignore_patterns("obj", "generated", "*.bin", "*.BIN", "*.dsk", "*.DSK", "*.map", "*.link"))
subprocess.run([runtime / "bin/make", "-B", "disk"], cwd=folder, env=env, check=True)
for disk_name, output, guest_name in payloads:
expected = (folder / output).read_bytes()
extracted = subprocess.check_output([runtime / "bin/writecocofile", "--stdout", disk_name, guest_name],
cwd=folder, env=env)
if not expected or extracted != expected:
raise SystemExit(f"{project_name}: {guest_name} differs from {output}")
subprocess.run([runtime / "bin/make", "-q", "build"], cwd=folder, env=env, check=True)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('runtime', type=Path)
args = parser.parse_args()
runtime = args.runtime.resolve()
record = json.loads((runtime / 'manifest.json').read_text())
validate_private_inputs(runtime, record)
disk = record.get('decbfile')
if disk:
if disk.get('profile') != 'rom-backed-core' or disk.get('standaloneDriverIncluded') is not False:
raise SystemExit('Unsupported disk library profile')
for relative, key in [('share/cmoc/lib/libdecbfile.a', 'archiveSHA256'), ('share/cmoc/include/decbfile.h', 'headerSHA256')]:
if hashlib.sha256((runtime / relative).read_bytes()).hexdigest() != disk[key]:
raise SystemExit('Disk library manifest hash mismatch: ' + relative)
helpers = {relative: record['architectures'] for relative in TOOLS}
helpers.update(record.get('nativeHelpers', {}))
for library in record.get('libraries', {}).values():
for relative, expected in library['filesSHA256'].items():
if hashlib.sha256((runtime / relative).read_bytes()).hexdigest() != expected:
raise SystemExit('Library manifest hash mismatch: ' + relative)
for relative, architectures in helpers.items():
binary = runtime / relative
info = subprocess.check_output(['/usr/bin/lipo', '-archs', str(binary)], text=True).split()
if not set(architectures).issubset(info): raise SystemExit(f'Missing architecture: {relative}')
links = subprocess.check_output(['/usr/bin/otool', '-L', str(binary)], text=True)
for line in links.splitlines():
if line.startswith('\t') and not line.strip().startswith(('/usr/lib/', '/System/Library/')):
raise SystemExit(f'Non-system runtime dependency: {relative}: {line}')
with tempfile.TemporaryDirectory(prefix='VCC runtime #$ quote" relocation ') as folder:
moved = Path(folder) / 'VCC Plus.app/Contents/Resources/Toolchain'
shutil.copytree(runtime, moved)
project = Path(folder) / 'C project with spaces'; project.mkdir()
(project / 'main.c').write_text('#include <cmoc.h>\n#define JOIN(a,b) a##b\n#define STRING(x) #x\nint main(void) { unsigned JOIN(co,unt)=7; printf(STRING(HELLO) " %u\\n", count); return 0; }\n')
if disk:
(project / 'disk.c').write_text('''#include <decbfile.h>
DECBDrive drives[1]; DECBFile file; byte written[256], readback[256];
int main(void) {
initCoCoSupport();
if (decb_init(drives, 1) || decb_registerDrive(0)) return 1;
memset(written, 42, 256);
if (decb_createSectorFile(&file, 0, "ROUND.DAT", DECB_TYPE_BASIC_DATA, DECB_FORMAT_BINARY)) return 2;
if (decb_writeSector(&file, written, 0) || decb_setNumBytesUsedInLastSector(&file, 256) || decb_closeSectorFile(&file)) return 3;
if (decb_openSectorFile(&file, 0, "ROUND.DAT") || decb_readSector(&file, readback, 0) || decb_closeSectorFile(&file)) return 4;
if (decb_rename(0, "ROUND.DAT", "RESULT.DAT") || decb_kill(0, "RESULT.DAT") || decb_shutdown()) return 5;
return memcmp(written, readback, 256) != 0;
}
''')
def compile_disk(toolchain, tool_env):
if disk:
subprocess.run([str(toolchain / 'bin/cmoc'), '--coco', '--intermediate', '-O0',
'-o', 'disk.bin', 'disk.c', '-ldecbfile'], cwd=project, env=tool_env, check=True)
image = (project / 'disk.bin').read_bytes()
if len(image) < 10 or image[0] != 0 or image[-5:-2] != b'\xff\0\0':
raise SystemExit('Invalid linked disk example binary')
if record.get('standaloneDisk'):
(project / 'standalone.c').write_text('#include <dskcon-standalone.h>\nint main(void) { unsigned long saved = dskcon_init(dskcon_nmiService); DCOPC=2; DCDRV=0; DCTRK=17; DCSEC=3; DCBPT=(void *)0x500; dskcon_processSector(); dskcon_irqService(); dskcon_shutdown(saved); return DCSTA; }\n')
subprocess.run([str(toolchain / 'bin/cmoc'), '--coco', '-o', 'standalone.bin',
'standalone.c', '-ldskcon-standalone'], cwd=project, env=tool_env, check=True)
(project / 'Makefile').write_text('all: main.bin\nmain.bin: main.c\n\tcmoc --coco --intermediate -O0 -o main.bin main.c\n')
env = dict(os.environ, PATH=str(moved / 'bin') + ':/usr/bin:/bin',
DEVELOPER_DIR='/VCC-validation-no-developer-tools', SDKROOT='/VCC-validation-no-sdk', LC_ALL='C')
for key in ('PERL5LIB', 'PERLLIB', 'PERL5OPT'): env.pop(key, None)
def check_perl(toolchain, tool_env):
if not record.get('perl'): return
result = subprocess.check_output([str(toolchain / 'bin/perl'), '-MGetopt::Long',
'-MDigest::SHA', '-e', 'use strict; use warnings; print $^X, \"\\n\", Digest::SHA::sha256_hex(\"VCC\");'],
cwd=project, env=tool_env, text=True)
if str(toolchain) not in result or hashlib.sha256(b'VCC').hexdigest() not in result:
raise SystemExit('Perl did not use the relocated bundled interpreter and modules')
subprocess.run([str(toolchain / 'bin/install-coco-boot-loader'), '--help'],
cwd=project, env=tool_env, check=True, stdout=subprocess.DEVNULL)
def check_dependencies(toolchain, tool_env, name):
dependency_project = Path(folder) / name
dependency_project.mkdir()
header = dependency_project / 'headers #$ spaces' / 'value.h'
header.parent.mkdir()
header.write_text('#define VALUE 42\n')
(dependency_project / 'main.c').write_text('#include <cmoc.h>\n#include "headers #$ spaces/value.h"\nint main(void) { return VALUE; }\n')
# Include before the .d exists: Make must generate/reparse it, not
# merely tolerate a dependency file that has never been consumed.
# --deps-only and --deps use separate CMOC marker readers.
(dependency_project / 'child').mkdir()
(dependency_project / 'child/Makefile').write_text('stamp:\n\tprintf child > stamp\n')
(dependency_project / 'Makefile').write_text(
'all: main.bin child/stamp\n'
'child/stamp:\n\t$(MAKE) -C child\n'
'main.bin: main.o\n\tcmoc --coco -o $@ $<\n'
'main.o: main.c\n\tcmoc --coco --deps -c -o $@ $<\n'
'main.d: main.c\n\tcmoc --coco --deps-only main.c\n'
'include main.d\n')
# Same recursion-safe override used by the app: Make's default MAKE
# is its absolute executable path, unsafe unquoted inside recipes.
command = [str(toolchain / 'bin/make'), 'MAKE=make', '--no-builtin-rules']
def make(*options):
subprocess.run(command + list(options), cwd=dependency_project, env=tool_env, check=True)
make()
make('-q')
first = (dependency_project / 'main.bin').read_bytes()
# A changed header must invalidate both the generated dependency
# file and compiled object; no-op rebuilds must remain no-ops.
header.write_text('#define VALUE 43\n')
make()
make('-q')
if first == (dependency_project / 'main.bin').read_bytes():
raise SystemExit('Changed dependency did not rebuild the executable')
dependency_text = (dependency_project / 'main.d').read_text()
if 'VCC\\ Plus.app' not in dependency_text and 'Toolchain' not in dependency_text:
raise SystemExit('Dependency test did not exercise relocated SDK headers')
if '\\#$$' not in dependency_text:
raise SystemExit('Make dependency special characters were not escaped')
check_disk_allocation(moved, Path(folder) / "Disk allocation")
check_dependencies(moved, env, 'Dependency project')
check_perl(moved, env)
# A deliberately unusable developer directory catches accidental xcrun
# or Apple compiler use even on the development machine.
subprocess.run([str(moved / 'bin/make'), '--no-builtin-rules'], cwd=project, env=env, check=True)
compile_disk(moved, env)
for name in ('main.bin', 'main.s', 'main.lst', 'main.map', 'main.link'):
if not (project / name).is_file(): raise SystemExit('Missing build product: ' + name)
binary = (project / 'main.bin').read_bytes()
if len(binary) < 10 or binary[0] != 0 or binary[-5:-2] != b'\xff\0\0':
raise SystemExit('Invalid DECB binary')
# Thin copies force the entire compiler/preprocessor/assembler/linker
# chain onto each architecture, not just a --version smoke test.
for architecture in record['architectures']:
thin = Path(folder) / (architecture + ' Toolchain')
shutil.copytree(runtime, thin)
for relative, architectures in helpers.items():
if architecture not in architectures: continue
binary = thin / relative
temporary = binary.with_name(binary.name + '.thin')
slices = subprocess.check_output(['/usr/bin/lipo', '-archs', str(binary)], text=True).split()
if len(slices) > 1:
subprocess.run(['/usr/bin/lipo', str(binary), '-thin', architecture,
'-output', str(temporary)], check=True)
temporary.replace(binary)
binary.chmod(0o755)
subprocess.run(['/usr/bin/codesign', '--force', '--sign', '-', '--timestamp=none',
str(binary)], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
arch_env = dict(env, PATH=str(thin / 'bin') + ':/usr/bin:/bin')
subprocess.run([str(thin / 'bin/make'), '--no-builtin-rules', '-B'],
cwd=project, env=arch_env, check=True)
if {"ssc", "orch90", "vcccompat"}.issubset(record.get("libraries", {})):
check_guest_example(thin, arch_env, Path(folder) / (architecture + " audio SDK"),
"TalkingPlanetLander", [("LANDER.dsk", "LANDER.bin", "LANDER.BIN")])
if record["libraries"]["vcccompat"].get("reentrantTokenizer"):
check_guest_example(thin, arch_env, Path(folder) / (architecture + " streams SDK"),
"PlanetSurvey", [("SURVEY.dsk", "SURVEY.bin", "SURVEY.BIN"),
("SURVEY.dsk", "generated/PLANETS.TXT", "PLANETS.TXT")])
if "sdc" in record.get("libraries", {}):
check_guest_example(thin, arch_env, Path(folder) / (architecture + " SDC SDK"),
"PlanetExpedition", [
("EXPED/EXPLORE.DSK", "EXPLORE.BIN", "EXPLORE.BIN"),
("EXPED/EARTH.DSK", "generated/earth/LANDING.TXT", "LANDING.TXT"),
("EXPED/MARS.DSK", "generated/mars/LANDING.TXT", "LANDING.TXT")])
libraries = record.get("libraries", {})
if (record.get("decbfile") and {"bank", "gime", "input", "bcontrol", "hirestxt"} <= libraries.keys()
and libraries.get("orch90", {}).get("backgroundPlayback")
and libraries.get("ssc", {}).get("storedSpeechAndEffects")
and libraries.get("vcccompat", {}).get("diskFileManagement")):
check_guest_example(thin, arch_env, Path(folder) / (architecture + " mission SDK"),
"MissionRecorder", [("RECORDER.dsk", "RECORDER.bin", "RECORDER.BIN")])
manual_examples = (
("vcccompat", "diskWriteStreams", "fieldlog.c", ["decbfile"]),
("vcccompat", "integerConversions", "atlas.c", ["decbfile"]),
("vcccompat", "diskStreamClearError", "returntrip.c", ["decbfile"]),
("vcccompat", "printerFormattedOutput", "flightreport.c", []),
("vcccompat", "cassetteTextFiles", "flightrecorder.c", []),
("vcccompat", "diskFileManagement", "atlasbackup.c", ["decbfile"]),
("vcccompat", "fixedDecimal", "descent.c", []),
("orch90", "backgroundPlayback", "flyby.c", ["input", "bcontrol"]),
("ssc", "storedSpeechAndEffects", "announcer.c", ["input", "bcontrol"]),
)
for library, feature, source, dependencies in manual_examples:
if record.get("libraries", {}).get(library, {}).get(feature):
example = Path(__file__).resolve().parents[2] / "examples/cmoc/manual" / source
shutil.copyfile(example, project / source)
link_flags = ["-l" + name for name in [library, *dependencies]]
subprocess.run([thin / "bin/cmoc", "--coco", "-O2", "-Werror", "-o",
example.stem + ".bin", source, *link_flags], cwd=project,
env=dict(arch_env, VCC_CMOC_COMPAT="1" if library == "vcccompat" else "0"), check=True)
if record.get("libraries", {}).get("vcccompat", {}).get("boundedHeap"):
example = Path(__file__).resolve().parents[2] / "examples/cmoc/manual/crew.c"
shutil.copyfile(example, project / "crew.c")
subprocess.run([thin / "bin/cmoc", "--coco", "-O2", "-Werror", "-o", "crew.bin",
"crew.c", "-lvcccompat", "-lwydealloc"],
cwd=project, env=dict(arch_env, VCC_CMOC_COMPAT="1"), check=True)
if "gime" in record.get("libraries", {}):
example = Path(__file__).resolve().parents[2] / "examples/cmoc/manual/lander.c"
shutil.copyfile(example, project / "lander.c")
subprocess.run([thin / "bin/cmoc", "--coco", "-O2", "-Werror", "-o", "lander.bin",
"lander.c", "-lgime", "-lbgraph", "-lbcontrol"],
cwd=project, env=arch_env, check=True)
if "input" in record.get("libraries", {}):
example = Path(__file__).resolve().parents[2] / "examples/cmoc/manual/probe.c"
shutil.copyfile(example, project / "probe.c")
subprocess.run([thin / "bin/cmoc", "--coco", "-O2", "-Werror", "-o", "probe.bin",
"probe.c", "-lgime", "-linput", "-lbcontrol"],
cwd=project, env=arch_env, check=True)
if "bank" in record.get("libraries", {}):
example = Path(__file__).resolve().parents[2] / "examples/cmoc/manual/ridge.c"
shutil.copyfile(example, project / "ridge.c")
subprocess.run([thin / "bin/cmoc", "--coco", "-O2", "-Werror", "-o", "ridge.bin",
"ridge.c", "-lbank", "-lgime", "-lhirestxt"],
cwd=project, env=arch_env, check=True)
compile_disk(thin, arch_env)
check_perl(thin, arch_env)
check_assembly(thin, Path(folder) / (architecture + " assembly"))
check_disk_allocation(thin, Path(folder) / (architecture + " disk allocation"))
check_dependencies(thin, arch_env, architecture + " dependency project")
# Preprocessor errors must stop Make and retain source-line diagnostics.
(project / 'main.c').write_text('#line 81 "mapped.c"\n#error VCC_EXPECTED_PREPROCESSOR_FAILURE\n')
failure = subprocess.run([str(moved / 'bin/make'), '-B'], cwd=project, env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
if failure.returncode == 0 or 'VCC_EXPECTED_PREPROCESSOR_FAILURE' not in failure.stdout or '81' not in failure.stdout:
raise SystemExit('Preprocessor errors/line directives were not preserved: ' + failure.stdout)
print('PASS: architectures, system-only libraries, relocated space-containing bundle, both complete architecture build chains, preprocessor errors, Make dependency regeneration with spaces/quotes/#/$, optional ROM-backed/standalone disk API linking, bundled Perl/core modules, disk allocation and BIN without developer tools')
if __name__ == '__main__': main()
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
"""Verify the checked-in source snapshots against their reviewed import manifests."""
from pathlib import Path
import hashlib
import json
ROOT = Path(__file__).resolve().parents[2]
def main():
total = 0
for manifest in sorted((ROOT / 'third_party/manifests').glob('*.json')):
record = json.loads(manifest.read_text())
directory = ROOT / record['directory']
actual = {p.relative_to(directory).as_posix(): hashlib.sha256(p.read_bytes()).hexdigest()
for p in directory.rglob('*') if p.is_file()}
expected = record['vendoredFileSHA256']
if actual != expected:
changed = sorted(k for k in actual.keys() | expected.keys() if actual.get(k) != expected.get(k))
raise SystemExit(f"{record['project']}: unexpected files or content: {changed}")
if any((directory / p).exists() for p in record['excludedFiles']):
raise SystemExit(f"{record['project']}: excluded source was reintroduced")
print(f"PASS {record['project']} {record['version']}: {len(actual)} files")
total += len(actual)
print(f'PASS: {total} reviewed source files; no downloaded binaries or ROMs required')
if __name__ == '__main__':
main()