xref: /openbmc/qemu/tests/lcitool/refresh (revision 9c4888c9)
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
68ubuntu1804_skipssh = [
69   "# https://bugs.launchpad.net/qemu/+bug/1838763\n",
70   "ENV QEMU_CONFIGURE_OPTS --disable-libssh\n"
71]
72
73ubuntu2004_tsanhack = [
74   "# Apply patch https://reviews.llvm.org/D75820\n",
75   "# This is required for TSan in clang-10 to compile with QEMU.\n",
76   "RUN sed -i 's/^const/static const/g' /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h\n"
77]
78
79def debian_cross_build(prefix, targets):
80   conf = "ENV QEMU_CONFIGURE_OPTS --cross-prefix=%s\n" % (prefix)
81   targets = "ENV DEF_TARGET_LIST %s\n" % (targets)
82   return "".join([conf, targets])
83
84
85try:
86   generate_dockerfile("centos8", "centos-stream-8")
87   generate_dockerfile("fedora", "fedora-35")
88   generate_dockerfile("ubuntu1804", "ubuntu-1804",
89                       trailer="".join(ubuntu1804_skipssh))
90   generate_dockerfile("ubuntu2004", "ubuntu-2004",
91                       trailer="".join(ubuntu2004_tsanhack))
92   generate_dockerfile("opensuse-leap", "opensuse-leap-152")
93   generate_dockerfile("alpine", "alpine-edge")
94
95   generate_dockerfile("debian-arm64-cross", "debian-11",
96                       cross="aarch64",
97                       trailer=debian_cross_build("aarch64-linux-gnu-",
98                                                  "aarch64-softmmu,aarch64-linux-user"))
99
100   generate_dockerfile("debian-s390x-cross", "debian-11",
101                       cross="s390x",
102                       trailer=debian_cross_build("s390x-linux-gnu-",
103                                                  "s390x-softmmu,s390x-linux-user"))
104
105   generate_cirrus("freebsd-12")
106   generate_cirrus("freebsd-13")
107   generate_cirrus("macos-11")
108
109   sys.exit(0)
110except Exception as ex:
111   print(str(ex), file=sys.stderr)
112   sys.exit(1)
113