common: add a writevars helper
This commit is contained in:
parent
353f8b9faf
commit
5335ee546b
16
common.lua
16
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,
|
||||
}
|
||||
|
30
macros.fedora-misc
Normal file
30
macros.fedora-misc
Normal file
@ -0,0 +1,30 @@
|
||||
# Some miscellaneous Fedora-related macros
|
||||
|
||||
# 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)
|
||||
}
|
||||
|
||||
# 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)
|
||||
}
|
12
macros.forge
12
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 "<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)
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user