diff --git a/python-rpm-generators.spec b/python-rpm-generators.spec index 599eb0c..df36108 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: 14 -Release: 13%{?dist} +Release: 20%{?dist} Url: https://src.fedoraproject.org/rpms/python-rpm-generators @@ -18,7 +18,8 @@ Source4: pythondistdeps.py # LicenseRef-Fedora-Public-Domain OR CC0-1.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later # Note that CC0-1.0 is not allowed for code in Fedora, so we skip it in the package License tag Source5: pythonbundles.py - +# This is built heavily on python.attr: GPL-2.0-or-later +Source6: pythonprerel.attr # See individual licenses above Source declarations # Originally, this was simplified to GPL-2.0-or-later, but "effective license" analysis is no longer allowed License: GPL-2.0-or-later AND LGPL-2.1-or-later AND (LicenseRef-Fedora-Public-Domain OR LGPL-2.1-or-later OR GPL-2.0-or-later) @@ -52,6 +53,7 @@ install -Dpm0755 -t %{buildroot}%{_rpmconfigdir} *.py %{_fileattrsdir}/python.attr %{_fileattrsdir}/pythondist.attr %{_fileattrsdir}/pythonname.attr +%{_fileattrsdir}/pythonprerel.attr %{_rpmconfigdir}/pythondistdeps.py %{_rpmconfigdir}/pythonbundles.py diff --git a/pythonprerel.attr b/pythonprerel.attr new file mode 100644 index 0000000..2840766 --- /dev/null +++ b/pythonprerel.attr @@ -0,0 +1,58 @@ +%__pythonprerel_provides() %{lua: + -- Match buildroot/payload paths of the form + -- /PATH/OF/BUILDROOT/usr/bin/pythonMAJOR.MINOR + -- generating a line of the form + -- python(prerel-abi) = MAJOR.MINOR.MICRO~RELEASELEVELSERIAL + -- (Don't match against -config tools e.g. /usr/bin/python3.14-config) + local path = rpm.expand('%1') + if path:match('/usr/bin/python%d+%.%d+$') then + if not _pythonprerel_version_cache then + _pythonprerel_version_cache = {} + end + + local version = _pythonprerel_version_cache[path] + if not version then + local buildroot = rpm.expand('%{buildroot}') + local ld_library_path = buildroot .. '/usr/lib64:' .. buildroot .. '/usr/lib' + local cmd = 'LD_LIBRARY_PATH=' .. ld_library_path .. ' ' .. path .. [[ -Esc "import sys; sys.stdout.write('{0.major}.{0.minor}.{0.micro}~{0.releaselevel}{0.serial}'.format(sys.version_info))"]] + version = io.popen(cmd):read("*a") + -- Cache the version for future calls + _pythonprerel_version_cache[path] = version + end + + local provides = 'python(prerel-abi) = ' .. version + print(provides) + end +} + +%__pythonprerel_requires() %{lua: + -- Match buildroot paths of the form + -- /PATH/OF/BUILDROOT/usr/lib/pythonMAJOR.MINOR/ and + -- /PATH/OF/BUILDROOT/usr/lib64/pythonMAJOR.MINOR/ + -- generating a line of the form: + -- python(prerel-abi) = MAJOR.MINOR.MICRO~RELEASELEVELSERIAL + local path = rpm.expand('%1') + local pyver = path:match('/usr/lib%d*/python(%d+%.%d+)/.*') + if pyver then + if not _pythonprerel_version_cache then + _pythonprerel_version_cache = {} + end + + local buildroot = rpm.expand('%{buildroot}') + local python_path = buildroot .. '/usr/bin/python' .. pyver + + local version = _pythonprerel_version_cache[python_path] + if not version then + local ld_library_path = buildroot .. '/usr/lib64:' .. buildroot .. '/usr/lib' + local cmd = 'LD_LIBRARY_PATH=' .. ld_library_path .. ' ' .. python_path .. [[ -Esc "import sys; sys.stdout.write('{0.major}.{0.minor}.{0.micro}~{0.releaselevel}{0.serial}'.format(sys.version_info))"]] + version = io.popen(cmd):read("*a") + -- Cache the version for future calls + _pythonprerel_version_cache[python_path] = version + end + + local requires = 'python(prerel-abi) = ' .. version + print(requires) + end +} + +%__pythonprerel_path ^((/usr/lib(64)?/python[[:digit:]]+\\.[[:digit:]]+/.*\\.so)|(%{_bindir}/python[[:digit:]]+\\.[[:digit:]]+))$ diff --git a/tests/pythonabi.sh b/tests/pythonabi.sh index 36b6060..eb68dff 100755 --- a/tests/pythonabi.sh +++ b/tests/pythonabi.sh @@ -5,6 +5,7 @@ PYVER=$(rpm --eval '%python3_version') RPMDIR=$(rpm --eval '%_topdir')/RPMS ARCH=$(rpm --eval '%_arch') ABI='^python(abi) = '${PYVER}'$' +PREREL_ABI='^python(prerel-abi) = '${PYVER}'.*$' rpm -qp --provides ${RPMDIR}/${ARCH}/python-interpreter-0-0.${ARCH}.rpm | grep "${ABI}" rpm -qp --requires ${RPMDIR}/${ARCH}/python-interpreter-0-0.${ARCH}.rpm | grep "${ABI}" && exit 1 || true @@ -17,3 +18,9 @@ rpm -qp --provides ${RPMDIR}/noarch/python-noarch-0-0.noarch.rpm | grep "${ABI}" rpm -qp --provides ${RPMDIR}/${ARCH}/python-misplaced-interpreter-0-0.${ARCH}.rpm | grep "${ABI}" && exit 1 || true rpm -qp --requires ${RPMDIR}/noarch/python-misplaced-library-0-0.noarch.rpm | grep "${ABI}" && exit 1 || true + +rpm -qp --requires ${RPMDIR}/${ARCH}/python-arched-0-0.${ARCH}.rpm | grep "${PREREL_ABI}" +rpm -qp --provides ${RPMDIR}/${ARCH}/python-arched-0-0.${ARCH}.rpm | grep "${PREREL_ABI}" && exit 1 || true + +rpm -qp --requires ${RPMDIR}/noarch/python-noarch-0-0.noarch.rpm | grep "${PREREL_ABI}" && exit 1 || true +rpm -qp --provides ${RPMDIR}/noarch/python-noarch-0-0.noarch.rpm | grep "${PREREL_ABI}" && exit 1 || true