| |
@@ -60,13 +60,27 @@
|
| |
if (rpm.expand("%{?-i}") ~= "") then
|
| |
informative = true
|
| |
end
|
| |
- local tag = rpm.expand("%{?tag}")
|
| |
- local commit = rpm.expand("%{?commit}")
|
| |
+ -- Packaging a moving branch is quite a bad idea, but since at least Gitlab
|
| |
+ -- will treat branches and tags the same way better support branches explicitly
|
| |
+ -- than have packagers hijack %{tag} to download branch states
|
| |
+ local tag = rpm.expand("%{?tag}")
|
| |
+ local commit = rpm.expand("%{?commit}")
|
| |
+ local branch = rpm.expand("%{?branch}")
|
| |
+ local version = rpm.expand("%{?version}")
|
| |
+ local ref = ""
|
| |
+ if (tag ~= "") then ref = "%{?tag}"
|
| |
+ elseif (commit ~= "") then ref = "%{?commit}"
|
| |
+ elseif (branch ~= "") then ref = "%{?branch}"
|
| |
+ else ref = "%{?version}"
|
| |
+ end
|
| |
+ if (rpm.expand(ref) == "") then
|
| |
+ rpm.expand("%{error:You need to define Version:, %{commit} or %{tag} before the macro invocation !}")
|
| |
+ end
|
| |
-- Be explicit about the spec variables we’re setting
|
| |
local function explicitset(rpmvariable,value)
|
| |
rpm.define(rpmvariable .. " " .. value)
|
| |
if verbose then
|
| |
- rpm.expand("%{echo:Setting %%{" .. rpmvariable .. "} = " .. value .. "\\n}")
|
| |
+ rpm.expand("%{echo:Setting %%{" .. rpmvariable .. "} = " .. value .. "}")
|
| |
end
|
| |
end
|
| |
-- Never ever stomp on a spec variable the packager already set
|
| |
@@ -75,128 +89,97 @@
|
| |
explicitset(rpmvariable,value)
|
| |
end
|
| |
end
|
| |
+ -- Computes the suffix of a version string, removing vprefix if it matches
|
| |
+ -- For example with vprefix 1.2.3: 1.2.3.rc2 → .rc2 but 1.2.30 → 1.2.30 not 0
|
| |
+ local function getversionsuffix(vstring,vprefix)
|
| |
+ if (string.sub(vstring, 1, #vprefix) == vprefix) and
|
| |
+ (not string.match(string.sub(vstring, #vprefix + 1), "^%.?%d")) then
|
| |
+ return string.sub(vstring, #vprefix + 1)
|
| |
+ else
|
| |
+ return vstring
|
| |
+ end
|
| |
+ end
|
| |
-- Set spec variable values for each known software publishing service
|
| |
if (forgeurl ~= "") then
|
| |
local forge = string.match(forgeurl, "^[^:]+://([^/]+)/")
|
| |
if (forge == nil) then
|
| |
if not silent then
|
| |
- rpm.expand("%{error:URLs must include a protocol such as https:// and a path starting with / !\\n}")
|
| |
+ rpm.expand("%{error:URLs must include a protocol such as https:// and a path starting with / !}")
|
| |
end
|
| |
else
|
| |
if (string.match(forge, "^gitlab[%.-]") or string.match(forge, "[%.-]gitlab[%.]")) then
|
| |
forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")
|
| |
if (forgeurl == nil) then
|
| |
if not silent then
|
| |
- rpm.expand("%{error:Gitlab URLs must match https://(…[-.])gitlab[-.]…/owner/repo !\\n}")
|
| |
+ rpm.expand("%{error:Gitlab URLs must match https://(…[-.])gitlab[-.]…/owner/repo !}")
|
| |
end
|
| |
else
|
| |
explicitset("forgeurl", forgeurl)
|
| |
- if (commit == "") then
|
| |
- 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}")
|
| |
- end
|
| |
safeset("archiveext", "tar.bz2")
|
| |
safeset("forgesetupargs", "-n %{archivename}")
|
| |
- if (commit ~= "") or (tag ~= "") then
|
| |
- safeset("scm", "git")
|
| |
- end
|
| |
- local owner = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")
|
| |
- local repo = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")
|
| |
- local version = rpm.expand("%{?version}")
|
| |
- if (version ~= "") and (version ~= "0") and (tag == "") then
|
| |
- -- GitLab does not have strong versionning semantics
|
| |
- -- Some projects use "version" as release tag, others "v" + "version"
|
| |
- -- Tag value needs to be explicitly declared before calling the macro
|
| |
- -- in the second case
|
| |
- tag = version
|
| |
- safeset("tag", tag)
|
| |
- end
|
| |
- if (tag ~= "") then
|
| |
- safeset("archivename", repo .. "-%{tag}-%{commit}")
|
| |
- safeset("archiveurl", "%{forgeurl}/repository/%{tag}/archive.%{archiveext}")
|
| |
- else
|
| |
- safeset("archivename", repo .. "-%{commit}")
|
| |
- safeset("archiveurl", "%{forgeurl}/repository/%{commit}/archive.%{archiveext}")
|
| |
- end
|
| |
+ if (ref ~= "%{?version}") then safeset("scm", "git") end
|
| |
+ local repo = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")
|
| |
+ safeset("archivename", repo .. "-" .. ref)
|
| |
+ safeset("archiveurl", "%{forgeurl}/-/archive/" .. ref .. "/%{archivename}.%{archiveext}")
|
| |
end
|
| |
end
|
| |
if (string.match(forge, "^github[%.-]") or string.match(forge, "[%.-]github[%.]")) then
|
| |
forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")
|
| |
if (forgeurl == nil) then
|
| |
if not silent then
|
| |
- rpm.expand("%{error:GitHub URLs must match https://(…[-.])github[-.]…/owner/repo !\\n}")
|
| |
+ rpm.expand("%{error:GitHub URLs must match https://(…[-.])github[-.]…/owner/repo !}")
|
| |
end
|
| |
else
|
| |
explicitset("forgeurl", forgeurl)
|
| |
safeset("archiveext", "tar.gz")
|
| |
- local forgesetupargs = "-n %{archivename}"
|
| |
- if (commit ~= "") or (tag ~= "") then
|
| |
- safeset("scm", "git")
|
| |
- end
|
| |
- local owner = string.match(forgeurl, "^[^:]+://[^/]+/([^/]+)")
|
| |
- local repo = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")
|
| |
- if (tag ~= "") then
|
| |
- -- if upstream used a version suffix such as -rc1 or -beta it will not
|
| |
- -- be a valid version string for rpm but github will accept it fine and
|
| |
- -- use the same naming as for other versions: v prefix in the tag and
|
| |
- -- archivename, no v prefix in the topdir naming inside the archive
|
| |
- local version = rpm.expand("%{?version}")
|
| |
- if version ~= "" and
|
| |
- (string.match(tag, "^v" .. version .. "[^%d]") or
|
| |
- string.match(tag, "^v" .. version .. "$")) then
|
| |
- forgesetupargs = "-n " .. repo .. "-" .. string.gsub(tag, "^v", "")
|
| |
- end
|
| |
- safeset("archivename", repo .. "-%{tag}")
|
| |
- safeset("archiveurl", "%{forgeurl}/archive/%{tag}.%{archiveext}")
|
| |
+ safeset("forgesetupargs", "-n %{archivename}")
|
| |
+ -- Workaround the way GitHub injects "v"s before some version strings (but not all!)
|
| |
+ -- To package one of the minority of sane GitHub projects that do not munge their version
|
| |
+ -- strings set tag to %{version} in your spec
|
| |
+ local fileref = ref
|
| |
+ if (ref == "%{?version}") then
|
| |
+ ref = "v" .. ref
|
| |
else
|
| |
- if (commit ~= "") then
|
| |
- safeset("archivename", repo .. "-%{commit}")
|
| |
- safeset("archiveurl", "%{forgeurl}/archive/%{commit}/" .. repo .. "-%{commit}.%{archiveext}")
|
| |
- else
|
| |
- safeset("archivename", repo .. "-%{version}")
|
| |
- safeset("archiveurl", "%{forgeurl}/archive/v%{version}.%{archiveext}")
|
| |
+ safeset("scm", "git")
|
| |
+ if (fileref ~= "%{?commit}") and string.match(rpm.expand(fileref), "^v[%d]") then
|
| |
+ fileref = string.gsub(rpm.expand(fileref), "^v", "")
|
| |
end
|
| |
end
|
| |
- safeset("forgesetupargs", forgesetupargs)
|
| |
+ local repo = string.match(forgeurl, "^[^:]+://[^/]+/[^/]+/([^/]+)")
|
| |
+ safeset("archivename", repo .. "-" .. fileref)
|
| |
+ safeset("archiveurl", "%{forgeurl}/archive/" .. ref .. "/%{archivename}.%{archiveext}")
|
| |
end
|
| |
end
|
| |
if (forge == "code.googlesource.com") then
|
| |
forgeurl = string.match(forgeurl, "https://code.googlesource.com/[^#?]*[^/#?]+")
|
| |
if (forgeurl == nil) then
|
| |
if not silent then
|
| |
- rpm.expand("%{error:Googlesource URLs must match https://code.googlesource.com/…/repo !\\n}")
|
| |
+ rpm.expand("%{error:Googlesource URLs must match https://code.googlesource.com/…/repo !}")
|
| |
end
|
| |
else
|
| |
explicitset("forgeurl", forgeurl)
|
| |
safeset("archiveext", "tar.gz")
|
| |
safeset("forgesetupargs", "-c")
|
| |
- if (commit ~= "") or (tag ~= "") then
|
| |
+ if (ref == "%{?version}") then
|
| |
+ ref = "v" .. ref
|
| |
+ else
|
| |
safeset("scm", "git")
|
| |
end
|
| |
local repo = string.match(forgeurl, "^[^:]+://.+/([^/?#]+)")
|
| |
- if (tag ~= "") then
|
| |
- safeset("archivename", repo .. "-%{tag}")
|
| |
- safeset("archiveurl", "%{forgeurl}/+archive/%{tag}.%{archiveext}")
|
| |
- else
|
| |
- if (commit ~= "") then
|
| |
- safeset("archivename", repo .. "-%{commit}")
|
| |
- safeset("archiveurl", "%{forgeurl}/+archive/%{commit}.%{archiveext}")
|
| |
- else
|
| |
- safeset("archivename", repo .. "-v%{version}")
|
| |
- safeset("archiveurl", "%{forgeurl}/+archive/v%{version}.%{archiveext}")
|
| |
- end
|
| |
- end
|
| |
+ safeset("archivename", repo .. "-" .. ref)
|
| |
+ safeset("archiveurl", "%{forgeurl}/+archive/" .. ref .. ".%{archiveext}")
|
| |
end
|
| |
end
|
| |
if (forge == "bitbucket.org") then
|
| |
forgeurl = string.match(forgeurl, "https://[^/]+/[^/]+/[^/#?]+")
|
| |
if (forgeurl == nil) then
|
| |
if not silent then
|
| |
- rpm.expand("%{error:BitBucket URLs must match https://bitbucket.org/owner/repo !\\n}")
|
| |
+ rpm.expand("%{error:BitBucket URLs must match https://bitbucket.org/owner/repo !}")
|
| |
end
|
| |
else
|
| |
explicitset("forgeurl", forgeurl)
|
| |
if (commit == "") then
|
| |
- rpm.expand("%{error:All BitBucket URLs require commit value knowledge: you need to define %{commit}!\\n}")
|
| |
+ rpm.expand("%{error:All BitBucket URLs require commit value knowledge: you need to define %{commit}!}")
|
| |
end
|
| |
local shortcommit = string.sub(commit, 1, 12)
|
| |
safeset("archiveext", "tar.bz2")
|
| |
@@ -216,13 +199,13 @@
|
| |
end
|
| |
if (forge == "pagure.io") then
|
| |
if not silent then
|
| |
- rpm.expand("%{error:https://pagure.io/pagure/issue/861 needs to be resolved before the “pagure.io”\\nsoftware publishing service can be supported.\\n}")
|
| |
+ rpm.expand("%{error:https://pagure.io/pagure/issue/861 needs to be resolved before the “pagure.io”\\nsoftware publishing service can be supported.}")
|
| |
end
|
| |
end
|
| |
-- Final tests to check forgeurl was successfuly parsed
|
| |
if not silent then
|
| |
if (rpm.expand("%{?archivename}") == "") or (rpm.expand("%{?archiveurl}") == "") then
|
| |
- rpm.expand("%{error:Automation for the “" .. forge .. "”\\nsoftware publishing service is not implemented yet.\\nPlease extend the %%forgemeta macro!\\n}")
|
| |
+ rpm.expand("%{error:Automation for the “" .. forge .. "”\\nsoftware publishing service is not implemented yet.\\nPlease extend the %%forgemeta macro!}")
|
| |
end
|
| |
end
|
| |
end
|
| |
@@ -246,33 +229,48 @@
|
| |
safeset("forgesource", "%{?archiveurl}#/%{?archivename}.%{archiveext}")
|
| |
end
|
| |
end
|
| |
- -- dist processing (computing the correct pefix for snapshots)
|
| |
- local distprefix = rpm.expand("%{?tag}")
|
| |
- local version = rpm.expand("%{?version}")
|
| |
- if (distprefix == version) or (distprefix == "v" .. version) then
|
| |
- distprefix = ""
|
| |
- end
|
| |
- if (distprefix == "") then
|
| |
- distprefix = string.sub(rpm.expand("%{?commit}"), 1, 7)
|
| |
+ -- dist processing (computing the correct prefix for snapshots)
|
| |
+ local distprefix = rpm.expand(ref)
|
| |
+ if (ref == "%{?commit}") then
|
| |
+ distprefix = string.sub(distprefix, 1, 7)
|
| |
+ elseif (ref ~= "%{?branch}") then
|
| |
+ distprefix = getversionsuffix(distprefix, version)
|
| |
+ distprefix = getversionsuffix(distprefix, "v" .. version)
|
| |
+ distprefix = string.gsub(distprefix, "[.-]+", ".")
|
| |
+ distprefix = string.gsub(distprefix, "^%.", "")
|
| |
end
|
| |
if (distprefix ~= "") then
|
| |
- local dist = ".%{?date}%{!?date:%([ -r %{_sourcedir}/%{archivename}.%{archiveext} ] && date +%Y%m%d -u -r %{_sourcedir}/%{archivename}.%{archiveext})}%{scm}" .. string.gsub(distprefix, "-",".") .. rpm.expand("%{?dist}")
|
| |
- explicitset("dist", dist)
|
| |
+ distprefix = "%{scm}" .. distprefix
|
| |
+ date = rpm.expand("%{?date}")
|
| |
+ if (date ~= "") then
|
| |
+ distprefix = date .. distprefix
|
| |
+ else
|
| |
+ distprefix = "%([ -r %{_sourcedir}/%{archivename}.%{archiveext} ] && date +%Y%m%d -u -r %{_sourcedir}/%{archivename}.%{archiveext})" .. distprefix
|
| |
+ end
|
| |
+ safeset ("distprefix", "." .. distprefix)
|
| |
+ -- Workaround releases where distprefix is not used by default
|
| |
+ local dist = rpm.expand("%{?dist}")
|
| |
+ local edistprefix = rpm.expand(distprefix)
|
| |
+ if (edistprefix ~= "") and (string.sub(dist, 1, #edistprefix) ~= edistprefix) then
|
| |
+ rpmmacros.explicitset("dist", "%{?distprefix}" .. dist,verbose)
|
| |
+ end
|
| |
end
|
| |
-- Final spec variable summary if the macro was called with -i
|
| |
if informative then
|
| |
- rpm.expand("%{echo:Forge-specific packaging variables\\n}")
|
| |
- rpm.expand("%{echo: forgeurl: %{?forgeurl}\\n}")
|
| |
- rpm.expand("%{echo: forgesource: %{?forgesource}\\n}")
|
| |
- rpm.expand("%{echo: forgesetupargs: %{?forgesetupargs}\\n}")
|
| |
- rpm.expand("%{echo:Generic variables\\n}")
|
| |
- rpm.expand("%{echo: archivename: %{?archivename}\\n}")
|
| |
- rpm.expand("%{echo: archiveext: %{?archiveext}\\n}")
|
| |
- rpm.expand("%{echo: archiveurl: %{?archiveurl}\\n}")
|
| |
- rpm.expand("%{echo: scm: %{?scm}\\n}")
|
| |
- rpm.expand("%{echo: tag: %{?tag}\\n}")
|
| |
- rpm.expand("%{echo: commit: %{?commit}\\n}")
|
| |
- rpm.expand("%{echo: dist: %{?dist} (snapshot date is either manually supplied or computed once %%{_sourcedir}/%%{archivename}.%%{archiveext} is available)\\n}")
|
| |
+ rpm.expand("%{echo:Forge-specific packaging variables}")
|
| |
+ rpm.expand("%{echo: forgeurl: %{?forgeurl}}")
|
| |
+ rpm.expand("%{echo: forgesource: %{?forgesource}}")
|
| |
+ rpm.expand("%{echo: forgesetupargs: %{?forgesetupargs}}")
|
| |
+ rpm.expand("%{echo:Generic packaging variables}")
|
| |
+ rpm.expand("%{echo: archivename: %{?archivename}}")
|
| |
+ rpm.expand("%{echo: archiveext: %{?archiveext}}")
|
| |
+ rpm.expand("%{echo: archiveurl: %{?archiveurl}}")
|
| |
+ rpm.expand("%{echo: scm: %{?scm}}")
|
| |
+ rpm.expand("%{echo: tag: %{?tag}}")
|
| |
+ rpm.expand("%{echo: commit: %{?commit}}")
|
| |
+ rpm.expand("%{echo: branch: %{?branch}}")
|
| |
+ rpm.expand("%{echo: date: %{?date}}")
|
| |
+ rpm.expand("%{echo: distprefix: %{?distprefix} (snapshot date is either manually supplied or computed once %%{_sourcedir}/%%{archivename}.%%{archiveext} is available)}")
|
| |
end
|
| |
}
|
| |
|
| |
Sync stable forge macro state with devel state as requested by users in
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/QFWERBIY3G5R2J76FAKOQPKCNL7T34QL/