common: add a setcurrent helper

This commit is contained in:
Nicolas Mailhot 2018-11-08 19:18:36 +01:00 committed by Igor Gnatenko
parent 7b6ec4668c
commit 353f8b9faf
3 changed files with 21 additions and 8 deletions

View File

@ -45,6 +45,18 @@ local function zalias(rpmvars,verbose)
end end
end end
-- Takes a list of rpm variable roots and a suffix and alias current<root> to
-- <root><suffix> if it resolves to something not empty
local function setcurrent(rpmvars, suffix, verbose)
for _, rpmvar in ipairs(rpmvars) do
if (rpm.expand("%{?" .. rpmvar .. suffix .. "}") ~= "") then
explicitset( "current" .. rpmvar, "%{" .. rpmvar .. suffix .. "}", verbose)
else
explicitunset("current" .. rpmvar, verbose)
end
end
end
-- Echo the list of rpm variables, with suffix, if set -- Echo the list of rpm variables, with suffix, if set
local function echovars(rpmvars, suffix) local function echovars(rpmvars, suffix)
for _, rpmvar in ipairs(rpmvars) do for _, rpmvar in ipairs(rpmvars) do
@ -106,6 +118,7 @@ return {
explicitunset = explicitunset, explicitunset = explicitunset,
safeset = safeset, safeset = safeset,
zalias = zalias, zalias = zalias,
setcurrent = setcurrent,
echovars = echovars, echovars = echovars,
getsuffixed = getsuffixed, getsuffixed = getsuffixed,
getsuffixes = getsuffixes, getsuffixes = getsuffixes,

View File

@ -66,7 +66,7 @@ end
-- The forgemeta macro main processing function -- The forgemeta macro main processing function
-- See the documentation in the macros.forge file for argument description -- See the documentation in the macros.forge file for argument description
-- Also called directly by gometa -- Also called directly by gometa
local function forgemeta(suffix, verbose, informative, silent) local function meta(suffix, verbose, informative, silent)
local fedora = require "fedora.common" local fedora = require "fedora.common"
local ismain = (suffix == "") or (suffix == "0") local ismain = (suffix == "") or (suffix == "0")
if ismain then if ismain then
@ -250,6 +250,6 @@ local function forgemeta(suffix, verbose, informative, silent)
end end
return { return {
forgemeta = forgemeta, meta = meta,
} }

View File

@ -53,10 +53,10 @@ local silent = rpm.expand("%{-s}") ~= ""
local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "") local processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "")
if processall then if processall then
for _,s in pairs(fedora.getsuffixes("forgeurl")) do for _,s in pairs(fedora.getsuffixes("forgeurl")) do
forge.forgemeta(s,verbose,informative,silent) forge.meta(s,verbose,informative,silent)
end end
else else
forge.forgemeta(rpm.expand("%{-z*}"),verbose,informative,silent) forge.meta(rpm.expand("%{-z*}"),verbose,informative,silent)
end end
} }