#46 Add various generic helpers used by the next version of fonts and golang macros
Closed 7 months ago by nim. Opened 9 months ago by nim.
rpms/ nim/redhat-rpm-config writevars  into  master

file modified
+33 -4

@@ -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 @@ 

  

  -- 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 @@ 

  

  -- 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 @@ 

  

  -- 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 @@ 

    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

@@ -101,13 +113,30 @@ 

    return best

  end

  

+ -- https://github.com/rpm-software-management/rpm/issues/581

+ -- Writes the content of a list of rpm variables to a macro spec file.

+ -- The target file must contain the corresponding anchors.

+ -- For example writevars("myfile", {"foo","bar"}) will replace:

+ --   @@FOO@@ with the rpm evaluation of %{foo} and

+ --   @@BAR@@ with the rpm evaluation of %{bar}

+ -- in myfile

+ local function writevars(macrofile, rpmvars)

+   for _, rpmvar in ipairs(rpmvars) do

+     print("sed -i 's\029" .. string.upper("@@" .. rpmvar .. "@@") ..

+                    "\029" .. rpm.expand(  "%{" .. rpmvar .. "}" ) ..

+                    "\029g' " .. macrofile .. "\n")

+   end

+ end

+ 

  return {

    explicitset   = explicitset,

    explicitunset = explicitunset,

    safeset       = safeset,

    zalias        = zalias,

+   setcurrent    = setcurrent,

    echovars      = echovars,

    getsuffixed   = getsuffixed,

    getsuffixes   = getsuffixes,

    getbestsuffix = getbestsuffix,

+   writevars     = writevars,

  }

file modified
+3 -3

@@ -66,7 +66,7 @@ 

  -- 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

@@ -224,7 +224,7 @@ 

    end

    if (rpm.expand(distprefix) ~= "") then

      if not ismain then

-       distprefix = string.gsub(distprefix, "^%.", ".S")

+       distprefix = string.gsub(distprefix, "^%.", ".s")

      end

      fedora.safeset ("distprefix"    .. suffix, distprefix, verbose)

    end

@@ -248,6 +248,6 @@ 

  end

  

  return {

-   forgemeta     = forgemeta,

+   meta = meta,

  }

  

file added
+44

@@ -0,0 +1,44 @@ 

+ # Some miscellaneous Fedora-related macros

+ 

+ # List files matching inclusion globs, excluding files matching exclusion blogs

+ # Optional parameters:

+ #  – -i "<globs>" inclusion globs

+ #  – -x "<globs>" exclusion globs

+ # Globs are space-separated lists of shell globs. Such lists require %{quote:}

+ # use for safe rpm argument passing.

+ # Alternatively, set the following rpm variables before calling the macro:

+ #  – “listfiles_inc” inclusion globs

+ #  — “listfiles_ex”  exclusion globs

+ # Arguments passed to the macro without flags will be interpreted as inclusion

+ # globs.

+ %listfiles(i:x:) %{expand:

+ while IFS= read -r -d $'\\n' finc ; do

+   printf "%s\\n" %{?-x*} %{?listfiles_ex} \\

+     | xargs -i realpath --relative-base=. '{}' \\

+     | grep "${finc}" >/dev/null || echo "${finc}"

+ done <<< $(printf "%s\\n" %{?-i*} %{?listfiles_inc} %* | xargs -i realpath --relative-base=. '{}' | sort -u)

+ }

+ 

+ # https://github.com/rpm-software-management/rpm/issues/581

+ # Write the contents of a list of rpm variables to a macro file.

+ # The target file must contain the corresponding anchors.

+ # For example %writevars -f myfile foo bar will replace:

+ #  @@FOO@@ with the rpm evaluation of %{foo} and

+ #  @@BAR@@ with the rpm evaluation of %{bar}

+ # in myfile

+ %writevars(f:) %{lua:

+ local    fedora = require "fedora.common"

+ local macrofile = rpm.expand("%{-f*}")

+ local   rpmvars = {}

+ for i = 1, rpm.expand("%#") do

+   table.insert(rpmvars, rpm.expand("%" .. i))

+ end

+ fedora.writevars(macrofile,rpmvars)

+ }

+ 

+ # https://github.com/rpm-software-management/rpm/issues/566

+ # Remove leading and ending empty lines

+ # Trim intermediary empty lines to a single line

+ # Fold on spaces

+ # Should really be a %%{text:…} verb

+ %cleandescription (sed 's|^[[:blank:]]*$||g' | sed '/^$/N;/^\\n$/D' | sed '/./,$!d' | tac | sed '/./,$!d' | tac | fold -s)

file modified
+2 -14

@@ -53,10 +53,10 @@ 

  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

  }

  

@@ -83,15 +83,3 @@ 

  %forgeautosetup(z:vNS:p:q) %{lua:

  print(rpm.expand("%autosetup %{-v} %{-N} %{?-S} %{?-p} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n"))

  }

- 

- # List files matching inclusion globs, excluding files matching exclusion blogs

- # Parameters:

- #  -i "<globs>" include shell globs (also takes all other macro arguments)

- #  -x "<globs>" exclude shell globs

- %listfiles(i:x:) %{expand:

- while IFS= read -r -d $'\\n' finc ; do

-   printf "%s\\n" %{?-x*} \\

-     | xargs -i realpath --relative-base=. '{}' \\

-     | grep "${finc}" >/dev/null || echo "${finc}"

- done <<< $(printf "%s\\n" %{?-i*} %* | xargs -i realpath --relative-base=. '{}' | sort -u)

- }

file modified
+2

@@ -40,6 +40,7 @@ 

  Source152: macros.vpath

  Source153: macros.forge

  Source154: macros.ldconfig

+ Source155: macros.fedora-misc

  

  # Build policy scripts

  # this comes from https://github.com/rpm-software-management/rpm/pull/344

@@ -177,6 +178,7 @@ 

  %{_rpmconfigdir}/macros.d/macros.forge

  %{_rpmconfigdir}/macros.d/macros.ldconfig

  %{_rpmconfigdir}/macros.d/macros.vpath

+ %{_rpmconfigdir}/macros.d/macros.fedora-misc

  %dir %{_rpmluadir}/fedora

  %dir %{_rpmluadir}/fedora/srpm

  %dir %{_rpmluadir}/fedora/rpm