From 325daa0c021a3e5091c9690bab5fac8929a7de33 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Feb 13 2019 02:49:24 +0000 Subject: refactor the py2/py3 macro flags --- diff --git a/koji.spec b/koji.spec index 84556e5..3d5eb58 100644 --- a/koji.spec +++ b/koji.spec @@ -1,17 +1,47 @@ -# Enable Python 3 builds for Fedora/RHEL8 -%if 0%{?fedora} || 0%{?rhel} >= 8 %bcond_without python3 -# If the definition isn't available for python3_pkgversion, define it -%{?!python3_pkgversion:%global python3_pkgversion 3} +%bcond_without python2 + +# We can build varying amounts of Koji for python2 and python3 based on +# the py[23]_support macro values. Valid values are: +# undefined or 0 -- do not build +# 1 -- build just the cli and lib +# 2 -- build everything we can +# For executable scripts, py3 wins if we build it +# The following rules tweak these settings based on options and environment + +# Default to building both fully +%define py2_support 2 +%define py3_support 2 + +# No python3 for older rhel +%if 0%{?rhel} < 8 +%define py3_support 0 %else -%bcond_with python3 +# and no python2 on rhel8+ +%define py2_support 0 %endif -# don't build py2 packages for py3-only systems -%if 0%{with python3} && (0%{?fedora} > 32 || 0%{?rhel} > 7) - %define with_python2 0 +%if 0%{?fedora} < 30 +# match what these Fedoras already have +%define py2_support 2 +%define py3_support 1 %else - %define with_python2 1 +%if 0%{?fedora} < 33 +%define py2_support 1 +%define py3_support 2 +%else +# no py2 after F33 +%define py2_support 0 +%define py3_support 2 +%endif +%endif + +# Lastly enforce the bcond parameters +%if %{without python2} +%define py2_support 0 +%endif +%if %{without python3} +%define py3_support 0 %endif # Compatibility with RHEL. These macros have been added to EPEL but @@ -23,6 +53,9 @@ %{!?py2_build: %global py2_build %{expand: CFLAGS="%{optflags}" %{__python2} setup.py %{?py_setup_args} build --executable="%{__python2} -s"}} %{!?py2_install: %global py2_install %{expand: CFLAGS="%{optflags}" %{__python2} setup.py %{?py_setup_args} install -O1 --skip-build --root %{buildroot}}} +# If the definition isn't available for python3_pkgversion, define it +%{?!python3_pkgversion:%global python3_pkgversion 3} + %if 0%{?fedora} >= 21 || 0%{?rhel} >= 7 %global use_systemd 1 %else @@ -48,7 +81,7 @@ URL: https://pagure.io/koji Source: https://releases.pagure.org/koji/koji-%{version}.tar.bz2 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch -%if 0%{with python3} +%if 0%{py3_support} Requires: python%{python3_pkgversion}-%{name} = %{version}-%{release} Requires: python%{python3_pkgversion}-libcomps %else @@ -66,7 +99,7 @@ BuildRequires: pkgconfig Koji is a system for building and tracking RPMS. The base package contains shared libraries and the command-line interface. -%if 0%{with_python2} +%if 0%{py2_support} %package -n python2-%{name} Summary: Build system tools python library %{?python_provide:%python_provide python2-%{name}} @@ -90,7 +123,7 @@ Requires: python-six desc %endif -%if 0%{with python3} +%if 0%{py3_support} %package -n python%{python3_pkgversion}-%{name} Summary: Build system tools python library %{?python_provide:%python_provide python%{python3_pkgversion}-%{name}} @@ -110,7 +143,7 @@ Requires: python%{python3_pkgversion}-six desc %endif -%if 0%{with_python2} +%if 0%{py2_support} %package -n python2-%{name}-cli-plugins Summary: Koji client plugins Group: Applications/Internet @@ -121,7 +154,7 @@ Requires: %{name} = %{version}-%{release} Plugins to the koji command-line interface %endif -%if 0%{with python3} +%if 0%{py3_support} %package -n python%{python3_pkgversion}-%{name}-cli-plugins Summary: Koji client plugins Group: Applications/Internet @@ -146,6 +179,7 @@ Suggests: python%{python3_pkgversion}-%{name}-hub-plugins %description hub koji-hub is the XMLRPC interface to the koji database +%if 0%{py2_support} > 1 %package -n python2-%{name}-hub Summary: Koji XMLRPC interface Group: Applications/Internet @@ -165,8 +199,9 @@ Provides: %{name}-hub-code = %{version}-%{release} %description -n python2-%{name}-hub koji-hub is the XMLRPC interface to the koji database +%endif -%if 0%{with python3} +%if 0%{py3_support} > 1 %package -n python%{python3_pkgversion}-%{name}-hub Summary: Koji XMLRPC interface Group: Applications/Internet @@ -200,6 +235,7 @@ Suggests: python%{python3_pkgversion}-%{name}-hub-plugins %description hub-plugins Plugins to the koji XMLRPC interface +%if 0%{py2_support} > 1 %package -n python2-%{name}-hub-plugins Summary: Koji hub plugins Group: Applications/Internet @@ -214,8 +250,9 @@ Provides: %{name}-hub-plugins-code %description -n python2-%{name}-hub-plugins Plugins to the koji XMLRPC interface +%endif -%if 0%{with python3} +%if 0%{py3_support} > 1 %package -n python%{python3_pkgversion}-%{name}-hub-plugins Summary: Koji hub plugins Group: Applications/Internet @@ -264,7 +301,7 @@ Requires: /usr/bin/cvs Requires: /usr/bin/svn Requires: /usr/bin/git Requires: createrepo >= 0.9.2 -%if 0%{with python3} +%if 0%{py3_support} > 1 Requires: python%{python3_pkgversion}-%{name} = %{version}-%{release} Requires: python%{python3_pkgversion}-multilib Requires: python%{python3_pkgversion}-cheetah @@ -320,7 +357,7 @@ Requires(postun): systemd %description utils Utilities for the Koji system -%if 0%{with_python2} +%if 0%{py2_support} > 1 %package -n python2-%{name}-web Summary: Koji Web UI Group: Applications/Internet @@ -344,7 +381,7 @@ Obsoletes: koji-web < 1.16.2 koji-web is a web UI to the Koji system. %endif -%if 0%{with python3} +%if 0%{py3_support} > 1 %package -n python%{python3_pkgversion}-%{name}-web Summary: Koji Web UI Group: Applications/Internet @@ -370,11 +407,28 @@ koji-web is a web UI to the Koji system. %install rm -rf $RPM_BUILD_ROOT -%if 0%{with_python2} + +%if 0%{py2_support} < 2 && 0%{py3_support} < 2 +echo "At least one python must be built with full support" +exit 1 +%endif + +# python2 build +%if 0%{py2_support} > 1 make DESTDIR=$RPM_BUILD_ROOT PYTHON=%{__python2} %{?install_opt} install +%else +%if 0%{py2_support} +for d in koji cli plugins ; do + pushd $d + make DESTDIR=$RPM_BUILD_ROOT PYTHON=%{__python2} %{?install_opt} install + popd +done %endif -%if 0%{with python3} -for d in koji cli plugins hub www ; do +%endif + +# python3 build +%if 0%{py3_support} > 1 +for d in koji cli plugins hub www builder ; do pushd $d make DESTDIR=$RPM_BUILD_ROOT PYTHON=%{__python3} %{?install_opt} install popd @@ -382,6 +436,19 @@ done # alter python interpreter in koji CLI sed -i 's/\#\!\/usr\/bin\/python2/\#\!\/usr\/bin\/python3/' $RPM_BUILD_ROOT/usr/bin/koji sed -i 's/\#\!\/usr\/bin\/python2/\#\!\/usr\/bin\/python3/' $RPM_BUILD_ROOT/usr/sbin/kojid +%else +%if 0%{py3_support} +# minimal +for d in koji cli plugins ; do + pushd $d + make DESTDIR=$RPM_BUILD_ROOT PYTHON=%{__python3} %{?install_opt} install + popd +done +# alter python interpreter in koji CLI +sed -i 's/\#\!\/usr\/bin\/python2/\#\!\/usr\/bin\/python3/' $RPM_BUILD_ROOT/usr/bin/koji +# remove the hub plugins pycache +rm -rf $RPM_BUILD_ROOT/usr/lib/koji-hub-plugins/__pycache__ +%endif %endif %clean @@ -394,20 +461,20 @@ rm -rf $RPM_BUILD_ROOT %dir /etc/koji.conf.d %doc docs Authors COPYING LGPL -%if 0%{with_python2} +%if 0%{py2_support} %files -n python2-%{name} %defattr(-,root,root) %{python2_sitelib}/%{name} %{python2_sitelib}/koji_cli %endif -%if 0%{with python3} +%if 0%{py3_support} %files -n python%{python3_pkgversion}-koji %{python3_sitelib}/%{name} %{python3_sitelib}/koji_cli %endif -%if 0%{with_python2} +%if 0%{py2_support} %files -n python2-%{name}-cli-plugins %defattr(-,root,root) %{python2_sitelib}/koji_cli_plugins @@ -416,7 +483,7 @@ rm -rf $RPM_BUILD_ROOT #%%config(noreplace) %%{_sysconfdir}/koji/plugins/*.conf %endif -%if 0%{with python3} +%if 0%{py3_support} %files -n python%{python3_pkgversion}-%{name}-cli-plugins %defattr(-,root,root) %{python3_sitelib}/koji_cli_plugins @@ -432,14 +499,14 @@ rm -rf $RPM_BUILD_ROOT %config(noreplace) /etc/koji-hub/hub.conf %dir /etc/koji-hub/hub.conf.d -%if 0%{with_python2} +%if 0%{py2_support} > 1 %files -n python2-%{name}-hub %defattr(-,root,root) %{_datadir}/koji-hub/*.py* %dir %{_libexecdir}/koji-hub %endif -%if 0%{with python3} +%if 0%{py3_support} > 1 %files -n python%{python3_pkgversion}-%{name}-hub %defattr(-,root,root) %{_datadir}/koji-hub/*.py @@ -451,20 +518,20 @@ rm -rf $RPM_BUILD_ROOT %dir /etc/koji-hub/plugins %config(noreplace) /etc/koji-hub/plugins/*.conf -%if 0%{with_python2} +%if 0%{py2_support} > 1 %files -n python2-%{name}-hub-plugins %defattr(-,root,root) %{_prefix}/lib/koji-hub-plugins/*.py* %endif -%if 0%{with python3} +%if 0%{py3_support} > 1 %files -n python%{python3_pkgversion}-%{name}-hub-plugins %defattr(-,root,root) %{_prefix}/lib/koji-hub-plugins/*.py %{_prefix}/lib/koji-hub-plugins/__pycache__ %endif -%if 0%{with_python2} +%if 0%{py2_support} > 1 %files builder-plugins %defattr(-,root,root) %dir /etc/kojid/plugins @@ -473,7 +540,7 @@ rm -rf $RPM_BUILD_ROOT %{_prefix}/lib/koji-builder-plugins/*.py* %endif -%if 0%{with_python2} +%if 0%{py2_support} %files utils %defattr(-,root,root) %{_sbindir}/kojira @@ -493,7 +560,7 @@ rm -rf $RPM_BUILD_ROOT %config(noreplace) /etc/koji-shadow/koji-shadow.conf %endif -%if 0%{with_python2} +%if 0%{py2_support} > 1 %files -n python2-%{name}-web %defattr(-,root,root) %{_datadir}/koji-web @@ -503,7 +570,7 @@ rm -rf $RPM_BUILD_ROOT %dir /etc/kojiweb/web.conf.d %endif -%if 0%{with python3} +%if 0%{py3_support} > 1 %files -n python%{python3_pkgversion}-%{name}-web %defattr(-,root,root) %{_datadir}/koji-web @@ -513,7 +580,6 @@ rm -rf $RPM_BUILD_ROOT %dir /etc/kojiweb/web.conf.d %endif -%if 0%{with_python2} %files builder %defattr(-,root,root) %{_sbindir}/kojid @@ -554,9 +620,8 @@ if [ $1 = 0 ]; then /sbin/chkconfig --del kojid fi %endif -%endif -%if 0%{with_python2} +%if 0%{py2_support} > 1 %files vm %defattr(-,root,root) %{_sbindir}/kojivmd