# SPDX-License-Identifier: GPL-1.0-or-later
# Copyright (C) 2018-2020 redhat-rpm-config contributors
# Computes forge-related variables for use in the rest of the spec file
# Control variables, flags and arguments:
# %{forgeurl<number>} the project url on the target forge
# %{tag<number>} the packaged tag, OR
# %{commit<number>} the packaged commit, OR
# %{version<number>} the packaged version
# – %{version}/%{version0} are set via:
# Version:
# – because git is lacking a built-in version
# reference, %{version<number>} will be translated
# into %{tag<number>} using unreliable heuristics;
# set %{tag<number>} directly if those fail
# %{date<number>} the packaged timestamp
# … %forgemeta will compute a huge number of variables:
# — the packager can override it by setting some of
# those before the %forgemeta call
# – use the -i flag to list those variables
# -z <number> only process the zth block of definitions
# "" for the no-suffix block
# -i list the resulting variable values
# -s silently ignore problems in %{forgeurl<number>}
# -v be verbose
# -a process all sources in one go, instead of using
# separate -z calls
%forgemeta(z:isva) %{lua:
local fedora = require "fedora.common"
local forge = require "fedora.srpm.forge"
local verbose = rpm.expand("%{-v}") ~= ""
local informative = rpm.expand("%{-i}") ~= ""
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.meta(s,verbose,informative,silent)
end
else
forge.meta(rpm.expand("%{-z*}"),verbose,informative,silent)
end
}
# Unpacks sources computed by %forgemeta
# - In most cases, it is recommended to instead use `%forgeautosetup -p1` so
# patches are automatically applied.
# Control variables, flags and arguments:
# %{forgesource<number>} the source archive that will be processed
# %{forgesetupargs<number>} %setup arguments
# -z <number> only process the zth block of definitions
# "" for the no-suffix block
# -v be verbose
# -a process all sources in one go, instead of using
# separate -z calls
%forgesetup(z:va) %{lua:
local fedora = require "fedora.common"
if (rpm.expand("%{-z}") == "") and (rpm.expand("%{-a}") ~= "") then
for _,s in pairs(fedora.getsuffixes("forgesetupargs")) do
print(rpm.expand("%setup %{!-v:-q} %{?forgesetupargs" .. s .. "}\\n"))
end
else
print( rpm.expand("%setup %{!-v:-q} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n"))
end
}
# Calls %autosetup using %forgemeta results
# – Using %forgeautosetup is not recommended in specfiles with multiple
# %forgeurl definitions,
# as %autosetup may produce strange results with multiple sources present.
# If you have have muiltiple sources,
# you can use `%forgesetup -a` to unpack them all at once and then apply
# patches manually using the %patch macro.
# Control variables, flags and arguments:
# -z <number> process the zth block of definitions
# -v -N -S -p relayed to %autosetup
%forgeautosetup(z:vNS:p:q) %{lua:
print(rpm.expand("%autosetup %{-v} %{-N} %{?-S} %{?-p} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n"))
}
# Appends the values of %_forgeversionsuffix<number> that %forgemeta sets
# to Version.
# This follows the new Versioning Guidelines that discourage putting release
# snapshot info in Release.
#
# NOTE: %forgeversion MUST be invoked before setting Release.
#
# If no %forgeversionsuffix<number> is set,
# the value is equivalent to %version.
#
# By default, %version and the suffix are separated with a '^'.
#
# Control variables, flags and arguments:
# -p Use the pre-release separator '~' instead of '^'
# -z <number> Only add the release suffix for a specific block.
# By default, -z0 is used.
# -a Concatenate the release suffixes for all blocks
# -b Base version to use. Defaults to %version0
# For example:
# %global forgeurl https://github.com/foo/bar
# %global version0 2.15.0
# %global commit <POST RELEASE SNAPSHOT>
# %forgemeta
# [....]
# Version: %{forgeversion}
%forgeversion(pz:ab:) %{lua:
local fedora = require "fedora.common"
local util = require "fedora.srpm._forge_util"
\
-- Zero-alias version/version0 macros
fedora.zalias({"version", "distprefix", "_forgeversionsuffix"}, nil)
\
-- Determine the seperator
local sep = "^"
if util.get_flag("p") then
sep = "~"
end
\
-- Determine baseversion
local baseversion = util.get_flag("b", true) or util.get_macro("version0")
if not baseversion then
rpm.expand(
"%{error:You must define %%version0" ..
" (%%global version0 <VERSION>) prior to invoking this macro.}"
)
end
\
-- Concatenate parts. Clear out %distprefix* to avoid duplicating data in Release.
-- forgemeta stores the same values in _forgeversionsuffix so we can run
-- forgeversion multiple times.
local part = ""
rpm.undefine("distprefix")
if util.get_flag("a") then
for i=0,9999 do
local curpart = util.get_macro("_forgeversionsuffix" .. i)
if curpart then
part = part .. curpart
end
rpm.undefine("distprefix" .. i)
end
else
local i = util.get_flag("z", true) or ""
part = part .. (util.get_macro("_forgeversionsuffix" .. i) or "")
-- Regardless of whether -a is used, undefine all other distprefixes to avoid
-- extra information in Release when forgeversion is already used.
-- See https://bugzilla.redhat.com/show_bug.cgi?id=2359090.
for i=0,9999 do
rpm.undefine("distprefix" .. i)
end
end
\
-- Strip any leading '.'
part = part:gsub("^%.", "")
\
-- Print final version
if part ~= "" then
print(baseversion .. sep .. part)
else
print(baseversion)
end
}