*/*: Clean PYTHON_COMPAT of obsolete impls
[gentoo.git] / sys-fs / zfs / zfs-9999.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 DISTUTILS_OPTIONAL=1
7 PYTHON_COMPAT=( python{2_7,3_{6,7}} )
8
9 inherit bash-completion-r1 flag-o-matic linux-info linux-mod distutils-r1 systemd toolchain-funcs udev usr-ldscript
10
11 DESCRIPTION="Userland utilities for ZFS Linux kernel module"
12 HOMEPAGE="https://zfsonlinux.org/"
13
14 if [[ ${PV} == "9999" ]] ; then
15         inherit autotools git-r3
16         EGIT_REPO_URI="https://github.com/zfsonlinux/zfs.git"
17 else
18         SRC_URI="https://github.com/zfsonlinux/${PN}/releases/download/${P}/${P}.tar.gz"
19         KEYWORDS="~amd64 ~arm64 ~ppc64"
20 fi
21
22 LICENSE="BSD-2 CDDL MIT"
23 SLOT="0"
24 IUSE="custom-cflags debug kernel-builtin libressl python +rootfs test-suite static-libs"
25
26 DEPEND="
27         ${PYTHON_DEPS}
28         net-libs/libtirpc[static-libs?]
29         sys-apps/util-linux[static-libs?]
30         sys-libs/zlib[static-libs(+)?]
31         virtual/awk
32         virtual/libudev[static-libs(-)?]
33         libressl? ( dev-libs/libressl:0=[static-libs?] )
34         !libressl? ( dev-libs/openssl:0=[static-libs?] )
35         python? (
36                 virtual/python-cffi[${PYTHON_USEDEP}]
37         )
38 "
39
40 BDEPEND="virtual/awk
41         virtual/pkgconfig
42         python? (
43                 dev-python/setuptools[${PYTHON_USEDEP}]
44         )
45 "
46
47 RDEPEND="${DEPEND}
48         !=sys-apps/grep-2.13*
49         !kernel-builtin? ( ~sys-fs/zfs-kmod-${PV} )
50         !sys-fs/zfs-fuse
51         !prefix? ( virtual/udev )
52         sys-fs/udev-init-scripts
53         rootfs? (
54                 app-arch/cpio
55                 app-misc/pax-utils
56                 !<sys-boot/grub-2.00-r2:2
57                 !<sys-kernel/genkernel-3.5.1.1
58                 !<sys-kernel/genkernel-next-67
59                 !<sys-kernel/bliss-initramfs-7.1.0
60                 !<sys-kernel/dracut-044-r1
61         )
62         test-suite? (
63                 sys-apps/util-linux
64                 sys-devel/bc
65                 sys-block/parted
66                 sys-fs/lsscsi
67                 sys-fs/mdadm
68                 sys-process/procps
69                 virtual/modutils
70         )
71 "
72
73 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
74
75 RESTRICT="test"
76
77 PATCHES=( "${FILESDIR}/bash-completion-sudo.patch" )
78
79 pkg_setup() {
80         if use kernel_linux && use test-suite; then
81                 linux-info_pkg_setup
82
83                 if  ! linux_config_exists; then
84                         ewarn "Cannot check the linux kernel configuration."
85                 else
86                         if use test-suite; then
87                                 if linux_chkconfig_present BLK_DEV_LOOP; then
88                                         eerror "The ZFS test suite requires loop device support enabled."
89                                         eerror "Please enable it:"
90                                         eerror "    CONFIG_BLK_DEV_LOOP=y"
91                                         eerror "in /usr/src/linux/.config or"
92                                         eerror "    Device Drivers --->"
93                                         eerror "        Block devices --->"
94                                         eerror "            [X] Loopback device support"
95                                 fi
96                         fi
97                 fi
98         fi
99 }
100
101 src_prepare() {
102         default
103
104         if [[ ${PV} == "9999" ]]; then
105                 eautoreconf
106         else
107                 # Set revision number
108                 sed -i "s/\(Release:\)\(.*\)1/\1\2${PR}-gentoo/" META || die "Could not set Gentoo release"
109         fi
110
111         if use python; then
112                 pushd contrib/pyzfs >/dev/null || die
113                 distutils-r1_src_prepare
114                 popd >/dev/null || die
115         fi
116
117         # prevent errors showing up on zfs-mount stop, #647688
118         # openrc will unmount all filesystems anyway.
119         sed -i "/^ZFS_UNMOUNT=/ s/yes/no/" etc/init.d/zfs.in || die
120 }
121
122 src_configure() {
123         use custom-cflags || strip-flags
124
125         local myconf=(
126                 --bindir="${EPREFIX}/bin"
127                 --enable-shared
128                 --enable-systemd
129                 --enable-sysvinit
130                 --localstatedir="${EPREFIX}/var"
131                 --sbindir="${EPREFIX}/sbin"
132                 --with-config=user
133                 --with-dracutdir="${EPREFIX}/usr/lib/dracut"
134                 --with-linux="${KV_DIR}"
135                 --with-linux-obj="${KV_OUT_DIR}"
136                 --with-udevdir="$(get_udevdir)"
137                 --with-systemdunitdir="$(systemd_get_systemunitdir)"
138                 --with-systemdpresetdir="${EPREFIX}/lib/systemd/system-preset"
139                 $(use_enable debug)
140                 $(use_enable python pyzfs)
141                 $(use_enable static-libs static)
142         )
143
144         econf "${myconf[@]}"
145 }
146
147 src_compile() {
148         default
149         if use python; then
150                 pushd contrib/pyzfs >/dev/null || die
151                 distutils-r1_src_compile
152                 popd >/dev/null || die
153         fi
154 }
155
156 src_install() {
157         default
158
159         gen_usr_ldscript -a uutil nvpair zpool zfs zfs_core
160
161         use test-suite || rm -rf "${ED}/usr/share/zfs"
162
163         if ! use static-libs; then
164                 find "${ED}/" -name '*.la' -delete || die
165         fi
166
167         dobashcomp contrib/bash_completion.d/zfs
168         bashcomp_alias zfs zpool
169
170         # strip executable bit from conf.d file
171         fperms 0644 /etc/conf.d/zfs
172
173         if use python; then
174                 pushd contrib/pyzfs >/dev/null || die
175                 distutils-r1_src_install
176                 popd >/dev/null || die
177         fi
178
179         # enforce best available python implementation
180         python_setup
181         python_fix_shebang "${ED}/bin"
182 }
183
184 pkg_postinst() {
185         if use rootfs; then
186                 if ! has_version sys-kernel/genkernel && ! has_version sys-kernel/dracut; then
187                         elog "root on zfs requires initramfs to boot"
188                         elog "the following packages known to provide one and tested on regular basis:"
189                         elog "  sys-kernel/dracut"
190                         elog "  sys-kernel/genkernel"
191                 fi
192
193                 if has_version "<=sys-kernel/genkernel-3.5.3.3"; then
194                         einfo "genkernel version 3.5.3.3 and earlier does NOT support"
195                         einfo " unlocking pools with native zfs encryption enabled at boot"
196                         einfo " use dracut or >=genkernel-4 if you requre this functionality"
197                 fi
198         fi
199
200         if ! use kernel-builtin && [[ ${PV} = "9999" ]]; then
201                 einfo "Adding ${P} to the module database to ensure that the"
202                 einfo "kernel modules and userland utilities stay in sync."
203                 update_moduledb
204         fi
205
206         [[ -e "${EROOT}/etc/runlevels/boot/zfs-import" ]] || \
207                 einfo "You should add zfs-import to the boot runlevel."
208         [[ -e "${EROOT}/etc/runlevels/boot/zfs-mount" ]]|| \
209                 einfo "You should add zfs-mount to the boot runlevel."
210         [[ -e "${EROOT}/etc/runlevels/default/zfs-share" ]] || \
211                 einfo "You should add zfs-share to the default runlevel."
212         [[ -e "${EROOT}/etc/runlevels/default/zfs-zed" ]] || \
213                 einfo "You should add zfs-zed to the default runlevel."
214 }
215
216 pkg_postrm() {
217         if ! use kernel-builtin && [[ ${PV} == "9999" ]]; then
218                 remove_moduledb
219         fi
220 }