From 353f8b9faff797c6068a037aaef18c5394c531c7 Mon Sep 17 00:00:00 2001 From: Nicolas Mailhot Date: Dec 04 2018 16:25:01 +0000 Subject: common: add a setcurrent helper --- diff --git a/common.lua b/common.lua index 77ebf69..92924c6 100644 --- a/common.lua +++ b/common.lua @@ -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 to +-- 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, diff --git a/forge.lua b/forge.lua index bcfe01f..950e345 100644 --- a/forge.lua +++ b/forge.lua @@ -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, } diff --git a/macros.forge b/macros.forge index b11ecec..167d2ed 100644 --- a/macros.forge +++ b/macros.forge @@ -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 }