79 lines
4.0 KiB
Python
79 lines
4.0 KiB
Python
#!/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()
|