debian-forge/tools/gen-stage-test-diff
Michael Vogt d801ef3958 tests: run osbuild as a python module in gen-stage-test-diff
Instead of running osbuild as a binary use `python3 -m osbuild`
(just like in `test/test.py:compile()`) so that it will use
osbuild fromgit and can be run from a checkout without the need
for an installed osbuild.
2023-11-14 20:34:50 +01:00

108 lines
2.7 KiB
Python
Executable file

#!/usr/bin/env python3
import argparse
import contextlib
import os
import subprocess
import tempfile
def run_osbuild(output_directory, store, cache_max_size, libdir, manifest):
args = [
"python3", "-m", "osbuild",
"--export",
"tree",
"--output-directory",
output_directory,
"--store",
store,
"--cache-max-size",
str(cache_max_size),
"--checkpoint",
"tree",
"--checkpoint",
"build",
]
if libdir:
args += ["--libdir", libdir]
args += [manifest]
try:
subprocess.run(
args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
encoding="utf-8",
check=True,
)
except subprocess.CalledProcessError as err:
raise RuntimeError(
f"osbuild crashed when building {manifest}:\n\nstdout:\n{err.stdout}\n\nstderr:\n{err.stderr}"
)
epilog = """
example:
sudo tools/gen-stage-test-diff \\
--store ~/osbuild-store \\
--libdir . \\
test/data/stages/zstd
"""
def main():
parser = argparse.ArgumentParser(
description="Generator for diff.json files of stage tests",
epilog=epilog,
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"--store",
type=str,
help="Specify the osbuild store",
)
parser.add_argument(
"--cache-max-size", type=int, help="Specify the osbuild max cache size",
default=1024 * 1024 * 1024,
)
parser.add_argument("--libdir", type=str, help="Specify the osbuild max cache size")
parser.add_argument("stage_test", type=str, help="Specify the stage test")
args = parser.parse_args()
with contextlib.ExitStack() as stack:
a = stack.enter_context(tempfile.TemporaryDirectory(dir="/var/tmp"))
b = stack.enter_context(tempfile.TemporaryDirectory(dir="/var/tmp"))
store = args.store
if not store:
store = stack.enter_context(tempfile.TemporaryDirectory(dir="/var/tmp"))
run_osbuild(
a,
store,
args.cache_max_size,
args.libdir,
os.path.join(args.stage_test, "a.json"),
)
run_osbuild(
b,
store,
args.cache_max_size,
args.libdir,
os.path.join(args.stage_test, "b.json"),
)
subprocess.run(
[
os.path.join(os.path.dirname(os.path.abspath(__file__)), "tree-diff"),
os.path.join(a, "tree"),
os.path.join(b, "tree"),
],
check=True,
)
if __name__ == "__main__":
main()