*/*: [QA] Remove redundant `|| die` guards
[gentoo.git] / app-emulation / libvirt / libvirt-9999.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python3_{5,6,7} )
7
8 inherit autotools out-of-source 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=""
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 dtrace firewalld fuse glusterfs iscsi
27         iscsi-direct +libvirtd lvm libssh lxc +macvtap nfs nls numa openvz
28         parted pcap phyp policykit +qemu rbd sasl selinux +udev +vepa
29         virtualbox virt-network wireshark-plugins xen 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/glib-2.48.0
54         dev-libs/libgcrypt:0
55         dev-libs/libnl:3
56         >=dev-libs/libxml2-2.7.6
57         >=net-analyzer/openbsd-netcat-1.105-r1
58         >=net-libs/gnutls-1.0.25:0=
59         net-libs/libssh2
60         net-libs/libtirpc
61         net-libs/rpcsvc-proto
62         >=net-misc/curl-7.18.0
63         sys-apps/dmidecode
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         dtrace? ( dev-util/systemtap )
73         firewalld? ( >=net-firewall/firewalld-0.6.3 )
74         fuse? ( >=sys-fs/fuse-2.8.6:= )
75         glusterfs? ( >=sys-cluster/glusterfs-3.4.1 )
76         iscsi? ( sys-block/open-iscsi )
77         iscsi-direct? ( >=net-libs/libiscsi-1.18.0 )
78         libssh? ( net-libs/libssh )
79         lvm? ( >=sys-fs/lvm2-2.02.48-r2[-device-mapper-only(-)] )
80         lxc? ( !sys-apps/systemd[-cgroup-hybrid(+)] )
81         nfs? ( net-fs/nfs-utils )
82         numa? (
83                 >sys-process/numactl-2.0.2
84                 sys-process/numad
85         )
86         parted? (
87                 >=sys-block/parted-1.8[device-mapper]
88                 sys-fs/lvm2[-device-mapper-only(-)]
89         )
90         pcap? ( >=net-libs/libpcap-1.0.0 )
91         policykit? ( >=sys-auth/polkit-0.9 )
92         qemu? (
93                 >=app-emulation/qemu-1.5.0
94                 dev-libs/yajl
95         )
96         rbd? ( sys-cluster/ceph )
97         sasl? ( dev-libs/cyrus-sasl )
98         selinux? ( >=sys-libs/libselinux-2.0.85 )
99         virt-network? (
100                 net-dns/dnsmasq[script]
101                 net-firewall/ebtables
102                 >=net-firewall/iptables-1.4.10[ipv6]
103                 net-misc/radvd
104                 sys-apps/iproute2[-minimal]
105         )
106         virtualbox? ( || ( app-emulation/virtualbox >=app-emulation/virtualbox-bin-2.2.0 ) )
107         wireshark-plugins? ( net-analyzer/wireshark:= )
108         xen? (
109                 >=app-emulation/xen-4.6.0
110                 app-emulation/xen-tools:=
111         )
112         udev? (
113                 virtual/udev
114                 >=x11-libs/libpciaccess-0.10.9
115         )
116         zfs? ( sys-fs/zfs )"
117
118 DEPEND="${RDEPEND}
119         ${PYTHON_DEPS}
120         app-text/xhtml1
121         dev-lang/perl
122         dev-libs/libxslt
123         dev-perl/XML-XPath
124         virtual/pkgconfig"
125
126 PATCHES=(
127         "${FILESDIR}"/${PN}-5.7.0-do-not-use-sysconf.patch
128         "${FILESDIR}"/${PN}-1.2.16-fix_paths_in_libvirt-guests_sh.patch
129         "${FILESDIR}"/${PN}-5.2.0-fix-paths-for-apparmor.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-r18" "${S}/libvirtd.init" || die
236         sed -e "s/USE_FLAG_FIREWALLD/$(usex firewalld 'need firewalld' '')/" \
237                 -i "${S}/libvirtd.init" || die "sed failed"
238
239         eautoreconf
240 }
241
242 my_src_configure() {
243         local myeconfargs=(
244                 $(use_with apparmor)
245                 $(use_with apparmor apparmor-profiles)
246                 $(use_with audit)
247                 $(use_with caps capng)
248                 $(use_with dbus)
249                 $(use_with dtrace)
250                 $(use_with firewalld)
251                 $(use_with fuse)
252                 $(use_with glusterfs)
253                 $(use_with glusterfs storage-gluster)
254                 $(use_with iscsi storage-iscsi)
255                 $(use_with iscsi-direct storage-iscsi-direct)
256                 $(use_with libvirtd)
257                 $(use_with libssh)
258                 $(use_with lvm storage-lvm)
259                 $(use_with lvm storage-mpath)
260                 $(use_with lxc)
261                 $(use_with macvtap)
262                 $(use_enable nls)
263                 $(use_with numa numactl)
264                 $(use_with numa numad)
265                 $(use_with openvz)
266                 $(use_with parted storage-disk)
267                 $(use_with pcap libpcap)
268                 $(use_with phyp)
269                 $(use_with policykit polkit)
270                 $(use_with qemu)
271                 $(use_with qemu yajl)
272                 $(use_with rbd storage-rbd)
273                 $(use_with sasl)
274                 $(use_with selinux)
275                 $(use_with udev)
276                 $(use_with vepa virtualport)
277                 $(use_with virt-network network)
278                 $(use_with wireshark-plugins wireshark-dissector)
279                 $(use_with xen libxl)
280                 $(use_with zfs storage-zfs)
281
282                 --without-hal
283                 --without-netcf
284                 --without-sanlock
285
286                 --with-esx
287                 --with-init-script=systemd
288                 --with-qemu-group=$(usex caps qemu root)
289                 --with-qemu-user=$(usex caps qemu root)
290                 --with-remote
291                 --with-storage-fs
292                 --with-vmware
293
294                 --disable-static
295                 --disable-werror
296
297                 --localstatedir=/var
298                 --enable-dependency-tracking
299         )
300
301         if use virtualbox && has_version app-emulation/virtualbox-ose; then
302                 myeconfargs+=( --with-vbox=/usr/lib/virtualbox-ose/ )
303         else
304                 myeconfargs+=( $(use_with virtualbox vbox) )
305         fi
306
307         econf "${myeconfargs[@]}"
308
309         if [[ ${PV} = *9999* ]]; then
310                 # Restore gnulib's config.sub and config.guess
311                 # bug #377279
312                 (cd ${S}/.gnulib && git reset --hard > /dev/null)
313         fi
314 }
315
316 my_src_test() {
317         # remove problematic tests, bug #591416, bug #591418
318         sed -i -e 's#commandtest$(EXEEXT) # #' \
319                 -e 's#virfirewalltest$(EXEEXT) # #' \
320                 -e 's#nwfilterebiptablestest$(EXEEXT) # #' \
321                 -e 's#nwfilterxml2firewalltest$(EXEEXT)$##' \
322                 tests/Makefile
323
324         export VIR_TEST_DEBUG=1
325         HOME="${T}" emake check
326 }
327
328 my_src_install() {
329         emake DESTDIR="${D}" \
330                 SYSTEMD_UNIT_DIR="$(systemd_get_systemunitdir)" install
331
332         find "${D}" -name '*.la' -delete || die
333
334         # Remove bogus, empty directories. They are either not used, or
335         # libvirtd is able to create them on demand
336         rm -rf "${D}"/etc/sysconfig
337         rm -rf "${D}"/var
338
339         newbashcomp "${S}/tools/bash-completion/vsh" virsh
340         bashcomp_alias virsh virt-admin
341
342         use libvirtd || return 0
343         # From here, only libvirtd-related instructions, be warned!
344
345         systemd_install_serviced \
346                 "${FILESDIR}"/libvirtd.service.conf libvirtd.service
347
348         systemd_newtmpfilesd "${FILESDIR}"/libvirtd.tmpfiles.conf libvirtd.conf
349
350         newinitd "${S}/libvirtd.init" libvirtd
351         newinitd "${FILESDIR}/libvirt-guests.init-r4" libvirt-guests
352         newinitd "${FILESDIR}/virtlockd.init-r1" virtlockd
353         newinitd "${FILESDIR}/virtlogd.init-r1" virtlogd
354
355         newconfd "${FILESDIR}/libvirtd.confd-r5" libvirtd
356         newconfd "${FILESDIR}/libvirt-guests.confd" libvirt-guests
357
358         DOC_CONTENTS=$(<"${FILESDIR}/README.gentoo-r2")
359         DISABLE_AUTOFORMATTING=true
360         readme.gentoo_create_doc
361 }
362
363 pkg_preinst() {
364         # we only ever want to generate this once
365         if [[ -e "${ROOT}"/etc/libvirt/qemu/networks/default.xml ]]; then
366                 rm -rf "${D}"/etc/libvirt/qemu/networks/default.xml
367         fi
368 }
369
370 pkg_postinst() {
371         if [[ -e "${ROOT}"/etc/libvirt/qemu/networks/default.xml ]]; then
372                 touch "${ROOT}"/etc/libvirt/qemu/networks/default.xml
373         fi
374
375         use libvirtd || return 0
376         # From here, only libvirtd-related instructions, be warned!
377
378         readme.gentoo_print_elog
379 }