Automatically call %python_provide

This allows us to drop the %python_provide macro from most spec files,
except where we want to use it for virtual provides or empty packages.
This commit is contained in:
Miro Hrončok 2020-03-05 23:40:17 +01:00
parent eae8dd0f57
commit bbfe4930d9
5 changed files with 120 additions and 2 deletions

View File

@ -10,7 +10,8 @@ Url: https://src.fedoraproject.org/python-rpm-generators
Source0: https://raw.githubusercontent.com/rpm-software-management/rpm/102eab50b3d0d6546dfe082eac0ade21e6b3dbf1/COPYING
Source1: python.attr
Source2: pythondist.attr
Source3: pythondistdeps.py
Source3: pythonname.attr
Source4: pythondistdeps.py
BuildArch: noarch
@ -22,6 +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
%description -n python3-rpm-generators
%{summary}.
@ -31,19 +34,21 @@ Requires: rpm > 4.15.90-0
cp -a %{sources} .
%install
install -Dpm0644 -t %{buildroot}%{_fileattrsdir} python.attr pythondist.attr
install -Dpm0644 -t %{buildroot}%{_fileattrsdir} *.attr
install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} pythondistdeps.py
%files -n python3-rpm-generators
%license COPYING
%{_fileattrsdir}/python.attr
%{_fileattrsdir}/pythondist.attr
%{_fileattrsdir}/pythonname.attr
%{_rpmconfigdir}/pythondistdeps.py
%changelog
* Wed Apr 01 2020 Miro Hrončok <mhroncok@redhat.com> - 11-1
- Rewrite python(abi) generators to Lua to make them faster
- RPM 4.16+ is needed
- Automatically call %%python_provide
* Thu Jan 30 2020 Fedora Release Engineering <releng@fedoraproject.org> - 10-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild

20
pythonname.attr Normal file
View File

@ -0,0 +1,20 @@
%__pythonname_provides() %{lua:
-- 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 .. " ")
end
__pythonname_beenthere[name] = true
end
}
%__pythonname_path ^/

28
tests/pythonname.sh Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/bash -eux
rpmbuild -ba pythonname.spec
XY=$(rpm --eval '%python3_version_nodots')
RPMDIR=$(rpm --eval '%_topdir')/RPMS/noarch
echo "Provides for python${XY}-foo"
rpm -qp --provides ${RPMDIR}/python${XY}-foo-0-0.noarch.rpm
rpm -qp --provides ${RPMDIR}/python${XY}-foo-0-0.noarch.rpm | grep -q '^python-foo = 0-0$'
rpm -qp --provides ${RPMDIR}/python${XY}-foo-0-0.noarch.rpm | grep -q '^python3-foo = 0-0$'
echo "Provides for python3-foo"
rpm -qp --provides ${RPMDIR}/python3-foo-0-0.noarch.rpm
rpm -qp --provides ${RPMDIR}/python3-foo-0-0.noarch.rpm | grep -q '^python-foo = 0-0$'
rpm -qp --provides ${RPMDIR}/python3-foo-0-0.noarch.rpm | grep -q '^python'${XY}'-foo = 0-0$'
echo "Provides for python2-foo"
rpm -qp --provides ${RPMDIR}/python2-foo-0-0.noarch.rpm
rpm -qp --provides ${RPMDIR}/python2-foo-0-0.noarch.rpm | grep -vq '^python-foo = 0-0$'
echo "Provides for python-foo"
rpm -qp --provides ${RPMDIR}/python-foo-0-0.noarch.rpm
rpm -qp --provides ${RPMDIR}/python-foo-0-0.noarch.rpm | grep -vq '^python2-foo = 0-0$'
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 -vq '^python-foo = 0-0$'
rpm -qp --provides ${RPMDIR}/python35-foo-0-0.noarch.rpm | grep -vq '^python3-foo = 0-0$'

62
tests/pythonname.spec Normal file
View File

@ -0,0 +1,62 @@
Name: pythonname
Version: 0
Release: 0
Summary: ...
License: MIT
BuildArch: noarch
%description
...
%install
touch %{buildroot}/something
touch %{buildroot}/something_else
touch %{buildroot}/something_completely_different
%package -n python-foo
Summary: ...
%description -n python-foo
...
%files -n python-foo
/*
%package -n python2-foo
Summary: ...
%description -n python2-foo
...
%files -n python2-foo
/*
%package -n python3-foo
Summary: ...
%description -n python3-foo
...
%files -n python3-foo
/*
%package -n python%{python3_version_nodots}-foo
Summary: ...
%description -n python%{python3_version_nodots}-foo
...
%files -n python%{python3_version_nodots}-foo
/*
%package -n python35-foo
Summary: ...
%description -n python35-foo
...
%files -n python35-foo
/*
%package -n ruby-foo
Summary: ...
%description -n ruby-foo
...
%files -n ruby-foo
/*

View File

@ -16,6 +16,9 @@
- pythonabi:
dir: .
run: ./pythonabi.sh
- pythonname:
dir: .
run: ./pythonname.sh
required_packages:
- rpm-build
- python3-devel