Add lua helper functions to make it possible to automatically generate Obsoletes tags
This commit is contained in:
parent
a8b26546eb
commit
5d7727c2aa
@ -191,6 +191,7 @@
|
|||||||
|
|
||||||
%py_provides() %{lua:
|
%py_provides() %{lua:
|
||||||
local python = require 'fedora.srpm.python'
|
local python = require 'fedora.srpm.python'
|
||||||
|
local rhel = rpm.expand('%{?rhel}')
|
||||||
local name = rpm.expand('%1')
|
local name = rpm.expand('%1')
|
||||||
if name == '%1' then
|
if name == '%1' then
|
||||||
rpm.expand('%{error:%%py_provides requires at least 1 argument, the name to provide}')
|
rpm.expand('%{error:%%py_provides requires at least 1 argument, the name to provide}')
|
||||||
@ -204,6 +205,16 @@
|
|||||||
for i, provide in ipairs(provides) do
|
for i, provide in ipairs(provides) do
|
||||||
print('Provides: ' .. provide .. '\\n')
|
print('Provides: ' .. provide .. '\\n')
|
||||||
end
|
end
|
||||||
|
-- We only generate these Obsoletes on CentOS/RHEL to provide clean upgrade
|
||||||
|
-- path, e.g. python3-foo obsoletes python3.9-foo from previous RHEL.
|
||||||
|
-- In Fedora this is not needed as we don't ship ecosystem packages
|
||||||
|
-- for alternative Python interpreters.
|
||||||
|
if rhel ~= '' then
|
||||||
|
local obsoletes = python.python_altobsoletes(name, evr)
|
||||||
|
for i, obsolete in ipairs(obsoletes) do
|
||||||
|
print('Obsoletes: ' .. obsolete .. '\\n')
|
||||||
|
end
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
%python_extras_subpkg(n:i:f:F) %{expand:%{lua:
|
%python_extras_subpkg(n:i:f:F) %{expand:%{lua:
|
||||||
|
@ -49,7 +49,7 @@ elseif posix.stat('macros.python-srpm') then
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
Version: %{__default_python3_version}
|
Version: %{__default_python3_version}
|
||||||
Release: 14%{?dist}
|
Release: 15%{?dist}
|
||||||
|
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
|
|
||||||
@ -145,6 +145,11 @@ install -m 755 brp-* %{buildroot}%{_rpmconfigdir}/redhat/
|
|||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Dec 21 2021 Tomas Orsava <torsava@redhat.com> - 3.10-15
|
||||||
|
- Add lua helper functions to make it possible to automatically generate
|
||||||
|
Obsoletes tags
|
||||||
|
- Modify the %%py_provides macro to also generate Obsoletes tags on CentOS/RHEL
|
||||||
|
|
||||||
* Wed Dec 08 2021 Miro Hrončok <mhroncok@redhat.com> - 3.10-14
|
* Wed Dec 08 2021 Miro Hrončok <mhroncok@redhat.com> - 3.10-14
|
||||||
- Set %%__python3 value according to %%python3_pkgversion
|
- Set %%__python3 value according to %%python3_pkgversion
|
||||||
I.e. when %%python3_pkgversion is 3.12, %%__python3 is /usr/bin/python3.12
|
I.e. when %%python3_pkgversion is 3.12, %%__python3 is /usr/bin/python3.12
|
||||||
|
81
python.lua
81
python.lua
@ -2,22 +2,25 @@
|
|||||||
|
|
||||||
-- Determine alternate names provided from the given name.
|
-- Determine alternate names provided from the given name.
|
||||||
-- Used in pythonname provides generator, python_provide and py_provides.
|
-- Used in pythonname provides generator, python_provide and py_provides.
|
||||||
-- There are 2 rules:
|
-- If only_3_to_3_X is false/nil/unused there are 2 rules:
|
||||||
-- python3-foo -> python-foo, python3.X-foo
|
-- python3-foo -> python-foo, python3.X-foo
|
||||||
-- python3.X-foo -> python-foo, python3-foo
|
-- python3.X-foo -> python-foo, python3-foo
|
||||||
|
-- If only_3_to_3_X is true there is only 1 rule:
|
||||||
|
-- python3-foo -> python3.X-foo
|
||||||
-- There is no python-foo -> rule, python-foo packages are version agnostic.
|
-- There is no python-foo -> rule, python-foo packages are version agnostic.
|
||||||
-- Returns a table/array with strings. Empty when no rule matched.
|
-- Returns a table/array with strings. Empty when no rule matched.
|
||||||
local function python_altnames(name)
|
local function python_altnames(name, only_3_to_3_X)
|
||||||
local xy = rpm.expand('%{__default_python3_pkgversion}')
|
local xy = rpm.expand('%{__default_python3_pkgversion}')
|
||||||
local altnames = {}
|
local altnames = {}
|
||||||
local replaced
|
local replaced
|
||||||
-- NB: dash needs to be escaped!
|
-- NB: dash needs to be escaped!
|
||||||
if name:match('^python3%-') then
|
if name:match('^python3%-') then
|
||||||
for i, prefix in ipairs({'python-', 'python' .. xy .. '-'}) do
|
local prefixes = only_3_to_3_X and {} or {'python-'}
|
||||||
|
for i, prefix in ipairs({'python' .. xy .. '-', table.unpack(prefixes)}) do
|
||||||
replaced = name:gsub('^python3%-', prefix)
|
replaced = name:gsub('^python3%-', prefix)
|
||||||
table.insert(altnames, replaced)
|
table.insert(altnames, replaced)
|
||||||
end
|
end
|
||||||
elseif name:match('^python' .. xy .. '%-') then
|
elseif name:match('^python' .. xy .. '%-') and not only_3_to_3_X then
|
||||||
for i, prefix in ipairs({'python-', 'python3-'}) do
|
for i, prefix in ipairs({'python-', 'python3-'}) do
|
||||||
replaced = name:gsub('^python' .. xy .. '%-', prefix)
|
replaced = name:gsub('^python' .. xy .. '%-', prefix)
|
||||||
table.insert(altnames, replaced)
|
table.insert(altnames, replaced)
|
||||||
@ -27,42 +30,72 @@ local function python_altnames(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function __python_alttags(name, evr, tag_type)
|
||||||
|
-- for the "provides" tag_type we want also unversioned provides
|
||||||
|
local only_3_to_3_X = tag_type ~= "provides"
|
||||||
|
local operator = tag_type == "provides" and ' = ' or ' < '
|
||||||
|
|
||||||
|
-- global cache that tells what package NEVRs were already processed for the
|
||||||
|
-- given tag type
|
||||||
|
if __python_alttags_beenthere == nil then
|
||||||
|
__python_alttags_beenthere = {}
|
||||||
|
end
|
||||||
|
if __python_alttags_beenthere[tag_type] == nil then
|
||||||
|
__python_alttags_beenthere[tag_type] = {}
|
||||||
|
end
|
||||||
|
__python_alttags_beenthere[tag_type][name .. ' ' .. evr] = true
|
||||||
|
local alttags = {}
|
||||||
|
for i, altname in ipairs(python_altnames(name, only_3_to_3_X)) do
|
||||||
|
table.insert(alttags, altname .. operator .. evr)
|
||||||
|
end
|
||||||
|
return alttags
|
||||||
|
end
|
||||||
|
|
||||||
-- For any given name and epoch-version-release, return provides except self.
|
-- For any given name and epoch-version-release, return provides except self.
|
||||||
-- Uses python_altnames under the hood
|
-- Uses python_altnames under the hood
|
||||||
-- Returns a table/array with strings.
|
-- Returns a table/array with strings.
|
||||||
local function python_altprovides(name, evr)
|
local function python_altprovides(name, evr)
|
||||||
-- global cache that tells what provides were already processed
|
return __python_alttags(name, evr, "provides")
|
||||||
if __python_altnames_provides_beenthere == nil then
|
|
||||||
__python_altnames_provides_beenthere = {}
|
|
||||||
end
|
|
||||||
__python_altnames_provides_beenthere[name .. ' ' .. evr] = true
|
|
||||||
local altprovides = {}
|
|
||||||
for i, altname in ipairs(python_altnames(name)) do
|
|
||||||
table.insert(altprovides, altname .. ' = ' .. evr)
|
|
||||||
end
|
|
||||||
return altprovides
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- For any given name and epoch-version-release, return versioned obsoletes except self.
|
||||||
|
-- Uses python_altnames under the hood
|
||||||
|
-- Returns a table/array with strings.
|
||||||
|
local function python_altobsoletes(name, evr)
|
||||||
|
return __python_alttags(name, evr, "obsoletes")
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function __python_alttags_once(name, evr, tag_type)
|
||||||
|
-- global cache that tells what provides were already processed
|
||||||
|
if __python_alttags_beenthere == nil
|
||||||
|
or __python_alttags_beenthere[tag_type] == nil
|
||||||
|
or __python_alttags_beenthere[tag_type][name .. ' ' .. evr] == nil then
|
||||||
|
return __python_alttags(name, evr, tag_type)
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Like python_altprovides but only return something once.
|
-- Like python_altprovides but only return something once.
|
||||||
-- For each argument can only be used once, returns nil otherwise.
|
-- For each argument can only be used once, returns nil otherwise.
|
||||||
-- Previous usage of python_altprovides counts as well.
|
-- Previous usage of python_altprovides counts as well.
|
||||||
local function python_altprovides_once(name, evr)
|
local function python_altprovides_once(name, evr)
|
||||||
-- global cache that tells what provides were already processed
|
return __python_alttags_once(name, evr, "provides")
|
||||||
if __python_altnames_provides_beenthere == nil then
|
end
|
||||||
__python_altnames_provides_beenthere = {}
|
|
||||||
end
|
-- Like python_altobsoletes but only return something once.
|
||||||
if __python_altnames_provides_beenthere[name .. ' ' .. evr] == nil then
|
-- For each argument can only be used once, returns nil otherwise.
|
||||||
__python_altnames_provides_beenthere[name .. ' ' .. evr] = true
|
-- Previous usage of python_altobsoletes counts as well.
|
||||||
return python_altprovides(name, evr)
|
local function python_altobsoletes_once(name, evr)
|
||||||
else
|
return __python_alttags_once(name, evr, "obsoletes")
|
||||||
return nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
python_altnames = python_altnames,
|
python_altnames = python_altnames,
|
||||||
python_altprovides = python_altprovides,
|
python_altprovides = python_altprovides,
|
||||||
|
python_altobsoletes = python_altobsoletes,
|
||||||
python_altprovides_once = python_altprovides_once,
|
python_altprovides_once = python_altprovides_once,
|
||||||
|
python_altobsoletes_once = python_altobsoletes_once,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user