# PYTHON # https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/ # https://docs.fedoraproject.org/en-US/packaging-guidelines/Python_Appendix/ # https://python-rpm-porting.readthedocs.io/en/latest/application-modules.html # https://rpmbuildtut.wordpress.com/python-setuptools/ # https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/installing_and_using_dynamic_programming_languages/assembly_packaging-python-3-rpms_installing-and-using-dynamic-programming-languages # https://docs.fedoraproject.org/en-US/quick-docs/publish-rpm-on-copr # http://ftp.rpm.org/max-rpm/s1-rpm-inside-scripts.html # https://rpm-software-management.github.io/rpm/manual/macros.html # https://rpm-packaging-guide.github.io/ %global _owner pgnd %global _build_timestamp %( date +%%Y%%m%%d_%%H%%M%%S --utc ) %global _dist .%{_build_timestamp}.%{_owner}.fc%{fedora} # https://stackoverflow.com/questions/47838041/rpmbuild-how-to-disable-check-buildroot # https://rpm-software-management.github.io/rpm/manual/dependency_generators.html # %%global __spec_install_pre /bin/true # %%global __arch_install_post %%{nil} # %%global __os_install_post %%{nil} %global _disable_source_fetch 0 %global debug_package %{nil} # %%undefine _auto_set_build_flags %global _hardened_build 1 # %%global __brp_mangle_shebangs %%{nil} # %%global __brp_strip %%{nil} # %%global __requires_exclude ^.*/xxx/bin/python.*$ # %%global __requires_exclude_from ^.*/xxx/bin/python.*$ # RHEL8 rpmbuild and /usr/lib/.build-id # https://access.redhat.com/discussions/5045161 %global _build_id_links none # %%bcond_with XXX : opt build with XXX; default, without # %%bcond_without XXX : opt build without XXX; default, with # VIRTNBDBACKUP # https://libvirtbackup.grinser.de/ # https://github.com/abbbi/virtnbdbackup %global _nbd_name virtnbdbackup %global _nbd_pkgnm virtnbdbackup %global _nbd_comment Backup utility for Libvirt / qemu / kvm %global _nbd_descrip %{expand: %{_nbd_comment}.} # https://spdx.org/licenses/GPL-3.0-only.html %global _pyzor_license GPL-3.0-only %global _nbd_install_dir /usr/local/virtnbdbackup %global _nbd_lib_dir %{_nbd_install_dir}/lib64 %global _nbd_bin_dir_r bin # https://docs.fedoraproject.org/en-US/packaging-guidelines/SourceURL/ %global _nbd0_scm_repo abbbi/virtnbdbackup #%%global _nbd0_scm_branch master %global _nbd0_scm_branch v2.13 %global _libnbd_scm_repo https://gitlab.com/nbdkit/libnbd.git %global _libnbd_scm_branch stable-1.20 %global _nbd0_scm_repo_esc %( echo %{_nbd0_scm_repo} | sed 's|_|-|g' | sed 's|/|%2F|g') %global _nbd0_scm_repo_norm %( echo %{_nbd0_scm_repo} | sed 's|_|-|g' | sed 's|/|-|g' ) %global _nbd0_scm_branch_norm %( echo %{_nbd0_scm_branch} | sed 's|_|-|g' | sed 's|/|-|g' ) %global _nbd0_scm_host https://github.com %global _nbd0_scm_host_api https://api.github.com/repos %global _nbd0_scm_url %{_nbd0_scm_host}/%{_nbd0_scm_repo} %global _nbd0_scm_tarball %{_nbd0_scm_host_api}/%{_nbd0_scm_repo}/tarball/%{commit0} # !!NOTE!! GH API tarball extracts to: %global _nbd0_scm_extract_dir %{_nbd0_scm_repo_norm}-%{shortcommit0} %global forgeurl0 %{_nbd0_scm_url} %global commit0 %( git ls-remote %{forgeurl0} | grep /%{_nbd0_scm_branch}$ | cut -f1 ) %global shortcommit0 %( c=%{commit0}; echo ${c} | head -c 7 ) %global forgesource0 %{_nbd0_scm_tarball} %global extractdir0 %{_nbd0_scm_extract_dir} %global forgesetupargs0 -T -D -b 0 -n %{extractdir0} %forgemeta -i -a %global dist %{_dist} # Vendor Pinning Vendor: %{_owner} # NEVRA (n-e:v-r.a) Name: %{_nbd_pkgnm} Epoch: 3 # https://docs.fedoraproject.org/en-US/packaging-guidelines/Versioning/ Version: %{scm0}_%( echo %{_nbd0_scm_branch} | sed 's|-|_|g' ) Release: 0%{?dist} # https://blog.jasonantman.com/2014/07/how-yum-and-rpm-compare-versions/ %global _same_evr %{epoch}:%{version}-%{release} Summary: %{_nbd_comment} License: %{_nbd_license} URL: %{forgeurl0} Source0: %{forgesource0} # https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets # https://docs.pagure.org/packaging-guidelines/Packaging:Scriptlets.html BuildRequires: autoconf BuildRequires: automake BuildRequires: findutils BuildRequires: gcc BuildRequires: libtool # required for git source builds BuildRequires: ocaml BuildRequires: patchelf BuildRequires: pax-utils BuildRequires: pkgconfig(gnutls) BuildRequires: pkgconfig(python3) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: python3-pytest-cov BuildRequires: python3-setuptools BuildRequires: python3-libvirt BuildRequires: libvirt-devel Requires: gnutls Provides: %{_nbd_name} = %{_same_evr} Obsoletes: %{_nbd_name} < %{_same_evr} %description %{_nbd_descrip} %prep echo '##### STARTING PREP #####' %forgesetup -a %build echo '##### STARTING BUILD #####' cd %{_builddir}/%{extractdir0} # https://github.com/kevinconway/rpmvenv # https://stackoverflow.com/questions/60959081/python-script-in-systemd-virtual-environment-or-real-environment python3 -m venv --clear --copies %{_builddir}/%{_nbd_pkgnm}.venv source %{_builddir}/%{_nbd_pkgnm}.venv/bin/activate echo '##### VERIFY VENV #####' pip3 -V # pip 23.2.1 from /builddir/build/BUILD/fangfrisch-5cb2fbb1a5eb24946f5c999af88b87e1a844676d/fangfrisch/lib64/python3.12/site-packages/pip (python 3.12) echo '##### PIP BUILD/INSTALL #####' pip3 -q install --upgrade pip wheel # https://github.com/abbbi/virtnbdbackup/blob/v2.13/venv/create.sh # UNMAINTAINED -> https://github.com/libguestfs/libnbd # https://gitlab.com/nbdkit/libnbd ## LIBNDB # !! DIY # https://github.com/abbbi/virtnbdbackup/tree/v2.13?tab=readme-ov-file#python-package git clone --single-branch --branch %{_libnbd_scm_branch} %{_libnbd_scm_repo} libnbd pushd libnbd autoreconf -vif ./configure \ --prefix=%{_builddir}/%{_nbd_pkgnm}.venv \ --exec-prefix=%{_builddir}/%{_nbd_pkgnm}.venv \ --enable-python \ --disable-ocaml \ --disable-golang \ --disable-fuse \ --disable-rust make V=0 -j${RPM_BUILD_NCPUS} make install popd pip3 install -r ./requirements.txt pip3 -q install . pip3 -q cache purge deactivate find %{_builddir}/%{_nbd_pkgnm}.venv -name ".gitignore" -exec rm {} \; %install echo '##### STARTING INSTALL #####' cd %{_builddir}/%{extractdir0} ## modify rpmbuild rpath check criteria # cref: /usr/lib/rpm/check-rpaths-worker # QA_RPATHS=$(( 0x0001|0x0002|0x0004|0x0008|0x0010|0x0020 )) # allow 'invalid' RPATHs export QA_RPATHS="$(( 0x0002 ))" # FIX venv SHEBANGS # https://docs.fedoraproject.org/en-US/packaging-guidelines/#_shebang_lines # Deploying python application internally using venv and rpm # https://stackoverflow.com/questions/58088468/deploying-python-application-internally-using-venv-and-rpm sed -i \ "1s|.*|#\!%{_nbd_install_dir}/bin/python3|" \ $(grep -rlni '^#!.*python3' %{_builddir}/%{_nbd_pkgnm}.venv) # symlink bins mkdir -p ${RPM_BUILD_ROOT}/usr/local/bin pushd ${RPM_BUILD_ROOT}/usr/local/bin _d="${RPM_BUILD_ROOT}%{_nbd_install_dir}/bin" ln -sfr ${_d}/nbddump . ln -sfr ${_d}/nbdsh . ln -sfr ${_d}/virtnbdbackup . ln -sfr ${_d}/virtnbdmap . ln -sfr ${_d}/virtnbdrestore . popd mkdir -p ${RPM_BUILD_ROOT}/$(dirname %{_nbd_install_dir}) cp -prT \ %{_builddir}/%{_nbd_pkgnm}.venv \ ${RPM_BUILD_ROOT}/%{_nbd_install_dir} # FIX ELF RUNTIME PATHS pushd ${RPM_BUILD_ROOT}/%{_nbd_install_dir} _list=$(scanelf -EET_EXEC -EET_DYN -RBF %F .) patchelf --remove-rpath $_list patchelf --force-rpath --set-rpath '%{_nbd_lib_dir}' $_list popd %pre %post -e %preun %postun %files # http://ftp.rpm.org/max-rpm/s1-rpm-inside-files-list-directives.html %dir %{_nbd_install_dir} %{_nbd_install_dir}/* %dir /usr/local/bin/ /usr/local/bin/* %changelog * Thu Oct 31 2024 pgnd _ - bump 1730381829