xref: /openbmc/qemu/tests/lcitool/refresh (revision de799beb)
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 subprocess
17
18from pathlib import Path
19
20if len(sys.argv) != 1:
21    print("syntax: %s" % sys.argv[0], file=sys.stderr)
22    sys.exit(1)
23
24self_dir = Path(__file__).parent
25src_dir = self_dir.parent.parent
26dockerfiles_dir = Path(src_dir, "tests", "docker", "dockerfiles")
27
28lcitool_path = Path(self_dir, "libvirt-ci", "lcitool")
29
30lcitool_cmd = [lcitool_path, "--data-dir", self_dir]
31
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
43
44def generate(filename, cmd, trailer):
45    print("Generate %s" % filename)
46    lcitool = subprocess.run(cmd, capture_output=True)
47
48    if lcitool.returncode != 0:
49        raise Exception("Failed to generate %s: %s" % (filename, lcitool.stderr))
50
51    content = lcitool.stdout.decode("utf8")
52    if trailer is not None:
53        content += trailer
54    atomic_write(filename, content)
55
56
57def generate_dockerfile(host, target, cross=None, trailer=None):
58    filename = Path(src_dir, "tests", "docker", "dockerfiles", host + ".docker")
59    cmd = lcitool_cmd + ["dockerfile"]
60    if cross is not None:
61        cmd.extend(["--cross", cross])
62    cmd.extend([target, "qemu"])
63    generate(filename, cmd, trailer)
64
65
66def generate_cirrus(target, trailer=None):
67    filename = Path(src_dir, ".gitlab-ci.d", "cirrus", target + ".vars")
68    cmd = lcitool_cmd + ["variables", target, "qemu"]
69    generate(filename, cmd, trailer)
70
71
72ubuntu2004_tsanhack = [
73    "# Apply patch https://reviews.llvm.org/D75820\n",
74    "# This is required for TSan in clang-10 to compile with QEMU.\n",
75    "RUN sed -i 's/^const/static const/g' /usr/lib/llvm-10/lib/clang/10.0.0/include/sanitizer/tsan_interface.h\n"
76]
77
78
79# Netmap still needs to be manually built as it is yet to be packaged
80# into a distro. We also add cscope and gtags which are used in the CI
81# test
82debian11_extras = [
83    "# netmap/cscope/global\n",
84    "RUN DEBIAN_FRONTEND=noninteractive eatmydata \\\n",
85    "  apt install -y --no-install-recommends \\\n",
86    "  cscope\\\n",
87    "  global\\\n",
88    "  linux-headers-amd64\n",
89    "RUN git clone https://github.com/luigirizzo/netmap.git /usr/src/netmap\n",
90    "RUN cd /usr/src/netmap && git checkout v11.3\n",
91    "RUN cd /usr/src/netmap/LINUX && ./configure --no-drivers --no-apps --kernel-dir=$(ls -d /usr/src/linux-headers-*-amd64) && make install\n",
92    "ENV QEMU_CONFIGURE_OPTS --enable-netmap\n"
93]
94
95
96def debian_cross_build(prefix, targets):
97    conf = "ENV QEMU_CONFIGURE_OPTS --cross-prefix=%s\n" % (prefix)
98    targets = "ENV DEF_TARGET_LIST %s\n" % (targets)
99    return "".join([conf, targets])
100
101#
102# Update all the various build configurations.
103# Please keep each group sorted alphabetically for easy reading.
104#
105
106try:
107    #
108    # Standard native builds
109    #
110    generate_dockerfile("alpine", "alpine-edge")
111    generate_dockerfile("centos8", "centos-stream-8")
112    generate_dockerfile("debian-amd64", "debian-11",
113                        trailer="".join(debian11_extras))
114    generate_dockerfile("fedora", "fedora-35")
115    generate_dockerfile("opensuse-leap", "opensuse-leap-152")
116    generate_dockerfile("ubuntu2004", "ubuntu-2004",
117                        trailer="".join(ubuntu2004_tsanhack))
118
119    #
120    # Cross compiling builds
121    #
122    generate_dockerfile("debian-arm64-cross", "debian-11",
123                        cross="aarch64",
124                        trailer=debian_cross_build("aarch64-linux-gnu-",
125                                                   "aarch64-softmmu,aarch64-linux-user"))
126
127    generate_dockerfile("debian-armel-cross", "debian-11",
128                        cross="armv6l",
129                        trailer=debian_cross_build("arm-linux-gnueabi-",
130                                                   "arm-softmmu,arm-linux-user,armeb-linux-user"))
131
132    generate_dockerfile("debian-armhf-cross", "debian-11",
133                        cross="armv7l",
134                        trailer=debian_cross_build("arm-linux-gnueabihf-",
135                                                   "arm-softmmu,arm-linux-user"))
136
137    generate_dockerfile("debian-mips64el-cross", "debian-11",
138                        cross="mips64el",
139                        trailer=debian_cross_build("mips64el-linux-gnuabi64-",
140                                                  "mips64el-softmmu,mips64el-linux-user"))
141
142    generate_dockerfile("debian-mipsel-cross", "debian-11",
143                        cross="mipsel",
144                        trailer=debian_cross_build("mipsel-linux-gnu-",
145                                                   "mipsel-softmmu,mipsel-linux-user"))
146
147    generate_dockerfile("debian-ppc64el-cross", "debian-11",
148                        cross="ppc64le",
149                        trailer=debian_cross_build("powerpc64le-linux-gnu-",
150                                                   "ppc64-softmmu,ppc64-linux-user"))
151
152    generate_dockerfile("debian-s390x-cross", "debian-11",
153                        cross="s390x",
154                        trailer=debian_cross_build("s390x-linux-gnu-",
155                                                   "s390x-softmmu,s390x-linux-user"))
156
157    #
158    # Cirrus packages lists for GitLab
159    #
160    generate_cirrus("freebsd-12")
161    generate_cirrus("freebsd-13")
162    generate_cirrus("macos-11")
163
164    sys.exit(0)
165except Exception as ex:
166    print(str(ex), file=sys.stderr)
167    sys.exit(1)
168