*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / app-emulation / libvirt / libvirt-5.2.0-r2.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python3_{6,7} )
7
8 inherit autotools bash-completion-r1 eutils linux-info python-any-r1 readme.gentoo-r1 systemd
9
10 if [[ ${PV} = *9999* ]]; then
11         inherit git-r3
12         EGIT_REPO_URI="https://libvirt.org/git/libvirt.git"
13         SRC_URI=""
14         KEYWORDS="amd64 x86"
15         SLOT="0"
16 else
17         SRC_URI="https://libvirt.org/sources/${P}.tar.xz"
18         KEYWORDS="amd64 ~arm64 x86"
19         SLOT="0/${PV}"
20 fi
21
22 DESCRIPTION="C toolkit to manipulate virtual machines"
23 HOMEPAGE="http://www.libvirt.org/"
24 LICENSE="LGPL-2.1"
25 IUSE="
26         apparmor audit +caps +dbus firewalld fuse glusterfs iscsi iscsi-direct
27         +libvirtd lvm libssh lxc +macvtap nfs nls numa openvz parted pcap phyp
28         policykit +qemu rbd sasl selinux +udev +vepa virtualbox virt-network
29         wireshark-plugins xen zeroconf zfs
30 "
31
32 REQUIRED_USE="
33         firewalld? ( virt-network )
34         libvirtd? ( || ( lxc openvz qemu virtualbox xen ) )
35         lxc? ( caps libvirtd )
36         openvz? ( libvirtd )
37         policykit? ( dbus )
38         qemu? ( libvirtd )
39         vepa? ( macvtap )
40         virt-network? ( libvirtd )
41         virtualbox? ( libvirtd )
42         xen? ( libvirtd )"
43
44 # gettext.sh command is used by the libvirt command wrappers, and it's
45 # non-optional, so put it into RDEPEND.
46 # We can use both libnl:1.1 and libnl:3, but if you have both installed, the
47 # package will use 3 by default. Since we don't have slot pinning in an API,
48 # we must go with the most recent
49 RDEPEND="
50         acct-user/qemu
51         policykit? ( acct-group/libvirt )
52         app-misc/scrub
53         dev-libs/libgcrypt:0
54         dev-libs/libnl:3
55         >=dev-libs/libxml2-2.7.6
56         >=net-analyzer/openbsd-netcat-1.105-r1
57         >=net-libs/gnutls-1.0.25:0=
58         net-libs/libssh2
59         net-libs/libtirpc
60         net-libs/rpcsvc-proto
61         >=net-misc/curl-7.18.0
62         sys-apps/dmidecode
63         !sys-apps/systemd[-cgroup-hybrid(+)]
64         >=sys-apps/util-linux-2.17
65         sys-devel/gettext
66         sys-libs/ncurses:0=
67         sys-libs/readline:=
68         apparmor? ( sys-libs/libapparmor )
69         audit? ( sys-process/audit )
70         caps? ( sys-libs/libcap-ng )
71         dbus? ( sys-apps/dbus )
72         firewalld? ( >=net-firewall/firewalld-0.6.3 )
73         fuse? ( >=sys-fs/fuse-2.8.6:= )
74         glusterfs? ( >=sys-cluster/glusterfs-3.4.1 )
75         iscsi? ( sys-block/open-iscsi )
76         iscsi-direct? ( >=net-libs/libiscsi-1.18.0 )
77         libssh? ( net-libs/libssh )
78         lvm? ( >=sys-fs/lvm2-2.02.48-r2[-device-mapper-only(-)] )
79         nfs? ( net-fs/nfs-utils )
80         numa? (
81                 >sys-process/numactl-2.0.2
82                 sys-process/numad
83         )
84         parted? (
85                 >=sys-block/parted-1.8[device-mapper]
86                 sys-fs/lvm2[-device-mapper-only(-)]
87         )
88         pcap? ( >=net-libs/libpcap-1.0.0 )
89         policykit? ( >=sys-auth/polkit-0.9 )
90         qemu? (
91                 >=app-emulation/qemu-1.5.0
92                 dev-libs/yajl
93         )
94         rbd? ( sys-cluster/ceph )
95         sasl? ( dev-libs/cyrus-sasl )
96         selinux? ( >=sys-libs/libselinux-2.0.85 )
97         virt-network? (
98                 net-dns/dnsmasq[script]
99                 net-firewall/ebtables
100                 >=net-firewall/iptables-1.4.10[ipv6]
101                 net-misc/radvd
102                 sys-apps/iproute2[-minimal]
103         )
104         virtualbox? ( || ( app-emulation/virtualbox >=app-emulation/virtualbox-bin-2.2.0 ) )
105         wireshark-plugins? ( net-analyzer/wireshark:= )
106         xen? (
107                 >=app-emulation/xen-4.6.0
108                 app-emulation/xen-tools:=
109         )
110         udev? (
111                 virtual/udev
112                 >=x11-libs/libpciaccess-0.10.9
113         )
114         zeroconf? ( >=net-dns/avahi-0.6[dbus] )
115         zfs? ( sys-fs/zfs )"
116
117 DEPEND="${RDEPEND}
118         ${PYTHON_DEPS}
119         app-text/xhtml1
120         dev-lang/perl
121         dev-libs/libxslt
122         dev-perl/XML-XPath
123         virtual/pkgconfig"
124
125 PATCHES=(
126         "${FILESDIR}"/${PN}-5.2.0-do-not-use-sysconf.patch
127         "${FILESDIR}"/${PN}-1.2.16-fix_paths_in_libvirt-guests_sh.patch
128         "${FILESDIR}"/${PN}-5.2.0-fix-paths-for-apparmor.patch
129         "${FILESDIR}"/${PN}-5.2.0-md-clear.patch
130 )
131
132 pkg_setup() {
133         # Check kernel configuration:
134         CONFIG_CHECK=""
135         use fuse && CONFIG_CHECK+="
136                 ~FUSE_FS"
137
138         use lvm && CONFIG_CHECK+="
139                 ~BLK_DEV_DM
140                 ~DM_MULTIPATH
141                 ~DM_SNAPSHOT"
142
143         use lxc && CONFIG_CHECK+="
144                 ~BLK_CGROUP
145                 ~CGROUP_CPUACCT
146                 ~CGROUP_DEVICE
147                 ~CGROUP_FREEZER
148                 ~CGROUP_NET_PRIO
149                 ~CGROUP_PERF
150                 ~CGROUPS
151                 ~CGROUP_SCHED
152                 ~CPUSETS
153                 ~IPC_NS
154                 ~MACVLAN
155                 ~NAMESPACES
156                 ~NET_CLS_CGROUP
157                 ~NET_NS
158                 ~PID_NS
159                 ~POSIX_MQUEUE
160                 ~SECURITYFS
161                 ~USER_NS
162                 ~UTS_NS
163                 ~VETH
164                 ~!GRKERNSEC_CHROOT_MOUNT
165                 ~!GRKERNSEC_CHROOT_DOUBLE
166                 ~!GRKERNSEC_CHROOT_PIVOT
167                 ~!GRKERNSEC_CHROOT_CHMOD
168                 ~!GRKERNSEC_CHROOT_CAPS"
169
170         kernel_is lt 4 7 && use lxc && CONFIG_CHECK+="
171                 ~DEVPTS_MULTIPLE_INSTANCES"
172
173         use macvtap && CONFIG_CHECK+="
174                 ~MACVTAP"
175
176         use virt-network && CONFIG_CHECK+="
177                 ~BRIDGE_EBT_MARK_T
178                 ~BRIDGE_NF_EBTABLES
179                 ~NETFILTER_ADVANCED
180                 ~NETFILTER_XT_CONNMARK
181                 ~NETFILTER_XT_MARK
182                 ~NETFILTER_XT_TARGET_CHECKSUM
183                 ~IP_NF_FILTER
184                 ~IP_NF_MANGLE
185                 ~IP_NF_NAT
186                 ~IP_NF_TARGET_MASQUERADE
187                 ~IP6_NF_FILTER
188                 ~IP6_NF_MANGLE
189                 ~IP6_NF_NAT"
190         # Bandwidth Limiting Support
191         use virt-network && CONFIG_CHECK+="
192                 ~BRIDGE_EBT_T_NAT
193                 ~IP_NF_TARGET_REJECT
194                 ~NET_ACT_POLICE
195                 ~NET_CLS_FW
196                 ~NET_CLS_U32
197                 ~NET_SCH_HTB
198                 ~NET_SCH_INGRESS
199                 ~NET_SCH_SFQ"
200
201         # Handle specific kernel versions for different features
202         kernel_is lt 3 6 && CONFIG_CHECK+=" ~CGROUP_MEM_RES_CTLR"
203         if kernel_is ge 3 6; then
204                 CONFIG_CHECK+=" ~MEMCG ~MEMCG_SWAP "
205                 kernel_is lt 4 5 && CONFIG_CHECK+=" ~MEMCG_KMEM "
206         fi
207
208         ERROR_USER_NS="Optional depending on LXC configuration."
209
210         if [[ -n ${CONFIG_CHECK} ]]; then
211                 linux-info_pkg_setup
212         fi
213 }
214
215 src_prepare() {
216         touch "${S}/.mailmap"
217
218         default
219
220         if [[ ${PV} = *9999* ]]; then
221                 # Reinitialize submodules as this is required for gnulib's bootstrap
222                 git submodule init
223                 # git checkouts require bootstrapping to create the configure script.
224                 # Additionally the submodules must be cloned to the right locations
225                 # bug #377279
226                 ./bootstrap || die "bootstrap failed"
227                 (
228                     git submodule status .gnulib | awk '{ print $1 }'
229                     git hash-object bootstrap.conf
230                     git ls-tree -d HEAD gnulib/local | awk '{ print $3 }'
231                 ) >.git-module-status
232         fi
233
234         # Tweak the init script:
235         cp "${FILESDIR}/libvirtd.init-r17" "${S}/libvirtd.init" || die
236         sed -e "s/USE_FLAG_FIREWALLD/$(usex firewalld 'need firewalld' '')/" \
237                 -e "s/USE_FLAG_AVAHI/$(usex zeroconf 'use avahi-daemon' '')/" \
238                 -e "s/USE_FLAG_ISCSI/$(usex iscsi 'use iscsid' '')/" \
239                 -e "s/USE_FLAG_RBD/$(usex rbd 'use ceph' '')/" \
240                 -i "${S}/libvirtd.init" || die "sed failed"
241
242         eautoreconf
243 }
244
245 src_configure() {
246         local myeconfargs=(
247                 $(use_with apparmor)
248                 $(use_with apparmor apparmor-profiles)
249                 $(use_with audit)
250                 $(use_with caps capng)
251                 $(use_with dbus)
252                 $(use_with firewalld)
253                 $(use_with fuse)
254                 $(use_with glusterfs)
255                 $(use_with glusterfs storage-gluster)
256                 $(use_with iscsi storage-iscsi)
257                 $(use_with iscsi-direct storage-iscsi-direct)
258                 $(use_with libvirtd)
259                 $(use_with libssh)
260                 $(use_with lvm storage-lvm)
261                 $(use_with lvm storage-mpath)
262                 $(use_with lxc)
263                 $(use_with macvtap)
264                 $(use_enable nls)
265                 $(use_with numa numactl)
266                 $(use_with numa numad)
267                 $(use_with openvz)
268                 $(use_with parted storage-disk)
269                 $(use_with pcap libpcap)
270                 $(use_with phyp)
271                 $(use_with policykit polkit)
272                 $(use_with qemu)
273                 $(use_with qemu yajl)
274                 $(use_with rbd storage-rbd)
275                 $(use_with sasl)
276                 $(use_with selinux)
277                 $(use_with udev)
278                 $(use_with vepa virtualport)
279                 $(use_with virt-network network)
280                 $(use_with wireshark-plugins wireshark-dissector)
281                 $(use_with xen libxl)
282                 $(use_with zeroconf avahi)
283                 $(use_with zfs storage-zfs)
284
285                 --without-hal
286                 --without-netcf
287                 --without-sanlock
288
289                 --with-esx
290                 --with-init-script=systemd
291                 --with-qemu-group=$(usex caps qemu root)
292                 --with-qemu-user=$(usex caps qemu root)
293                 --with-remote
294                 --with-storage-fs
295                 --with-vmware
296
297                 --disable-static
298                 --disable-werror
299
300                 --with-html-subdir=${PF}/html
301                 --localstatedir=/var
302         )
303
304         if use virtualbox && has_version app-emulation/virtualbox-ose; then
305                 myeconfargs+=( --with-vbox=/usr/lib/virtualbox-ose/ )
306         else
307                 myeconfargs+=( $(use_with virtualbox vbox) )
308         fi
309
310         econf "${myeconfargs[@]}"
311
312         if [[ ${PV} = *9999* ]]; then
313                 # Restore gnulib's config.sub and config.guess
314                 # bug #377279
315                 (cd .gnulib && git reset --hard > /dev/null)
316         fi
317 }
318
319 src_test() {
320         cd "${BUILD_DIR}"
321
322         # remove problematic tests, bug #591416, bug #591418
323         sed -i -e 's#commandtest$(EXEEXT) # #' \
324                 -e 's#virfirewalltest$(EXEEXT) # #' \
325                 -e 's#nwfilterebiptablestest$(EXEEXT) # #' \
326                 -e 's#nwfilterxml2firewalltest$(EXEEXT)$##' \
327                 tests/Makefile
328
329         export VIR_TEST_DEBUG=1
330         HOME="${T}" emake check
331 }
332
333 src_install() {
334         emake DESTDIR="${D}" \
335                 SYSTEMD_UNIT_DIR="$(systemd_get_systemunitdir)" install
336
337         find "${D}" -name '*.la' -delete || die
338
339         # Remove bogus, empty directories. They are either not used, or
340         # libvirtd is able to create them on demand
341         rm -rf "${D}"/etc/sysconfig
342         rm -rf "${D}"/var
343
344         newbashcomp "${S}/tools/bash-completion/vsh" virsh
345         bashcomp_alias virsh virt-admin
346
347         use libvirtd || return 0
348         # From here, only libvirtd-related instructions, be warned!
349
350         systemd_install_serviced \
351                 "${FILESDIR}"/libvirtd.service.conf libvirtd.service
352
353         systemd_newtmpfilesd "${FILESDIR}"/libvirtd.tmpfiles.conf libvirtd.conf
354
355         newinitd "${S}/libvirtd.init" libvirtd
356         newinitd "${FILESDIR}/libvirt-guests.init-r3" libvirt-guests
357         newinitd "${FILESDIR}/virtlockd.init-r1" virtlockd
358         newinitd "${FILESDIR}/virtlogd.init-r1" virtlogd
359
360         newconfd "${FILESDIR}/libvirtd.confd-r5" libvirtd
361         newconfd "${FILESDIR}/libvirt-guests.confd" libvirt-guests
362
363         DOC_CONTENTS=$(<"${FILESDIR}/README.gentoo-r2")
364         DISABLE_AUTOFORMATTING=true
365         readme.gentoo_create_doc
366 }
367
368 pkg_preinst() {
369         # we only ever want to generate this once
370         if [[ -e "${ROOT}"/etc/libvirt/qemu/networks/default.xml ]]; then
371                 rm -rf "${D}"/etc/libvirt/qemu/networks/default.xml
372         fi
373 }
374
375 pkg_postinst() {
376         if [[ -e "${ROOT}"/etc/libvirt/qemu/networks/default.xml ]]; then
377                 touch "${ROOT}"/etc/libvirt/qemu/networks/default.xml
378         fi
379
380         use libvirtd || return 0
381         # From here, only libvirtd-related instructions, be warned!
382
383         readme.gentoo_print_elog
384 }