clean up macro and lua function documentation
This commit is contained in:
parent
0cb7566d95
commit
166707b501
27
common.lua
27
common.lua
@ -13,7 +13,7 @@ local function read(rpmvar)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Returns true if the macro that called this function had flag set
|
-- Returns true if the macro that called this function had flag set
|
||||||
-- For example, hasflag("z") would give the following results:
|
-- – for example, hasflag("z") would give the following results:
|
||||||
-- %foo -z bar → true
|
-- %foo -z bar → true
|
||||||
-- %foo -z → true
|
-- %foo -z → true
|
||||||
-- %foo → false
|
-- %foo → false
|
||||||
@ -22,7 +22,7 @@ local function hasflag(flag)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Returns the argument passed to flag in the macro that called this function
|
-- Returns the argument passed to flag in the macro that called this function
|
||||||
-- For example, readflag("z") would give the following results:
|
-- – for example, readflag("z") would give the following results:
|
||||||
-- %foo -z bar → bar
|
-- %foo -z bar → bar
|
||||||
-- %foo → nil
|
-- %foo → nil
|
||||||
-- %foo -z "" → empty string
|
-- %foo -z "" → empty string
|
||||||
@ -40,8 +40,7 @@ local function readflag(flag)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set a spec variable
|
-- Sets a spec variable; echoes the result if verbose
|
||||||
-- Echo the result if verbose
|
|
||||||
local function explicitset(rpmvar, value, verbose)
|
local function explicitset(rpmvar, value, verbose)
|
||||||
local value = value
|
local value = value
|
||||||
if (value == nil) or (value == "") then
|
if (value == nil) or (value == "") then
|
||||||
@ -53,8 +52,7 @@ local function explicitset(rpmvar, value, verbose)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Unset a spec variable if it is defined
|
-- Unsets a spec variable if it is defined; echoes the result if verbose
|
||||||
-- Echo the result if verbose
|
|
||||||
local function explicitunset(rpmvar, verbose)
|
local function explicitunset(rpmvar, verbose)
|
||||||
if (rpm.expand("%{" .. rpmvar .. "}") ~= "%{" .. rpmvar .. "}") then
|
if (rpm.expand("%{" .. rpmvar .. "}") ~= "%{" .. rpmvar .. "}") then
|
||||||
rpm.define(rpmvar .. " %{nil}")
|
rpm.define(rpmvar .. " %{nil}")
|
||||||
@ -64,16 +62,15 @@ local function explicitunset(rpmvar, verbose)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set a spec variable, if not already set
|
-- Sets a spec variable, if not already set; echoes the result if verbose
|
||||||
-- Echo the result if verbose
|
|
||||||
local function safeset(rpmvar, value, verbose)
|
local function safeset(rpmvar, value, verbose)
|
||||||
if (rpm.expand("%{" .. rpmvar .. "}") == "%{" .. rpmvar .. "}") then
|
if (rpm.expand("%{" .. rpmvar .. "}") == "%{" .. rpmvar .. "}") then
|
||||||
explicitset(rpmvar,value,verbose)
|
explicitset(rpmvar,value,verbose)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Alias a list of rpm variables to the same variables suffixed with 0 (and vice versa)
|
-- Aliases a list of rpm variables to the same variables suffixed with 0 (and
|
||||||
-- Echo the result if verbose
|
-- vice versa); echoes the result if verbose
|
||||||
local function zalias(rpmvars, verbose)
|
local function zalias(rpmvars, verbose)
|
||||||
for _, sfx in ipairs({{"","0"},{"0",""}}) do
|
for _, sfx in ipairs({{"","0"},{"0",""}}) do
|
||||||
for _, rpmvar in ipairs(rpmvars) do
|
for _, rpmvar in ipairs(rpmvars) do
|
||||||
@ -153,13 +150,7 @@ local function getbestsuffix(rpmvar, value)
|
|||||||
return best
|
return best
|
||||||
end
|
end
|
||||||
|
|
||||||
-- https://github.com/rpm-software-management/rpm/issues/581
|
-- %writevars core
|
||||||
-- 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
|
|
||||||
local function writevars(macrofile, rpmvars)
|
local function writevars(macrofile, rpmvars)
|
||||||
for _, rpmvar in ipairs(rpmvars) do
|
for _, rpmvar in ipairs(rpmvars) do
|
||||||
print("sed -i 's\029" .. string.upper("@@" .. rpmvar .. "@@") ..
|
print("sed -i 's\029" .. string.upper("@@" .. rpmvar .. "@@") ..
|
||||||
@ -243,7 +234,7 @@ Summary: %{source_summary}
|
|||||||
set("currentname", "%{source_name}", verbose)
|
set("currentname", "%{source_name}", verbose)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- The processing core of %new_package
|
-- %new_package core
|
||||||
local function new_package(source_name, pkg_name, name_suffix, first, verbose)
|
local function new_package(source_name, pkg_name, name_suffix, first, verbose)
|
||||||
-- Safety net when the wrapper is used in conjunction with traditional syntax
|
-- Safety net when the wrapper is used in conjunction with traditional syntax
|
||||||
if (not first) and (not source_name) then
|
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
|
# Lists files matching inclusion globs, excluding files matching exclusion
|
||||||
# Optional parameters:
|
# globs
|
||||||
# – -i "<globs>" inclusion globs
|
# – globs are space-separated lists of shell globs. Such lists require
|
||||||
# – -x "<globs>" exclusion globs
|
# %{quote:} use when passed as rpm arguments or flags.
|
||||||
# Globs are space-separated lists of shell globs. Such lists require %{quote:}
|
# Control variables, flags and arguments:
|
||||||
# use for safe rpm argument passing.
|
# %{listfiles_include} inclusion globs
|
||||||
# Alternatively, set the following rpm variables before calling the macro:
|
# %{listfiles_exclude} exclusion globs
|
||||||
# – “listfiles_include” inclusion globs
|
# -i <globs> inclusion globs
|
||||||
# — “listfiles_exclude” exclusion globs
|
# -x <globs> exclusion globs
|
||||||
# Arguments passed to the macro without flags will be interpreted as inclusion
|
# … arguments passed to the macro without flags will be
|
||||||
# globs.
|
# interpreted as inclusion globs
|
||||||
%listfiles(i:x:) %{expand:
|
%listfiles(i:x:) %{expand:
|
||||||
%if %{lua: print(string.len(rpm.expand("%{?-i*}%{?listfiles_include}%*")))}
|
%if %{lua: print(string.len(rpm.expand("%{?-i*}%{?listfiles_include}%*")))}
|
||||||
listfiles_include=$(realpath -e --relative-base=. %{?-i*} %{?listfiles_include} %* | sort -u)
|
listfiles_include=$(realpath -e --relative-base=. %{?-i*} %{?listfiles_include} %* | sort -u)
|
||||||
@ -26,9 +26,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
# https://github.com/rpm-software-management/rpm/issues/581
|
# https://github.com/rpm-software-management/rpm/issues/581
|
||||||
# Write the contents of a list of rpm variables to a macro file.
|
# Writes the contents of a list of rpm variables to a macro file
|
||||||
# The target file must contain the corresponding anchors.
|
# Control variables, flags and arguments:
|
||||||
# For example %writevars -f myfile foo bar will replace:
|
# -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
|
# @@FOO@@ with the rpm evaluation of %{foo} and
|
||||||
# @@BAR@@ with the rpm evaluation of %{bar}
|
# @@BAR@@ with the rpm evaluation of %{bar}
|
||||||
# in myfile
|
# in myfile
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
# Some miscellaneous Fedora-related macros, intended to be used at rpmbuild -bs
|
# Fedora macros, safe to use at SRPM build stage
|
||||||
# stage
|
|
||||||
|
|
||||||
# A directory for rpm macros
|
# A directory for rpm macros
|
||||||
%rpmmacrodir /usr/lib/rpm/macros.d
|
%rpmmacrodir /usr/lib/rpm/macros.d
|
||||||
@ -11,41 +10,28 @@
|
|||||||
# A directory for SWID tag files describing the installation
|
# A directory for SWID tag files describing the installation
|
||||||
%_swidtagdir %{_prefix}/lib/swidtag/fedoraproject.org
|
%_swidtagdir %{_prefix}/lib/swidtag/fedoraproject.org
|
||||||
|
|
||||||
# A helper to apply the fedora.wordwrap filter to the content of an rpm
|
# Applies the fedora.wordwrap filter to the content of an rpm variable, and
|
||||||
# variable, and print the result. Optional parameter:
|
# prints the result.
|
||||||
# – -v <variable_name> (default value: _description)
|
# – putting multiple lines of UTF-8 text inside a variable is usually
|
||||||
# Putting multiple lines of UTF-8 text inside a variable is usually
|
# accomplished with %{expand:some_text}
|
||||||
# accomplished with a %%{expand: some_text}.
|
# Control variables, flags and arguments:
|
||||||
|
# -v <variable_name> (default value: _description)
|
||||||
%wordwrap(v:) %{lua:
|
%wordwrap(v:) %{lua:
|
||||||
local fedora = require "fedora.common"
|
local fedora = require "fedora.common"
|
||||||
local variable = "%{" .. rpm.expand("%{-v*}%{!-v:_description}") .. "}"
|
local variable = "%{?" .. rpm.expand("%{-v*}%{!-v:_description}") .. "}"
|
||||||
print(fedora.wordwrap(variable))
|
print(fedora.wordwrap(variable))
|
||||||
}
|
}
|
||||||
|
|
||||||
# A wrapper around Name: and %package that abstracts their quirks from
|
# A single Name: and %package substitute
|
||||||
# packagers and macros. Its behavior is controled by the %{source_name}
|
# Control variables, flags and arguments:
|
||||||
# global variable:
|
# %{source_name} the SRPM name
|
||||||
# – when %{source_name} is not set, the first call to %new_package will
|
# %{source_summary} the SRPM summary
|
||||||
# create a Name: block and set %{source_name} to the %{name} of this
|
# %{source_description} the SRPM description
|
||||||
# block.
|
# -n <name> declare a package named <name>
|
||||||
# – when %{source_name} is set:
|
# (%package-like behavior)
|
||||||
# – a call to %new_package with no arguments creates:
|
# -v be verbose
|
||||||
# Name: %{source_name}
|
# %1 declare a package named %{source_name}-%{%1}
|
||||||
# – otherwise, a call to %new_package creates the corresponding:
|
# (%package-like behavior)
|
||||||
# %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.
|
|
||||||
%new_package(n:v) %{lua:
|
%new_package(n:v) %{lua:
|
||||||
local fedora = require "fedora.common"
|
local fedora = require "fedora.common"
|
||||||
local pkg_name = fedora.readflag("n")
|
local pkg_name = fedora.readflag("n")
|
||||||
|
97
macros.forge
97
macros.forge
@ -1,50 +1,28 @@
|
|||||||
# Map forge information to rpm metadata. This macro will compute default spec
|
# Computes forge-related variables for use in the rest of the spec file
|
||||||
# variable values.
|
# Control variables, flags and arguments:
|
||||||
#
|
# %{forgeurl<number>} the project url on the target forge
|
||||||
# The following spec variables SHOULD be set before calling the macro:
|
# %{tag<number>} the packaged tag, OR
|
||||||
#
|
# %{commit<number>} the packaged commit, OR
|
||||||
# forgeurl the project url on the forge, strongly recommended;
|
# %{version<number>} the packaged version
|
||||||
# Version if applicable, set it with Version: <version>
|
# – %{version}/%{version0} are set via:
|
||||||
# tag if applicable
|
# Version:
|
||||||
# commit if applicable
|
# – because git is lacking a built-in version
|
||||||
# date if applicable (to override the mtime of the Source archive)
|
# reference, %{version<number>} will be translated
|
||||||
#
|
# into %{tag<number>} using unreliable heuristics;
|
||||||
# Use -z for multiple calls to the macro
|
# set %{tag<number>} directly if those fail
|
||||||
#
|
# %{date<number>} the packaged timestamp
|
||||||
# The macro will attempt to compute and set the following variables if they are
|
# … %forgemeta will compute a huge number of variables:
|
||||||
# not already set by the packager:
|
# — the packager can override it by setting some of
|
||||||
#
|
# those before the %forgemeta call
|
||||||
# forgesource an URL that can be used as SourceX: value
|
# – use the -i flag to list those variables
|
||||||
# forgesetupargs the correct arguments to pass to %setup for this source
|
# -z <number> only process the zth block of definitions
|
||||||
# used by %forgesetup and %forgeautosetup
|
# "" for the no-suffix block
|
||||||
# archivename the source archive filename, without extentions
|
# -i list the resulting variable values
|
||||||
# archiveext the source archive filename extensions, without leading dot
|
# -s silently ignore problems in %{forgeurl<number>}
|
||||||
# archiveurl the url that can be used to download the source archive,
|
# -v be verbose
|
||||||
# without renaming
|
# -a process all sources in one go, instead of using
|
||||||
# topdir the source archive top directory (can be empty)
|
# separate -z calls
|
||||||
# extractdir the source directory created inside %{_builddir} after using
|
%forgemeta(z:isva) %{lua:
|
||||||
# %%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:
|
|
||||||
local fedora = require "fedora.common"
|
local fedora = require "fedora.common"
|
||||||
local forge = require "fedora.srpm.forge"
|
local forge = require "fedora.srpm.forge"
|
||||||
local verbose = rpm.expand("%{-v}") ~= ""
|
local verbose = rpm.expand("%{-v}") ~= ""
|
||||||
@ -60,12 +38,17 @@ else
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
# Convenience macro to relay computed arguments to %setup
|
# Unpacks sources computed by %forgemeta
|
||||||
# Optional parameters:
|
# Control variables, flags and arguments:
|
||||||
# -a process all sources in one go, instead of using separate -z calls
|
# %{forgesource<number>} the source archive that will be processed
|
||||||
# -z <number> read %{?forgesetupargs<number>}
|
# %{forgesetupargs<number>} %setup arguments
|
||||||
|
|
||||||
|
# -z <number> only process the zth block of definitions
|
||||||
|
# "" for the no-suffix block
|
||||||
# -v be verbose
|
# -v be verbose
|
||||||
%forgesetup(az:v) %{lua:
|
# -a process all sources in one go, instead of using
|
||||||
|
# separate -z calls
|
||||||
|
%forgesetup(z:va) %{lua:
|
||||||
local fedora = require "fedora.common"
|
local fedora = require "fedora.common"
|
||||||
if (rpm.expand("%{-z}") == "") and (rpm.expand("%{-a}") ~= "") then
|
if (rpm.expand("%{-z}") == "") and (rpm.expand("%{-a}") ~= "") then
|
||||||
for _,s in pairs(fedora.getsuffixes("forgesetupargs")) do
|
for _,s in pairs(fedora.getsuffixes("forgesetupargs")) do
|
||||||
@ -76,10 +59,12 @@ else
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
# Convenience macro to relay computed arguments to %autosetup
|
# Calls %autosetup using %forgemeta results
|
||||||
# Parameters relayed to %autosetup: -v -N -S -p
|
# – this will probably be removed since it is unsafe in presence of multiple
|
||||||
# Optional parameters:
|
# sources
|
||||||
# -z <number> read %{?forgesetupargs<number>}
|
# 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:
|
%forgeautosetup(z:vNS:p:q) %{lua:
|
||||||
print(rpm.expand("%autosetup %{-v} %{-N} %{?-S} %{?-p} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n"))
|
print(rpm.expand("%autosetup %{-v} %{-N} %{?-S} %{?-p} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user