7c4cd3
# Map forge information to rpm metadata. This macro will compute default spec
7c4cd3
# variable values.
7c4cd3
#
7c4cd3
# The following spec variables SHOULD be set before calling the macro:
7c4cd3
#
7c4cd3
#   forgeurl  the project url on the forge, strongly recommended;
7c4cd3
#   Version   if applicable, set it with Version: <version>
7c4cd3
#   tag       if applicable
7c4cd3
#   commit    if applicable
228332
#   date      if applicable (to override the mtime of the Source archive)
7c4cd3
#
c70110
#  Use -z for multiple calls to the macro
c70110
#
7c4cd3
# The macro will attempt to compute and set the following variables if they are
7c4cd3
# not already set by the packager:
7c4cd3
#
7c4cd3
#   forgesource    an URL that can be used as SourceX: value
7c4cd3
#   forgesetupargs the correct arguments to pass to %setup for this source
7c4cd3
#                  used by %forgesetup and %forgeautosetup
7c4cd3
#   archivename    the source archive filename, without extentions
7c4cd3
#   archiveext     the source archive filename extensions, without leading dot
7c4cd3
#   archiveurl     the url that can be used to download the source archive,
7c4cd3
#                  without renaming
c70110
#   topdir         the source archive top directory (can be empty)
c70110
#   extractdir     the source directory created inside %{_builddir} after using
c70110
#                  %%forgesetup, %forgeautosetup or %{forgesetupargs}
c70110
#   repo           the repository name
c70110
#   owner          the repository owner (if used by another computed variable)
c70110
#   shortcommit    the commit hash clamping used by the forge, if any
7c4cd3
#   scm            the scm type, when packaging code snapshots: commits or tags
c70110
#   distprefix     the prefix that needs adding to dist to trace non-release packaging
7c4cd3
#
c70110
# Most of the computed variables are both overridable and optional.
7c4cd3
#
7c4cd3
# Optional parameters:
c70110
#   -a          process all sources in one go, instead of using separate -z calls
c70110
#   -z <number> suffix all the read and written variable names with <number>
c70110
#               for example read     forgeurl<number>, version<number>…
c70110
#                       and generate forgesetupargs<number>, archiveurl<number>…
c70110
#               The macro assumes that null or nil suffix is used for the primary
c70110
#               package source.
7c4cd3
#   -s  Silently ignore problems in forgeurl, use it if it can be parsed,
7c4cd3
#       ignore it otherwise.
7c4cd3
#   -v  Be verbose and print every spec variable the macro sets.
7c4cd3
#   -i  Print some info about the state of spec variables the macro may use or
7c4cd3
#       set at the end of the processing.
c70110
%forgemeta(az:sviu:) %{lua:
c70110
local      fedora = require "fedora.common"
c70110
local       forge = require "fedora.srpm.forge"
c70110
local     verbose =  rpm.expand("%{-v}") ~= ""
c70110
local informative =  rpm.expand("%{-i}") ~= ""
c70110
local      silent =  rpm.expand("%{-s}") ~= ""
c70110
local  processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "")
c70110
if processall then
c70110
  for _,s in pairs(fedora.getsuffixes("forgeurl")) do
c70110
    forge.forgemeta(s,verbose,informative,silent)
7c4cd3
  end
c70110
else
c70110
  forge.forgemeta(rpm.expand("%{-z*}"),verbose,informative,silent)
7c4cd3
end
7c4cd3
}
7c4cd3
7c4cd3
# Convenience macro to relay computed arguments to %setup
c70110
# Optional parameters:
c70110
#   -a          process all sources in one go, instead of using separate -z calls
c70110
#   -z <number> read %{?forgesetupargs<number>}
c70110
#   -v          be verbose
c70110
%forgesetup(az:v) %{lua:
c70110
local fedora = require "fedora.common"
c70110
if (rpm.expand("%{-z}") == "") and (rpm.expand("%{-a}") ~= "") then
c70110
  for _,s in pairs(fedora.getsuffixes("forgesetupargs")) do
c70110
    print(rpm.expand("%setup %{!-v:-q} %{?forgesetupargs" .. s                     .. "}\\n"))
c70110
  end
c70110
else
c70110
  print(  rpm.expand("%setup %{!-v:-q} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n"))
c70110
end
c70110
}
7c4cd3
7c4cd3
# Convenience macro to relay computed arguments to %autosetup
c70110
# Parameters relayed to %autosetup: -v -N -S -p
c70110
# Optional parameters:
c70110
#   -z <number> read %{?forgesetupargs<number>}
8ba2a6
%forgeautosetup(z:vNS:p:q) %{lua:
c70110
print(rpm.expand("%autosetup %{-v} %{-N} %{?-S} %{?-p} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n"))
c70110
}
c70110
c70110
# List files matching inclusion globs, excluding files matching exclusion blogs
c70110
# Parameters:
c70110
#  -i "<globs>" include shell globs (also takes all other macro arguments)
c70110
#  -x "<globs>" exclude shell globs
c70110
%listfiles(i:x:) %{expand:
c70110
while IFS= read -r -d $'\\n' finc ; do
c70110
  printf "%s\\n" %{?-x*} \\
c70110
    | xargs -i realpath --relative-base=. '{}' \\
c70110
    | grep "${finc}" >/dev/null || echo "${finc}"
c70110
done <<< $(printf "%s\\n" %{?-i*} %* | xargs -i realpath --relative-base=. '{}' | sort -u)
c70110
}