# 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} the project url on the target forge # %{tag} the packaged tag, OR # %{commit} the packaged commit, OR # %{version} the packaged version # – %{version}/%{version0} are set via: # Version: # – because git is lacking a built-in version # reference, %{version} will be translated # into %{tag} using unreliable heuristics; # set %{tag} directly if those fail # %{date} 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 only process the zth block of definitions # "" for the no-suffix block # -i list the resulting variable values # -s silently ignore problems in %{forgeurl} # -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 # Control variables, flags and arguments: # %{forgesource} the source archive that will be processed # %{forgesetupargs} %setup arguments # -z 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 # – this will probably be removed since it is unsafe in presence of multiple # sources # Control variables, flags and arguments: # -z 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 that %forgemeta sets # to Version. # This follows the new Versioning Guidelines that discourage putting release # snapshot info in Release. # # If no %forgeversionsuffix 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 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 # %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 \ -- Release uses %dist and %distprefix, so we need to make sure it's not used before if util.is_defined("release") then rpm.expand( "%{warn:'Version: %%forgeversion' must be invoked before setting Release.}" ) 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 ) 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 "") end \ -- Strip any leading '.' part = part:gsub("^%.", "") \ -- Print final version if part ~= "" then print(baseversion .. sep .. part) else print(baseversion) end }