Deduplicate automatically provided names trough Python RPM Lua macros

This commit is contained in:
Miro Hrončok 2020-05-05 13:26:30 +02:00
parent c3f90ed2e8
commit 33358b9a65
4 changed files with 43 additions and 13 deletions

View File

@ -1,7 +1,7 @@
Name: python-rpm-generators Name: python-rpm-generators
Summary: Dependency generators for Python RPMs Summary: Dependency generators for Python RPMs
Version: 11 Version: 11
Release: 5%{?dist} Release: 6%{?dist}
# Originally all those files were part of RPM, so license is kept here # Originally all those files were part of RPM, so license is kept here
License: GPLv2+ License: GPLv2+
@ -23,8 +23,8 @@ Summary: %{summary}
Requires: python3-setuptools Requires: python3-setuptools
# We have parametric macro generators, we need RPM 4.16 (4.15.90+ is 4.16 alpha) # We have parametric macro generators, we need RPM 4.16 (4.15.90+ is 4.16 alpha)
Requires: rpm > 4.15.90-0 Requires: rpm > 4.15.90-0
# We use %%python_provide # This contains the Lua functions we use:
Requires: python-rpm-macros Requires: python-srpm-macros >= 3.8-5
%description -n python3-rpm-generators %description -n python3-rpm-generators
%{summary}. %{summary}.
@ -45,6 +45,9 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} pythondistdeps.py
%{_rpmconfigdir}/pythondistdeps.py %{_rpmconfigdir}/pythondistdeps.py
%changelog %changelog
* Tue May 05 2020 Miro Hrončok <mhroncok@redhat.com> - 11-6
- Deduplicate automatically provided names trough Python RPM Lua macros
* Wed Apr 29 2020 Tomas Orsava <torsava@redhat.com> - 11-5 * Wed Apr 29 2020 Tomas Orsava <torsava@redhat.com> - 11-5
- Backporting proposed upstream changes - Backporting proposed upstream changes
https://github.com/rpm-software-management/rpm/pull/1195 https://github.com/rpm-software-management/rpm/pull/1195

View File

@ -1,19 +1,18 @@
%__pythonname_provides() %{lua: %__pythonname_provides() %{lua:
local python = require 'fedora.srpm.python'
-- this macro is called for each file in a package, the path being in %1 -- 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 -- 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 -- in here, we expand %name conditionally on %1 to suppress the warning
local name = rpm.expand('%{?1:%{name}}') local name = rpm.expand('%{?1:%{name}}')
-- a structure that knows what names were already processed, so we can end early local evr = rpm.expand('%{?epoch:%{epoch}:}%{version}-%{release}')
if __pythonname_beenthere == nil then local provides = python.python_altprovides_once(name, evr)
__pythonname_beenthere = {} -- provides is either an array/table or nil
end -- nil means the function was already called with the same arguments:
-- we save ourselves a trip to %python_provide if we have already been there -- either with another file in %1 or manually via %py_provide
if __pythonname_beenthere[name] == nil then if provides then
local python_provide = rpm.expand('%{?python_provide:%python_provide %{name}}') for i, provide in ipairs(provides) do
for provides in python_provide:gmatch('Provides:[ \\t]+([^\\n]+)') do print(provide .. ' ')
print(provides .. " ")
end end
__pythonname_beenthere[name] = true
end end
} }

View File

@ -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
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 '^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 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

View File

@ -60,3 +60,23 @@ Summary: ...
... ...
%files -n ruby-foo %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
/*