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

@ -2,7 +2,7 @@
-- Set a spec variable
-- Echo the result if verbose
local function explicitset(rpmvar,value,verbose)
local function explicitset(rpmvar, value, verbose)
local value = value
if (value == nil) or (value == "") then
value = "%{nil}"
@ -15,7 +15,7 @@ end
-- Unset a spec variable if it is defined
-- Echo the result if verbose
local function explicitunset(rpmvar,verbose)
local function explicitunset(rpmvar, verbose)
if (rpm.expand("%{" .. rpmvar .. "}") ~= "%{" .. rpmvar .. "}") then
rpm.define(rpmvar .. " %{nil}")
if verbose then
@ -26,7 +26,7 @@ end
-- Set a spec variable, if not already set
-- Echo the result if verbose
local function safeset(rpmvar,value,verbose)
local function safeset(rpmvar, value, verbose)
if (rpm.expand("%{" .. rpmvar .. "}") == "%{" .. rpmvar .. "}") then
explicitset(rpmvar,value,verbose)
end
@ -34,7 +34,7 @@ end
-- Alias a list of rpm variables to the same variables suffixed with 0 (and vice versa)
-- Echo the result if verbose
local function zalias(rpmvars,verbose)
local function zalias(rpmvars, verbose)
for _, sfx in ipairs({{"","0"},{"0",""}}) do
for _, rpmvar in ipairs(rpmvars) do
local toalias = "%{?" .. rpmvar .. sfx[1] .. "}"
@ -45,6 +45,18 @@ local function zalias(rpmvars,verbose)
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
local function echovars(rpmvars, suffix)
for _, rpmvar in ipairs(rpmvars) do
@ -106,6 +118,7 @@ return {
explicitunset = explicitunset,
safeset = safeset,
zalias = zalias,
setcurrent = setcurrent,
echovars = echovars,
getsuffixed = getsuffixed,
getsuffixes = getsuffixes,

View File

@ -66,7 +66,7 @@ end
-- The forgemeta macro main processing function
-- See the documentation in the macros.forge file for argument description
-- 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 ismain = (suffix == "") or (suffix == "0")
if ismain then
@ -250,6 +250,6 @@ local function forgemeta(suffix, verbose, informative, silent)
end
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}") == "")
if processall then
for _,s in pairs(fedora.getsuffixes("forgeurl")) do
forge.forgemeta(s,verbose,informative,silent)
forge.meta(s,verbose,informative,silent)
end
else
forge.forgemeta(rpm.expand("%{-z*}"),verbose,informative,silent)
forge.meta(rpm.expand("%{-z*}"),verbose,informative,silent)
end
}