clean up macro and lua function documentation
This commit is contained in:
parent
0cb7566d95
commit
166707b501
41
common.lua
41
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
|
||||
|
@ -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 "<globs>" inclusion globs
|
||||
# – -x "<globs>" 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 <globs> inclusion globs
|
||||
# -x <globs> 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 <filename> 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*}")
|
||||
|
@ -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 <variable_name> (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 <variable_name> (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 <name> declare a package named <name>
|
||||
# (%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")
|
||||
|
99
macros.forge
99
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: <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 <number> suffix all the read and written variable names with <number>
|
||||
# for example read forgeurl<number>, version<number>…
|
||||
# and generate forgesetupargs<number>, archiveurl<number>…
|
||||
# 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<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}") ~= ""
|
||||
@ -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 <number> read %{?forgesetupargs<number>}
|
||||
# -v be verbose
|
||||
%forgesetup(az:v) %{lua:
|
||||
# Unpacks sources computed by %forgemeta
|
||||
# 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
|
||||
@ -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 <number> read %{?forgesetupargs<number>}
|
||||
# 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 <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"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user