diff options
-rw-r--r-- | openEuler-rpm-config.spec | 8 | ||||
-rw-r--r-- | python.lua | 101 |
2 files changed, 107 insertions, 2 deletions
diff --git a/openEuler-rpm-config.spec b/openEuler-rpm-config.spec index d044886..57adaef 100644 --- a/openEuler-rpm-config.spec +++ b/openEuler-rpm-config.spec @@ -3,7 +3,7 @@ Name: %{vendor}-rpm-config Version: 31 -Release: 6 +Release: 7 License: GPL+ Summary: specific rpm configuration files URL: https://gitee.com/src-openeuler/openEuler-rpm-config @@ -58,6 +58,7 @@ Source706: brp-strip-lto # Convenience lua functions Source800: common.lua +Source801: python.lua Provides: python-rpm-macros = %{?epoch:%{epoch}:}%{version}-%{release} Provides: python2-rpm-macros = %{?epoch:%{epoch}:}%{version}-%{release} @@ -152,7 +153,7 @@ mkdir -p %{buildroot}%{_fileattrsdir} install -p -m 644 -t %{buildroot}%{_fileattrsdir} *.attr mkdir -p %{buildroot}%{_rpmluadir}/%{_vendor}/{rpm,srpm} -install -p -m 644 -t %{buildroot}%{_rpmluadir}/%{_vendor} common.lua +install -p -m 644 -t %{buildroot}%{_rpmluadir}/%{_vendor} *.lua # Adaptive according to vendor sed -i "s/@VENDOR@/%{vendor}/g" `grep "@VENDOR@" -rl %{buildroot}%{_rpmconfigdir}` @@ -178,6 +179,9 @@ sed -i "s/@VENDOR@/%{vendor}/g" `grep "@VENDOR@" -rl %{buildroot}%{_rpmconfigdir %{rpmvdir}/find-requires.ksyms %changelog +* Thu Oct 24 2024 Funda Wang <fundawang@yeah.net> - 31-7 +- add python.lua from fedora + * Sat Oct 19 2024 Funda Wang <fundawang@yeah.net> - 31-6 - add extension flags for python modules diff --git a/python.lua b/python.lua new file mode 100644 index 0000000..bd30a85 --- /dev/null +++ b/python.lua @@ -0,0 +1,101 @@ +-- Convenience Lua functions that can be used within Python srpm/rpm macros + +-- Determine alternate names provided from the given name. +-- Used in pythonname provides generator, python_provide and py_provides. +-- If only_3_to_3_X is false/nil/unused there are 2 rules: +-- python3-foo -> python-foo, python3.X-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. +-- Returns a table/array with strings. Empty when no rule matched. +local function python_altnames(name, only_3_to_3_X) + local xy = rpm.expand('%{__default_python3_pkgversion}') + local altnames = {} + local replaced + -- NB: dash needs to be escaped! + if name:match('^python3%-') then + 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) + table.insert(altnames, replaced) + end + elseif name:match('^python' .. xy .. '%-') and not only_3_to_3_X then + for i, prefix in ipairs({'python-', 'python3-'}) do + replaced = name:gsub('^python' .. xy .. '%-', prefix) + table.insert(altnames, replaced) + end + end + return altnames +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. +-- Uses python_altnames under the hood +-- Returns a table/array with strings. +local function python_altprovides(name, evr) + return __python_alttags(name, evr, "provides") +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. +-- For each argument can only be used once, returns nil otherwise. +-- Previous usage of python_altprovides counts as well. +local function python_altprovides_once(name, evr) + return __python_alttags_once(name, evr, "provides") +end + +-- Like python_altobsoletes but only return something once. +-- For each argument can only be used once, returns nil otherwise. +-- Previous usage of python_altobsoletes counts as well. +local function python_altobsoletes_once(name, evr) + return __python_alttags_once(name, evr, "obsoletes") +end + + +return { + python_altnames = python_altnames, + python_altprovides = python_altprovides, + python_altobsoletes = python_altobsoletes, + python_altprovides_once = python_altprovides_once, + python_altobsoletes_once = python_altobsoletes_once, +} |