xref: /openbmc/qemu/tests/lcitool/refresh (revision d6cd3ae0)
1#!/usr/bin/env python3
2#
3# Re-generate container recipes
4#
5# This script uses the "lcitool" available from
6#
7#   https://gitlab.com/libvirt/libvirt-ci
8#
9# Copyright (c) 2020 Red Hat Inc.
10#
11# This work is licensed under the terms of the GNU GPL, version 2
12# or (at your option) any later version. See the COPYING file in
13# the top-level directory.
14
15import sys
16import os
17import subprocess
18
19from pathlib import Path
20
21if len(sys.argv) != 1:
22   print("syntax: %s" % sys.argv[0], file=sys.stderr)
23   sys.exit(1)
24
25self_dir = Path(__file__).parent
26src_dir = self_dir.parent.parent
27dockerfiles_dir = Path(src_dir, "tests", "docker", "dockerfiles")
28
29lcitool_path = Path(self_dir, "libvirt-ci", "lcitool")
30
31lcitool_cmd = [lcitool_path, "--data-dir", self_dir]
32
33def atomic_write(filename, content):
34   tmp = filename.with_suffix(filename.suffix + ".tmp")
35   try:
36      with tmp.open("w") as fp:
37         print(content, file=fp, end="")
38         tmp.rename(filename)
39   except Exception as ex:
40      tmp.unlink()
41      raise
42
43def generate(filename, cmd, trailer):
44   print("Generate %s" % filename)
45   lcitool=subprocess.run(cmd, capture_output=True)
46
47   if lcitool.returncode != 0:
48      raise Exception("Failed to generate %s: %s" % (filename, lcitool.stderr))
49
50   content = lcitool.stdout.decode("utf8")
51   if trailer is not None:
52      content += trailer
53   atomic_write(filename, content)
54
55def generate_dockerfile(host, target, cross=None, trailer=None):
56   filename = Path(src_dir, "tests", "docker", "dockerfiles", host + ".docker")
57   cmd = lcitool_cmd + ["dockerfile"]
58   if cross is not None:
59      cmd.extend(["--cross", cross])
60   cmd.extend([target, "qemu"])
61   generate(filename, cmd, trailer)
62
63def generate_cirrus(target, trailer=None):
64   filename = Path(src_dir, ".gitlab-ci.d", "cirrus", target + ".vars")
65   cmd = lcitool_cmd + ["variables", target, "qemu"]
66   generate(filename, cmd, trailer)
67
68ubuntu2004_tsanhack = [
69   "# Apply patch https://reviews.llvm.org/D75820\n",
70   "# This is required for TSan in clang-10 to compile with QEMU.\n",
71   "RUN sed -i 's/^const/static const/g' /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h\n"
72]
73
74def debian_cross_build(prefix, targets):
75   conf = "ENV QEMU_CONFIGURE_OPTS --cross-prefix=%s\n" % (prefix)
76   targets = "ENV DEF_TARGET_LIST %s\n" % (targets)
77   return "".join([conf, targets])
78
79
80try:
81   generate_dockerfile("centos8", "centos-stream-8")
82   generate_dockerfile("fedora", "fedora-35")
83   generate_dockerfile("ubuntu2004", "ubuntu-2004",
84                       trailer="".join(ubuntu2004_tsanhack))
85   generate_dockerfile("opensuse-leap", "opensuse-leap-152")
86   generate_dockerfile("alpine", "alpine-edge")
87
88   generate_dockerfile("debian-arm64-cross", "debian-11",
89                       cross="aarch64",
90                       trailer=debian_cross_build("aarch64-linux-gnu-",
91                                                  "aarch64-softmmu,aarch64-linux-user"))
92
93   generate_dockerfile("debian-s390x-cross", "debian-11",
94                       cross="s390x",
95                       trailer=debian_cross_build("s390x-linux-gnu-",
96                                                  "s390x-softmmu,s390x-linux-user"))
97
98   generate_cirrus("freebsd-12")
99   generate_cirrus("freebsd-13")
100   generate_cirrus("macos-11")
101
102   sys.exit(0)
103except Exception as ex:
104   print(str(ex), file=sys.stderr)
105   sys.exit(1)
106