diff --git a/common.lua b/common.lua index 49cba0c..710da31 100644 --- a/common.lua +++ b/common.lua @@ -13,20 +13,20 @@ local function read(rpmvar) end -- Returns true if the macro that called this function had flag set --- For example, hasflag("z") would give the following results: --- %foo -z bar → true --- %foo -z → true --- %foo → false +-- – for example, hasflag("z") would give the following results: +-- %foo -z bar → true +-- %foo -z → true +-- %foo → false local function hasflag(flag) return (rpm.expand("%{-" .. flag .. "}") ~= "") end -- Returns the argument passed to flag in the macro that called this function --- For example, readflag("z") would give the following results: --- %foo -z bar → bar --- %foo → nil --- %foo -z "" → empty string --- %foo -z '' → empty string +-- – for example, readflag("z") would give the following results: +-- %foo -z bar → bar +-- %foo → nil +-- %foo -z "" → empty string +-- %foo -z '' → empty string local function readflag(flag) if not hasflag(flag) then return nil @@ -40,8 +40,7 @@ local function readflag(flag) end end --- Set a spec variable --- Echo the result if verbose +-- Sets a spec variable; echoes the result if verbose local function explicitset(rpmvar, value, verbose) local value = value if (value == nil) or (value == "") then @@ -53,8 +52,7 @@ local function explicitset(rpmvar, value, verbose) end end --- Unset a spec variable if it is defined --- Echo the result if verbose +-- Unsets a spec variable if it is defined; echoes the result if verbose local function explicitunset(rpmvar, verbose) if (rpm.expand("%{" .. rpmvar .. "}") ~= "%{" .. rpmvar .. "}") then rpm.define(rpmvar .. " %{nil}") @@ -64,16 +62,15 @@ local function explicitunset(rpmvar, verbose) end end --- Set a spec variable, if not already set --- Echo the result if verbose +-- Sets a spec variable, if not already set; echoes the result if verbose local function safeset(rpmvar, value, verbose) if (rpm.expand("%{" .. rpmvar .. "}") == "%{" .. rpmvar .. "}") then explicitset(rpmvar,value,verbose) end end --- Alias a list of rpm variables to the same variables suffixed with 0 (and vice versa) --- Echo the result if verbose +-- Aliases a list of rpm variables to the same variables suffixed with 0 (and +-- vice versa); echoes the result if verbose local function zalias(rpmvars, verbose) for _, sfx in ipairs({{"","0"},{"0",""}}) do for _, rpmvar in ipairs(rpmvars) do @@ -153,13 +150,7 @@ 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 +-- %writevars core local function writevars(macrofile, rpmvars) for _, rpmvar in ipairs(rpmvars) do print("sed -i 's\029" .. string.upper("@@" .. rpmvar .. "@@") .. @@ -243,7 +234,7 @@ Summary: %{source_summary} set("currentname", "%{source_name}", verbose) end --- The processing core of %new_package +-- %new_package core local function new_package(source_name, pkg_name, name_suffix, first, verbose) -- Safety net when the wrapper is used in conjunction with traditional syntax if (not first) and (not source_name) then diff --git a/macros.fedora-misc b/macros.fedora-misc index df96ba5..82286f3 100644 --- a/macros.fedora-misc +++ b/macros.fedora-misc @@ -1,16 +1,16 @@ -# Some miscellaneous Fedora-related macros +# Fedora macros, safe to use after the SRPM build stage -# List files matching inclusion globs, excluding files matching exclusion blogs -# Optional parameters: -# – -i "" inclusion globs -# – -x "" exclusion globs -# Globs are space-separated lists of shell globs. Such lists require %{quote:} -# use for safe rpm argument passing. -# Alternatively, set the following rpm variables before calling the macro: -# – “listfiles_include” inclusion globs -# — “listfiles_exclude” exclusion globs -# Arguments passed to the macro without flags will be interpreted as inclusion -# globs. +# Lists files matching inclusion globs, excluding files matching exclusion +# globs +# – globs are space-separated lists of shell globs. Such lists require +# %{quote:} use when passed as rpm arguments or flags. +# Control variables, flags and arguments: +# %{listfiles_include} inclusion globs +# %{listfiles_exclude} exclusion globs +# -i inclusion globs +# -x exclusion globs +# … arguments passed to the macro without flags will be +# interpreted as inclusion globs %listfiles(i:x:) %{expand: %if %{lua: print(string.len(rpm.expand("%{?-i*}%{?listfiles_include}%*")))} listfiles_include=$(realpath -e --relative-base=. %{?-i*} %{?listfiles_include} %* | sort -u) @@ -26,12 +26,14 @@ } # 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 +# Writes the contents of a list of rpm variables to a macro file +# Control variables, flags and arguments: +# -f the macro file to process: +# – it must contain 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*}") diff --git a/macros.fedora-misc-srpm b/macros.fedora-misc-srpm index c553f83..f3ac0ce 100644 --- a/macros.fedora-misc-srpm +++ b/macros.fedora-misc-srpm @@ -1,5 +1,4 @@ -# Some miscellaneous Fedora-related macros, intended to be used at rpmbuild -bs -# stage +# Fedora macros, safe to use at SRPM build stage # A directory for rpm macros %rpmmacrodir /usr/lib/rpm/macros.d @@ -11,41 +10,28 @@ # A directory for SWID tag files describing the installation %_swidtagdir %{_prefix}/lib/swidtag/fedoraproject.org -# A helper to apply the fedora.wordwrap filter to the content of an rpm -# variable, and print the result. Optional parameter: -# – -v (default value: _description) -# Putting multiple lines of UTF-8 text inside a variable is usually -# accomplished with a %%{expand: some_text}. +# Applies the fedora.wordwrap filter to the content of an rpm variable, and +# prints the result. +# – putting multiple lines of UTF-8 text inside a variable is usually +# accomplished with %{expand:some_text} +# Control variables, flags and arguments: +# -v (default value: _description) %wordwrap(v:) %{lua: local fedora = require "fedora.common" -local variable = "%{" .. rpm.expand("%{-v*}%{!-v:_description}") .. "}" +local variable = "%{?" .. rpm.expand("%{-v*}%{!-v:_description}") .. "}" print(fedora.wordwrap(variable)) } -# A wrapper around Name: and %package that abstracts their quirks from -# packagers and macros. Its behavior is controled by the %{source_name} -# global variable: -# – when %{source_name} is not set, the first call to %new_package will -# create a Name: block and set %{source_name} to the %{name} of this -# block. -# – when %{source_name} is set: -# – a call to %new_package with no arguments creates: -# Name: %{source_name} -# – otherwise, a call to %new_package creates the corresponding: -# %package… -# line, unless the resulting %{name} matches %{source_name}. In that -# case it creates -# Name: %{source_name} -# as before. -# Arguments: -# – -n and %1 like %package -# – -v to print the variables %new_package sets directly. -# The intended use-case it to simplify coordination between macros that -# create subpackages, make it easy for packagers to declare which of the -# macro-created packages owns the SRPM, and make %{source_name} available -# within spec files and not just as a dnf synthetic variable. -# Unlike %{name} %{source_name} matches the SRPM name regardless of its -# location within the spec file. +# A single Name: and %package substitute +# Control variables, flags and arguments: +# %{source_name} the SRPM name +# %{source_summary} the SRPM summary +# %{source_description} the SRPM description +# -n declare a package named +# (%package-like behavior) +# -v be verbose +# %1 declare a package named %{source_name}-%{%1} +# (%package-like behavior) %new_package(n:v) %{lua: local fedora = require "fedora.common" local pkg_name = fedora.readflag("n") diff --git a/macros.forge b/macros.forge index e1c3ed2..efd7327 100644 --- a/macros.forge +++ b/macros.forge @@ -1,50 +1,28 @@ -# Map forge information to rpm metadata. This macro will compute default spec -# variable values. -# -# The following spec variables SHOULD be set before calling the macro: -# -# forgeurl the project url on the forge, strongly recommended; -# Version if applicable, set it with Version: -# tag if applicable -# commit if applicable -# date if applicable (to override the mtime of the Source archive) -# -# Use -z for multiple calls to the macro -# -# The macro will attempt to compute and set the following variables if they are -# not already set by the packager: -# -# forgesource an URL that can be used as SourceX: value -# forgesetupargs the correct arguments to pass to %setup for this source -# used by %forgesetup and %forgeautosetup -# archivename the source archive filename, without extentions -# archiveext the source archive filename extensions, without leading dot -# archiveurl the url that can be used to download the source archive, -# without renaming -# topdir the source archive top directory (can be empty) -# extractdir the source directory created inside %{_builddir} after using -# %%forgesetup, %forgeautosetup or %{forgesetupargs} -# repo the repository name -# owner the repository owner (if used by another computed variable) -# shortcommit the commit hash clamping used by the forge, if any -# scm the scm type, when packaging code snapshots: commits or tags -# distprefix the prefix that needs adding to dist to trace non-release packaging -# -# Most of the computed variables are both overridable and optional. -# -# Optional parameters: -# -a process all sources in one go, instead of using separate -z calls -# -z suffix all the read and written variable names with -# for example read forgeurl, version… -# and generate forgesetupargs, archiveurl… -# The macro assumes that null or nil suffix is used for the primary -# package source. -# -s Silently ignore problems in forgeurl, use it if it can be parsed, -# ignore it otherwise. -# -v Be verbose and print every spec variable the macro sets. -# -i Print some info about the state of spec variables the macro may use or -# set at the end of the processing. -%forgemeta(az:sviu:) %{lua: +# 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}") ~= "" @@ -60,12 +38,17 @@ else end } -# Convenience macro to relay computed arguments to %setup -# Optional parameters: -# -a process all sources in one go, instead of using separate -z calls -# -z read %{?forgesetupargs} -# -v be verbose -%forgesetup(az:v) %{lua: +# 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 @@ -76,10 +59,12 @@ else end } -# Convenience macro to relay computed arguments to %autosetup -# Parameters relayed to %autosetup: -v -N -S -p -# Optional parameters: -# -z read %{?forgesetupargs} +# 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")) }