From 33358b9a65b84d73a64fe7b5f00ff2a7fe83f72c Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: May 05 2020 12:02:52 +0000 Subject: Deduplicate automatically provided names trough Python RPM Lua macros --- diff --git a/python-rpm-generators.spec b/python-rpm-generators.spec index 6687b81..5c61cd9 100644 --- a/python-rpm-generators.spec +++ b/python-rpm-generators.spec @@ -1,7 +1,7 @@ Name: python-rpm-generators Summary: Dependency generators for Python RPMs Version: 11 -Release: 5%{?dist} +Release: 6%{?dist} # Originally all those files were part of RPM, so license is kept here License: GPLv2+ @@ -23,8 +23,8 @@ Summary: %{summary} Requires: python3-setuptools # We have parametric macro generators, we need RPM 4.16 (4.15.90+ is 4.16 alpha) Requires: rpm > 4.15.90-0 -# We use %%python_provide -Requires: python-rpm-macros +# This contains the Lua functions we use: +Requires: python-srpm-macros >= 3.8-5 %description -n python3-rpm-generators %{summary}. @@ -45,6 +45,9 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} pythondistdeps.py %{_rpmconfigdir}/pythondistdeps.py %changelog +* Tue May 05 2020 Miro Hrončok - 11-6 +- Deduplicate automatically provided names trough Python RPM Lua macros + * Wed Apr 29 2020 Tomas Orsava - 11-5 - Backporting proposed upstream changes https://github.com/rpm-software-management/rpm/pull/1195 diff --git a/pythonname.attr b/pythonname.attr index b086549..85969d7 100644 --- a/pythonname.attr +++ b/pythonname.attr @@ -1,19 +1,18 @@ %__pythonname_provides() %{lua: + local python = require 'fedora.srpm.python' -- this macro is called for each file in a package, the path being in %1 -- but we don't need to know the path, so we would get for each file: Macro %1 defined but not used within scope -- in here, we expand %name conditionally on %1 to suppress the warning local name = rpm.expand('%{?1:%{name}}') - -- a structure that knows what names were already processed, so we can end early - if __pythonname_beenthere == nil then - __pythonname_beenthere = {} - end - -- we save ourselves a trip to %python_provide if we have already been there - if __pythonname_beenthere[name] == nil then - local python_provide = rpm.expand('%{?python_provide:%python_provide %{name}}') - for provides in python_provide:gmatch('Provides:[ \\t]+([^\\n]+)') do - print(provides .. " ") + local evr = rpm.expand('%{?epoch:%{epoch}:}%{version}-%{release}') + local provides = python.python_altprovides_once(name, evr) + -- provides is either an array/table or nil + -- nil means the function was already called with the same arguments: + -- either with another file in %1 or manually via %py_provide + if provides then + for i, provide in ipairs(provides) do + print(provide .. ' ') end - __pythonname_beenthere[name] = true end } diff --git a/tests/pythonname.sh b/tests/pythonname.sh index 8bedc03..d5c8f3c 100755 --- a/tests/pythonname.sh +++ b/tests/pythonname.sh @@ -26,3 +26,11 @@ echo "Provides for python35-foo" rpm -qp --provides ${RPMDIR}/python35-foo-0-0.noarch.rpm rpm -qp --provides ${RPMDIR}/python35-foo-0-0.noarch.rpm | grep -q '^python-foo = 0-0$' && exit 1 || true rpm -qp --provides ${RPMDIR}/python35-foo-0-0.noarch.rpm | grep -q '^python3-foo = 0-0$' && exit 1 || true + +echo "Provides for python3-python_provide" +rpm -qp --provides ${RPMDIR}/python3-python_provide-0-0.noarch.rpm +test $(rpm -qp --provides ${RPMDIR}/python3-python_provide-0-0.noarch.rpm | grep python-python_provide | wc -l) -eq 1 + +echo "Provides for python3-py_provides" +rpm -qp --provides ${RPMDIR}/python3-py_provides-0-0.noarch.rpm +test $(rpm -qp --provides ${RPMDIR}/python3-py_provides-0-0.noarch.rpm | grep python-py_provides | wc -l) -eq 1 diff --git a/tests/pythonname.spec b/tests/pythonname.spec index b4a3f6d..01222ef 100644 --- a/tests/pythonname.spec +++ b/tests/pythonname.spec @@ -60,3 +60,23 @@ Summary: ... ... %files -n ruby-foo /* + + +%package -n python3-python_provide +Summary: ... +%{?python_provide:%python_provide python3-python_provide} + +%description -n python3-python_provide +... +%files -n python3-python_provide +/* + + +%package -n python3-py_provides +Summary: ... +%py_provides python3-py_provides + +%description -n python3-py_provides +... +%files -n python3-py_provides +/*