Package workstation tools, reuse emulator sessions, and derive build versions
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import argparse
|
||||
import io
|
||||
import json
|
||||
import shlex
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -12,6 +13,7 @@ import uuid
|
||||
|
||||
project = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(project/'tools'))
|
||||
from fds_version import validate
|
||||
from image_formats import digest, gpt, LINUX_FILESYSTEM, NAMESPACE
|
||||
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
@@ -21,6 +23,8 @@ parser.add_argument('--output-directory', type=Path)
|
||||
args = parser.parse_args()
|
||||
rootfs = args.rootfs.resolve(strict=True)
|
||||
with tarfile.open(rootfs) as archive:
|
||||
identity = dict(line.split('=', 1) for line in shlex.split(archive.extractfile('usr/lib/os-release').read().decode(), comments=True))
|
||||
image_version = validate(identity['VERSION_ID'])
|
||||
embedded = archive.extractfile('usr/share/fds/image-profile').read(64).decode().strip()
|
||||
try:
|
||||
root = archive.getmember('.')
|
||||
@@ -34,7 +38,7 @@ args.profile = embedded
|
||||
work = args.output_directory or Path(tempfile.mkdtemp(prefix='system-build.', dir=project/'out'))
|
||||
if not work.is_dir() or any(work.iterdir()): parser.error('output directory must exist and be empty')
|
||||
epoch = int(subprocess.check_output(['git', '-C', str(project/'vendor/void-packages'), 'show', '-s', '--format=%ct', 'HEAD']))
|
||||
manifest = f'''format = 1\n[cartridge]\nid = "fds.system.{args.profile}"\nname = "FDS/OS {args.profile.upper()}"\nclass = "system"\nversion = "0.1.0"\n[media]\nwritable = false\n'''.encode()
|
||||
manifest = f'''format = 1\n[cartridge]\nid = "fds.system.{args.profile}"\nname = "FDS/OS {args.profile.upper()}"\nclass = "system"\nversion = "{image_version}"\n[media]\nwritable = false\n'''.encode()
|
||||
with tarfile.open(rootfs) as source, tarfile.open(work/'system.tar', 'w', format=tarfile.PAX_FORMAT) as output:
|
||||
for member in source:
|
||||
if member.name in ('FDS', 'FDS/CARTRIDGE.TOML'): continue
|
||||
@@ -57,6 +61,7 @@ layout = gpt(work/'system.img', [('FDS_SYSTEM', LINUX_FILESYSTEM, work/'system.e
|
||||
layout['rootfs_sha256'] = digest(rootfs)
|
||||
layout['image_sha256'] = digest(work/'system.img')
|
||||
layout['profile'] = args.profile
|
||||
layout['version'] = image_version
|
||||
(work/'layout.json').write_text(json.dumps(layout, indent=2)+'\n')
|
||||
# An independent implementation checks the actual on-disk partition table.
|
||||
observed = json.loads(subprocess.check_output(['sfdisk', '--json', str(work/'system.img')]))['partitiontable']
|
||||
|
||||
Reference in New Issue
Block a user