|
|
a008c1 |
# Map forge information to rpm metadata. This macro will compute default spec
|
|
|
a008c1 |
# variable values.
|
|
|
a008c1 |
#
|
|
|
a008c1 |
# The following spec variables SHOULD be set before calling the macro:
|
|
|
a008c1 |
#
|
|
|
a008c1 |
# forgeurl the project url on the forge, strongly recommended;
|
|
|
a008c1 |
# alternatively, use -u <url>
|
|
|
a008c1 |
# Version if applicable, set it with Version: <version>
|
|
|
a008c1 |
# tag if applicable
|
|
|
a008c1 |
# commit if applicable
|
|
|
a008c1 |
#
|
|
|
a008c1 |
# The macro will attempt to compute and set the following variables if they are
|
|
|
a008c1 |
# not already set by the packager:
|
|
|
a008c1 |
#
|
|
|
a008c1 |
# forgesource an URL that can be used as SourceX: value
|
|
|
a008c1 |
# forgesetupargs the correct arguments to pass to %setup for this source
|
|
|
a008c1 |
# used by %forgesetup and %forgeautosetup
|
|
|
a008c1 |
# archivename the source archive filename, without extentions
|
|
|
a008c1 |
# archiveext the source archive filename extensions, without leading dot
|
|
|
a008c1 |
# archiveurl the url that can be used to download the source archive,
|
|
|
a008c1 |
# without renaming
|
|
|
a008c1 |
# scm the scm type, when packaging code snapshots: commits or tags
|
|
|
a008c1 |
#
|
|
|
a008c1 |
# If the macro is unable to parse your forgeurl value set at least archivename
|
|
|
a008c1 |
# and archiveurl before calling it.
|
|
|
a008c1 |
#
|
|
|
a008c1 |
# Most of the computed variables are both overridable and optional. However,
|
|
|
a008c1 |
# the macro WILL REDEFINE %{dist} when packaging a snapshot (commit or tag).
|
|
|
a008c1 |
# The previous %{dist} value will be lost. Don’t call the macro if you don’t
|
|
|
a008c1 |
# wish %{dist} to be changed.
|
|
|
a008c1 |
#
|
|
|
a008c1 |
# Optional parameters:
|
|
|
a008c1 |
# -u <url> Ignore forgeurl even if it exists and use <url> instead. Note
|
|
|
a008c1 |
# that the macro will still end up setting <url> as the forgeurl
|
|
|
a008c1 |
# spec variable if it manages to parse it.
|
|
|
a008c1 |
# -s Silently ignore problems in forgeurl, use it if it can be parsed,
|
|
|
a008c1 |
# ignore it otherwise.
|
|
|
a008c1 |
# -p Restore problem handling, override -s.
|
|
|
a008c1 |
# -v Be verbose and print every spec variable the macro sets.
|
|
|
a008c1 |
# -i Print some info about the state of spec variables the macro may use or
|
|
|
a008c1 |
# set at the end of the processing.
|
|
|
a008c1 |
%forgemeta(u:spvi) %{lua:
|
|
|
a008c1 |
local forgeurl = rpm.expand("%{?-u*}")
|
|
|
a008c1 |
if (forgeurl == "") then
|
|
|
a008c1 |
forgeurl = rpm.expand("%{?forgeurl}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
local silent = false
|
|
|
a008c1 |
local verbose = false
|
|
|
a008c1 |
local informative = false
|
|
|
a008c1 |
if (rpm.expand("%{?-s}") ~= "") then
|
|
|
a008c1 |
silent = true
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (rpm.expand("%{?-p}") ~= "") then
|
|
|
a008c1 |
silent = false
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (rpm.expand("%{?-v}") ~= "") then
|
|
|
a008c1 |
verbose = true
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (rpm.expand("%{?-i}") ~= "") then
|
|
|
a008c1 |
informative = true
|
|
|
a008c1 |
end
|
|
|
a008c1 |
local tag = rpm.expand("%{?tag}")
|
|
|
a008c1 |
local commit = rpm.expand("%{?commit}")
|
|
|
a008c1 |
-- Be explicit about the spec variables we’re setting
|
|
|
a008c1 |
local function explicitset(rpmvariable,value)
|
|
|
a008c1 |
rpm.define(rpmvariable .. " " .. value)
|
|
|
a008c1 |
if verbose then
|
|
|
a008c1 |
rpm.expand("%{echo:Setting %%{" .. rpmvariable .. "} = " .. value .. "\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
-- Never ever stomp on a spec variable the packager already set
|
|
|
a008c1 |
local function safeset(rpmvariable,value)
|
|
|
a008c1 |
if (rpm.expand("%{?" .. rpmvariable .. "}") == "") then
|
|
|
a008c1 |
explicitset(rpmvariable,value)
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
-- Set spec variable values for each known software publishing service
|
|
|
a008c1 |
if (forgeurl ~= "") then
|
|
|
a008c1 |
local forge = string.match(forgeurl, "^[^:]+://([^/]+)/")
|
|
|
a008c1 |
if (forge == nil) then
|
|
|
a008c1 |
if not silent then
|
|
|
a008c1 |
rpm.expand("%{error:URLs must include a protocol such as https:// and a path starting with / !\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
else
|
|
|
a008c1 |
if (string.match(forge, "^gitlab[%.-]") or string.match(forge, "[%.-]gitlab[%.]")) then
|
|
|
a008c1 |
forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")
|
|
|
a008c1 |
if (forgeurl == nil) then
|
|
|
a008c1 |
if not silent then
|
|
|
a008c1 |
rpm.expand("%{error:Gitlab URLs must match https://(…[-.])gitlab[-.]…/owner/repo !\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
else
|
|
|
a008c1 |
explicitset("forgeurl", forgeurl)
|
|
|
a008c1 |
if (commit == "") then
|
|
|
a008c1 |
rpm.expand("%{error:All Gitlab URLs require commit value knowledge: you need to define %{commit}!\\nPlease vote on https://gitlab.com/gitlab-org/gitlab-ce/issues/38830\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
safeset("archiveext", "tar.bz2")
|
|
|
a008c1 |
safeset("forgesetupargs", "-n %{archivename}")
|
|
|
a008c1 |
if (commit ~= "") or (tag ~= "") then
|
|
|
a008c1 |
safeset("scm", "git")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
local owner = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")
|
|
|
a008c1 |
local repo = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")
|
|
|
a008c1 |
local version = rpm.expand("%{?version}")
|
|
|
a008c1 |
if (version ~= "") and (version ~= "0") and (tag == "") then
|
|
|
a008c1 |
-- GitLab does not have strong versionning semantics
|
|
|
a008c1 |
-- Some projects use "version" as release tag, others "v" + "version"
|
|
|
a008c1 |
-- Tag value needs to be explicitly declared before calling the macro
|
|
|
a008c1 |
-- in the second case
|
|
|
a008c1 |
tag = version
|
|
|
a008c1 |
safeset("tag", tag)
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (tag ~= "") then
|
|
|
a008c1 |
safeset("archivename", repo .. "-%{tag}-%{commit}")
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/repository/%{tag}/archive.%{archiveext}")
|
|
|
a008c1 |
else
|
|
|
a008c1 |
safeset("archivename", repo .. "-%{commit}")
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/repository/%{commit}/archive.%{archiveext}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (string.match(forge, "^github[%.-]") or string.match(forge, "[%.-]github[%.]")) then
|
|
|
a008c1 |
forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")
|
|
|
a008c1 |
if (forgeurl == nil) then
|
|
|
a008c1 |
if not silent then
|
|
|
a008c1 |
rpm.expand("%{error:GitHub URLs must match https://(…[-.])github[-.]…/owner/repo !\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
else
|
|
|
a008c1 |
explicitset("forgeurl", forgeurl)
|
|
|
a008c1 |
safeset("archiveext", "tar.gz")
|
|
|
a008c1 |
local forgesetupargs = "-n %{archivename}"
|
|
|
a008c1 |
if (commit ~= "") or (tag ~= "") then
|
|
|
a008c1 |
safeset("scm", "git")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
local owner = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")
|
|
|
a008c1 |
local repo = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")
|
|
|
a008c1 |
if (tag ~= "") then
|
|
|
a008c1 |
-- if upstream used a version suffix such as -rc1 or -beta it will not
|
|
|
a008c1 |
-- be a valid version string for rpm but github will accept it fine and
|
|
|
a008c1 |
-- use the same naming as for other versions: v prefix in the tag and
|
|
|
a008c1 |
-- archivename, no v prefix in the topdir naming inside the archive
|
|
|
a008c1 |
local version = rpm.expand("%{?version}")
|
|
|
a008c1 |
if version ~= "" and
|
|
|
a008c1 |
(string.match(tag, "^v" .. version .. "[^%d]") or
|
|
|
a008c1 |
string.match(tag, "^v" .. version .. "$")) then
|
|
|
a008c1 |
forgesetupargs = "-n " .. repo .. "-" .. string.gsub(tag, "^v", "")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
safeset("archivename", repo .. "-%{tag}")
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/archive/%{tag}.%{archiveext}")
|
|
|
a008c1 |
else
|
|
|
a008c1 |
if (commit ~= "") then
|
|
|
a008c1 |
safeset("archivename", repo .. "-%{commit}")
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/archive/%{commit}/" .. repo .. "-%{commit}.%{archiveext}")
|
|
|
a008c1 |
else
|
|
|
a008c1 |
safeset("archivename", repo .. "-%{version}")
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/archive/v%{version}.%{archiveext}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
safeset("forgesetupargs", forgesetupargs)
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (forge == "code.googlesource.com") then
|
|
|
a008c1 |
forgeurl = string.match(forgeurl, "https://code.googlesource.com/[^#?]*[^/#?]+")
|
|
|
a008c1 |
if (forgeurl == nil) then
|
|
|
a008c1 |
if not silent then
|
|
|
a008c1 |
rpm.expand("%{error:Googlesource URLs must match https://code.googlesource.com/…/repo !\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
else
|
|
|
a008c1 |
explicitset("forgeurl", forgeurl)
|
|
|
a008c1 |
safeset("archiveext", "tar.gz")
|
|
|
a008c1 |
safeset("forgesetupargs", "-c")
|
|
|
a008c1 |
if (commit ~= "") or (tag ~= "") then
|
|
|
a008c1 |
safeset("scm", "git")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
local repo = string.match(forgeurl, "^[^:]+://.+/([^/?#]+)")
|
|
|
a008c1 |
if (tag ~= "") then
|
|
|
a008c1 |
safeset("archivename", repo .. "-%{tag}")
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/+archive/%{tag}.%{archiveext}")
|
|
|
a008c1 |
else
|
|
|
a008c1 |
if (commit ~= "") then
|
|
|
a008c1 |
safeset("archivename", repo .. "-%{commit}")
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/+archive/%{commit}.%{archiveext}")
|
|
|
a008c1 |
else
|
|
|
a008c1 |
safeset("archivename", repo .. "-v%{version}")
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/+archive/v%{version}.%{archiveext}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (forge == "bitbucket.org") then
|
|
|
a008c1 |
forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")
|
|
|
a008c1 |
if (forgeurl == nil) then
|
|
|
a008c1 |
if not silent then
|
|
|
a008c1 |
rpm.expand("%{error:BitBucket URLs must match https://bitbucket.org/owner/repo !\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
else
|
|
|
a008c1 |
explicitset("forgeurl", forgeurl)
|
|
|
a008c1 |
if (commit == "") then
|
|
|
a008c1 |
rpm.expand("%{error:All BitBucket URLs require commit value knowledge: you need to define %{commit}!\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
local shortcommit = string.sub(commit, 1, 12)
|
|
|
a008c1 |
safeset("archiveext", "tar.bz2")
|
|
|
a008c1 |
-- Default to git even though BitBucket allows choosing between several SCMs
|
|
|
a008c1 |
-- Set scm to hg for example before calling the macro if your project does not use git
|
|
|
a008c1 |
safeset("scm", "git")
|
|
|
a008c1 |
local owner = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")
|
|
|
a008c1 |
local repo = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")
|
|
|
a008c1 |
safeset("archivename", owner .. "-" .. repo .. "-" .. shortcommit)
|
|
|
a008c1 |
safeset("forgesetupargs", "-n %{archivename}")
|
|
|
a008c1 |
if (tag ~= "") then
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/get/%{tag}.%{archiveext}")
|
|
|
a008c1 |
else
|
|
|
a008c1 |
safeset("archiveurl", "%{forgeurl}/get/%{commit}.%{archiveext}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (forge == "pagure.io") then
|
|
|
a008c1 |
if not silent then
|
|
|
a008c1 |
rpm.expand("%{error:https://pagure.io/pagure/issue/861 needs to be resolved before the “pagure.io”\\nsoftware publishing service can be supported.\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
-- Final tests to check forgeurl was successfuly parsed
|
|
|
a008c1 |
if not silent then
|
|
|
a008c1 |
if (rpm.expand("%{?archivename}") == "") or (rpm.expand("%{?archiveurl}") == "") then
|
|
|
a008c1 |
rpm.expand("%{error:Automation for the “" .. forge .. "”\\nsoftware publishing service is not implemented yet.\\nPlease extend the %%forgemeta macro!\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
-- Set defaults if forgeurl is missing or does not parse
|
|
|
a008c1 |
local archivename = rpm.expand("%{?archivename}")
|
|
|
a008c1 |
safeset("archiveext", "tar.gz")
|
|
|
a008c1 |
if (archivename ~= "") then
|
|
|
a008c1 |
safeset("forgesetupargs", "-n %{archivename}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (commit ~= "") or (tag ~= "") then
|
|
|
a008c1 |
safeset("scm", "git")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
-- Source URL processing (computing the forgesource spec variable)
|
|
|
a008c1 |
local archiveurl = rpm.expand("%{?archiveurl}")
|
|
|
a008c1 |
local archiveext = rpm.expand("%{?archiveext}")
|
|
|
a008c1 |
if (archivename ~= "") and (archiveurl ~= "") then
|
|
|
a008c1 |
if (string.match(archiveurl, "/([^/]+)$") == archivename .. "." .. archiveext) then
|
|
|
a008c1 |
safeset("forgesource", "%{archiveurl}")
|
|
|
a008c1 |
else
|
|
|
a008c1 |
safeset("forgesource", "%{?archiveurl}#/%{?archivename}.%{archiveext}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
end
|
|
|
a008c1 |
-- dist processing (computing the correct pefix for snapshots)
|
|
|
a008c1 |
local distprefix = rpm.expand("%{?tag}")
|
|
|
a008c1 |
local version = rpm.expand("%{?version}")
|
|
|
a008c1 |
if (distprefix == version) or (distprefix == "v" .. version) then
|
|
|
a008c1 |
distprefix = ""
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (distprefix == "") then
|
|
|
a008c1 |
distprefix = string.sub(rpm.expand("%{?commit}"), 1, 7)
|
|
|
a008c1 |
end
|
|
|
a008c1 |
if (distprefix ~= "") then
|
|
|
a008c1 |
local dist = ".%([ -r %{_sourcedir}/%{archivename}.%{archiveext} ] && date +%Y%m%d -u -r %{_sourcedir}/%{archivename}.%{archiveext})%{scm}" .. string.gsub(distprefix, "-",".") .. rpm.expand("%{?dist}")
|
|
|
a008c1 |
explicitset("dist", dist)
|
|
|
a008c1 |
end
|
|
|
a008c1 |
-- Final spec variable summary if the macro was called with -i
|
|
|
a008c1 |
if informative then
|
|
|
a008c1 |
rpm.expand("%{echo:Forge-specific packaging variables\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: forgeurl: %{?forgeurl}\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: forgesource: %{?forgesource}\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: forgesetupargs: %{?forgesetupargs}\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo:Generic variables\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: archivename: %{?archivename}\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: archiveext: %{?archiveext}\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: archiveurl: %{?archiveurl}\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: scm: %{?scm}\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: tag: %{?tag}\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: commit: %{?commit}\\n}")
|
|
|
a008c1 |
rpm.expand("%{echo: dist: %{?dist} (snapshot date is computed once %%{_sourcedir}/%%{archivename}.%%{archiveext} is available)\\n}")
|
|
|
a008c1 |
end
|
|
|
a008c1 |
}
|
|
|
a008c1 |
|
|
|
a008c1 |
# Convenience macro to relay computed arguments to %setup
|
|
|
a008c1 |
%forgesetup(a:b:cDn:Tq) %setup %{?forgesetupargs} %{-a} %{-b} %{-c} %{-D} %{-n} %{-T} %{-q}
|
|
|
a008c1 |
|
|
|
a008c1 |
# Convenience macro to relay computed arguments to %autosetup
|
|
|
a008c1 |
%forgeautosetup(a:b:cDn:TvNS:p:) %autosetup %{?forgesetupargs} %{-a} %{-b} %{-c} %{-D} %{-n} %{-T} %{-v} %{-N} %{-S} %{-p}
|