]> git.proxmox.com Git - mirror_qemu.git/blame - tests/lcitool/refresh
Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging
[mirror_qemu.git] / tests / lcitool / refresh
CommitLineData
04cca669 1#!/usr/bin/env python3
4ebb040f
DB
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
4ebb040f
DB
16import subprocess
17
18from pathlib import Path
19
20if len(sys.argv) != 1:
06885cf9
AB
21 print("syntax: %s" % sys.argv[0], file=sys.stderr)
22 sys.exit(1)
4ebb040f
DB
23
24self_dir = Path(__file__).parent
25src_dir = self_dir.parent.parent
26dockerfiles_dir = Path(src_dir, "tests", "docker", "dockerfiles")
27
feb6cb93 28lcitool_path = Path(self_dir, "libvirt-ci", "bin", "lcitool")
4ebb040f
DB
29
30lcitool_cmd = [lcitool_path, "--data-dir", self_dir]
31
06885cf9 32
4ebb040f 33def atomic_write(filename, content):
06885cf9
AB
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
4ebb040f
DB
43
44def generate(filename, cmd, trailer):
06885cf9
AB
45 print("Generate %s" % filename)
46 lcitool = subprocess.run(cmd, capture_output=True)
4ebb040f 47
06885cf9
AB
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)
4ebb040f 55
5b8bcf6b
AB
56# Optional user setting, this will always be the last thing added
57# so maximise the number of layers that are cached
58add_user_mapping = [
59 "# As a final step configure the user (if env is defined)",
60 "ARG USER",
61 "ARG UID",
62 "RUN if [ \"${USER}\" ]; then \\",
63 " id ${USER} 2>/dev/null || useradd -u ${UID} -U ${USER}; fi\n"
64]
4ebb040f
DB
65
66def generate_dockerfile(host, target, cross=None, trailer=None):
06885cf9
AB
67 filename = Path(src_dir, "tests", "docker", "dockerfiles", host + ".docker")
68 cmd = lcitool_cmd + ["dockerfile"]
69 if cross is not None:
70 cmd.extend(["--cross", cross])
71 cmd.extend([target, "qemu"])
5b8bcf6b
AB
72
73 if trailer is not None:
74 trailer += "\n".join(add_user_mapping)
75 else:
76 trailer = "\n".join(add_user_mapping)
77
06885cf9
AB
78 generate(filename, cmd, trailer)
79
4ebb040f 80
c45a540f 81def generate_cirrus(target, trailer=None):
06885cf9
AB
82 filename = Path(src_dir, ".gitlab-ci.d", "cirrus", target + ".vars")
83 cmd = lcitool_cmd + ["variables", target, "qemu"]
84 generate(filename, cmd, trailer)
85
c45a540f 86
9e19fd7d
AB
87# Netmap still needs to be manually built as it is yet to be packaged
88# into a distro. We also add cscope and gtags which are used in the CI
89# test
90debian11_extras = [
91 "# netmap/cscope/global\n",
92 "RUN DEBIAN_FRONTEND=noninteractive eatmydata \\\n",
93 " apt install -y --no-install-recommends \\\n",
94 " cscope\\\n",
95 " global\\\n",
96 " linux-headers-amd64\n",
97 "RUN git clone https://github.com/luigirizzo/netmap.git /usr/src/netmap\n",
98 "RUN cd /usr/src/netmap && git checkout v11.3\n",
99 "RUN cd /usr/src/netmap/LINUX && ./configure --no-drivers --no-apps --kernel-dir=$(ls -d /usr/src/linux-headers-*-amd64) && make install\n",
100 "ENV QEMU_CONFIGURE_OPTS --enable-netmap\n"
101]
102
103
6532426a 104def cross_build(prefix, targets):
06885cf9
AB
105 conf = "ENV QEMU_CONFIGURE_OPTS --cross-prefix=%s\n" % (prefix)
106 targets = "ENV DEF_TARGET_LIST %s\n" % (targets)
107 return "".join([conf, targets])
e3000245 108
06885cf9
AB
109#
110# Update all the various build configurations.
111# Please keep each group sorted alphabetically for easy reading.
112#
e3000245 113
4ebb040f 114try:
06885cf9
AB
115 #
116 # Standard native builds
117 #
81844654 118 generate_dockerfile("alpine", "alpine-316")
06885cf9 119 generate_dockerfile("centos8", "centos-stream-8")
9e19fd7d
AB
120 generate_dockerfile("debian-amd64", "debian-11",
121 trailer="".join(debian11_extras))
0054dc8b 122 generate_dockerfile("fedora", "fedora-37")
5f9efbbc 123 generate_dockerfile("opensuse-leap", "opensuse-leap-15")
171080d8
AB
124 generate_dockerfile("ubuntu2004", "ubuntu-2004")
125 generate_dockerfile("ubuntu2204", "ubuntu-2204")
06885cf9
AB
126
127 #
128 # Cross compiling builds
129 #
cd150e19
AB
130 generate_dockerfile("debian-amd64-cross", "debian-11",
131 cross="x86_64",
6532426a
AB
132 trailer=cross_build("x86_64-linux-gnu-",
133 "x86_64-softmmu,"
134 "x86_64-linux-user,"
135 "i386-softmmu,i386-linux-user"))
cd150e19 136
06885cf9
AB
137 generate_dockerfile("debian-arm64-cross", "debian-11",
138 cross="aarch64",
6532426a
AB
139 trailer=cross_build("aarch64-linux-gnu-",
140 "aarch64-softmmu,aarch64-linux-user"))
06885cf9 141
94806241
AB
142 generate_dockerfile("debian-armel-cross", "debian-11",
143 cross="armv6l",
6532426a
AB
144 trailer=cross_build("arm-linux-gnueabi-",
145 "arm-softmmu,arm-linux-user,armeb-linux-user"))
94806241 146
18ad049d
AB
147 generate_dockerfile("debian-armhf-cross", "debian-11",
148 cross="armv7l",
6532426a
AB
149 trailer=cross_build("arm-linux-gnueabihf-",
150 "arm-softmmu,arm-linux-user"))
18ad049d 151
1e834d17
AB
152 generate_dockerfile("debian-mips64el-cross", "debian-11",
153 cross="mips64el",
6532426a
AB
154 trailer=cross_build("mips64el-linux-gnuabi64-",
155 "mips64el-softmmu,mips64el-linux-user"))
1e834d17 156
432ae739
AB
157 generate_dockerfile("debian-mipsel-cross", "debian-11",
158 cross="mipsel",
6532426a
AB
159 trailer=cross_build("mipsel-linux-gnu-",
160 "mipsel-softmmu,mipsel-linux-user"))
432ae739 161
4ec740e1
AB
162 generate_dockerfile("debian-ppc64el-cross", "debian-11",
163 cross="ppc64le",
6532426a
AB
164 trailer=cross_build("powerpc64le-linux-gnu-",
165 "ppc64-softmmu,ppc64-linux-user"))
4ec740e1 166
06885cf9
AB
167 generate_dockerfile("debian-s390x-cross", "debian-11",
168 cross="s390x",
6532426a
AB
169 trailer=cross_build("s390x-linux-gnu-",
170 "s390x-softmmu,s390x-linux-user"))
06885cf9 171
0054dc8b 172 generate_dockerfile("fedora-win32-cross", "fedora-37",
9e243b76
AB
173 cross="mingw32",
174 trailer=cross_build("i686-w64-mingw32-",
175 "i386-softmmu"))
176
0054dc8b 177 generate_dockerfile("fedora-win64-cross", "fedora-37",
9e243b76
AB
178 cross="mingw64",
179 trailer=cross_build("x86_64-w64-mingw32-",
180 "x86_64-softmmu"))
181
06885cf9
AB
182 #
183 # Cirrus packages lists for GitLab
184 #
185 generate_cirrus("freebsd-12")
186 generate_cirrus("freebsd-13")
c70fe3b1 187 generate_cirrus("macos-12")
06885cf9
AB
188
189 sys.exit(0)
4ebb040f 190except Exception as ex:
06885cf9
AB
191 print(str(ex), file=sys.stderr)
192 sys.exit(1)