diff --git a/common.lua b/common.lua index 92924c6..1191c1f 100644 --- a/common.lua +++ b/common.lua @@ -113,6 +113,21 @@ local function getbestsuffix(rpmvar, value) 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, @@ -123,4 +138,5 @@ return { getsuffixed = getsuffixed, getsuffixes = getsuffixes, getbestsuffix = getbestsuffix, + writevars = writevars, } diff --git a/macros.fedora-misc b/macros.fedora-misc new file mode 100644 index 0000000..ca54197 --- /dev/null +++ b/macros.fedora-misc @@ -0,0 +1,30 @@ +# Some miscellaneous Fedora-related macros + +# List files matching inclusion globs, excluding files matching exclusion blogs +# Parameters: +# -i "" include shell globs (also takes all other macro arguments) +# -x "" 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) +} + +# 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) +} diff --git a/macros.forge b/macros.forge index 167d2ed..e1c3ed2 100644 --- a/macros.forge +++ b/macros.forge @@ -83,15 +83,3 @@ end %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 "" include shell globs (also takes all other macro arguments) -# -x "" 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) -} diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index b9735f6..205cf5a 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -40,6 +40,7 @@ Source151: macros.kmp 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 @@ install -p -m 644 -t %{buildroot}%{_rpmluadir}/fedora/srpm forge.lua %{_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