#!/usr/bin/env python3 import hashlib import os import pathlib import shutil import struct import subprocess import sys import tempfile binary = str(pathlib.Path(sys.argv[1]).resolve()) compiler = shutil.which(os.environ.get("FIXTURE_CC", "cc")) or shutil.which("gcc") def call(*args, status=0): result = subprocess.run([binary, *map(str, args)], capture_output=True, text=True) assert result.returncode == status, (args, result.returncode, result.stdout, result.stderr) return result.stdout def pack_snap(source, image, offset=8): """a snap is a SquashFS image behind a header of its offset and its size""" filesystem = image.with_suffix(".squashfs") subprocess.run(["mksquashfs", str(source), str(filesystem), "-noappend", "-quiet"], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) body = filesystem.read_bytes() image.write_bytes(struct.pack("