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