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", "bin", "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-153") 116 generate_dockerfile("ubuntu2004", "ubuntu-2004", 117 trailer="".join(ubuntu2004_tsanhack)) 118 119 # 120 # Cross compiling builds 121 # 122 generate_dockerfile("debian-amd64-cross", "debian-11", 123 cross="x86_64", 124 trailer=debian_cross_build("x86_64-linux-gnu-", 125 "x86_64-softmmu," 126 "x86_64-linux-user," 127 "i386-softmmu,i386-linux-user")) 128 129 generate_dockerfile("debian-arm64-cross", "debian-11", 130 cross="aarch64", 131 trailer=debian_cross_build("aarch64-linux-gnu-", 132 "aarch64-softmmu,aarch64-linux-user")) 133 134 generate_dockerfile("debian-armel-cross", "debian-11", 135 cross="armv6l", 136 trailer=debian_cross_build("arm-linux-gnueabi-", 137 "arm-softmmu,arm-linux-user,armeb-linux-user")) 138 139 generate_dockerfile("debian-armhf-cross", "debian-11", 140 cross="armv7l", 141 trailer=debian_cross_build("arm-linux-gnueabihf-", 142 "arm-softmmu,arm-linux-user")) 143 144 generate_dockerfile("debian-mips64el-cross", "debian-11", 145 cross="mips64el", 146 trailer=debian_cross_build("mips64el-linux-gnuabi64-", 147 "mips64el-softmmu,mips64el-linux-user")) 148 149 generate_dockerfile("debian-mipsel-cross", "debian-11", 150 cross="mipsel", 151 trailer=debian_cross_build("mipsel-linux-gnu-", 152 "mipsel-softmmu,mipsel-linux-user")) 153 154 generate_dockerfile("debian-ppc64el-cross", "debian-11", 155 cross="ppc64le", 156 trailer=debian_cross_build("powerpc64le-linux-gnu-", 157 "ppc64-softmmu,ppc64-linux-user")) 158 159 generate_dockerfile("debian-s390x-cross", "debian-11", 160 cross="s390x", 161 trailer=debian_cross_build("s390x-linux-gnu-", 162 "s390x-softmmu,s390x-linux-user")) 163 164 # 165 # Cirrus packages lists for GitLab 166 # 167 generate_cirrus("freebsd-12") 168 generate_cirrus("freebsd-13") 169 generate_cirrus("macos-11") 170 171 sys.exit(0) 172except Exception as ex: 173 print(str(ex), file=sys.stderr) 174 sys.exit(1) 175