srpm/fonts.lua000064400000021020151074713450007363 0ustar00-- Copyright © 2018-2019 Nicolas Mailhot -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -- -- SPDX-License-Identifier: GPL-3.0-or-later -- Convenience lua functions used to create rpm font packages local globargs = {fonts = "f", fontsex = "F", fontconfs = "c", fontconfsex = "C", fontconfngs = "n", fontconfngsex = "N", fontappstreams = "s", fontappstreamsex = "S", fontdocs = "d", fontdocsex = "D", fontlicenses = "l", fontlicensesex = "L"} -- Return a normalized name local function norm(name) local r = name r = string.gsub(r, "[%p%s]+", "-") r = string.gsub(r, "^-", "") r = string.gsub(r, "-$", "") r = string.lower(r) return r end -- loop over suffixlist and return name minus the first suffix that matches -- - is used as suffix separator -- name should have passed through norm at one point in the past local function dropsuffix(name,suffixlist) local r = name for _, s in ipairs(suffixlist) do r, n = string.gsub(r, "-" .. norm(s) .. "$", "") if (n == 1) then break end end return r end -- Compute a font family name that can be used in packaging, lowercasing, using -- - as separator, and applying “WPF font selection model” whitepaper -- simplifications local function rpmname(name) local r = norm(name) -- Normal & co r = dropsuffix(r,{"normal","book","regular","upright"}) -- Slant r = dropsuffix(r,{"italic","ita","ital","cursive","kursiv", "oblique","inclined","backslanted","backslant","slanted"}) -- Width / Stretch r = dropsuffix(r,{"ultracondensed","extra-compressed","ext-compressed","ultra-compressed","ultra-condensed", "extracondensed","compressed","extra-condensed","ext-condensed","extra-cond", "semicondensed","narrow","semi-condens", "semiexpanded","wide","semi-expanded","semi-extended", "extraexpanded","extra-expanded","ext-expanded","extra-extended","ext-extended", "ultraexpanded","ultra-expanded","ultra-extended", "condensed","cond", "expanded","extended"}) -- Weight (no abbreviated suffix handling, too dangerous) r = dropsuffix(r,{"thin","extra-thin","ext-thin","ultra-thin", "extralight","extra-light","ext-light","ultra-light", "demibold","semi-bold","demi-bold", "extrabold","extra-bold","ext-bold","ultra-bold", "extrablack","extra-black","ext-black","ultra-black", "bold","thin","light","medium", "black","heavy","nord", "demi","ultra"}) local tokens = {} for _, t in ipairs({"font","fonts"}) do tokens[t] = true end local ts = string.gmatch(r, "[^%-]+") r = "" for t in ts do if not tokens[t] then r = r .. "-" .. t tokens[t] = true end end r = string.gsub(r, "^-", "") .. "-fonts" return r end -- The fontenv macro main processing function -- See the documentation in the macros.fonts file for argument description local function env(suffix, verbose, globvalues) local fedora = require "fedora.common" local ismain = (suffix == "") or (suffix == "0") fedora.zalias({"foundry", "fontlicense"}, verbose) fedora.safeset("fontlicense", "%{license}", verbose) if ismain then fedora.zalias({"fontsummary", "fontdescription", "fontpkgname", "fonthumanname", "fontpkgheader", "fonts", "fontsex", "fontconfs", "fontconfsex", "fontconfngs", "fontconfngsex", "fontappstreams", "fontappstreamsex", "fontdocs", "fontdocsex", "fontlicense", "fontlicenses", "fontlicensesex", "fontdir", "fontfilelist"}, verbose) end for _, v in ipairs({"foundry", "fontdocs", "fontdocsex", "fontlicense", "fontlicenses", "fontlicensesex"}) do if (rpm.expand("%{" .. v .. "}") ~= "%{" .. v .. "}") then fedora.safeset(v .. suffix, "%{" .. v .. "}", verbose) end end for g, _ in pairs(globargs) do local v = rpm.expand("%{?" .. g .. suffix .. "} " .. (globvalues[g] or "")) if (string.gsub(v, "[%s]+", "") ~= "") then fedora.explicitset( "current" .. g, v, verbose) else fedora.explicitunset("current" .. g, verbose) end end local basename = rpm.expand("%{?foundry" .. suffix .. ":%{foundry" .. suffix .. "} }%{fontfamily" .. suffix .. "}") fedora.safeset("fontpkgname" .. suffix, rpmname(basename), verbose) fedora.safeset("fonthumanname" .. suffix, basename, verbose) fedora.safeset("fontdir" .. suffix, "%{_fontbasedir}/%{fontpkgname" .. suffix .. "}", verbose) fedora.safeset("fontfilelist" .. suffix, "%{_builddir}/%{?buildsubdir}/%{fontpkgname" .. suffix .. "}.list", verbose) if ismain then fedora.zalias({"fontpkgname", "fontdir", "fontfilelist"}) end for _, v in ipairs({"foundry", "fontpkgname", "fonthumanname", "fontpkgheader", "fontdir", "fontfilelist", "fontfamily", "fontlicense", "fontsummary", "fontdescription"}) do if (rpm.expand("%{?" .. v .. suffix .. "}") ~= "") then fedora.explicitset( "current" .. v, "%{" .. v .. suffix .. "}", verbose) else fedora.explicitunset("current" .. v, verbose) end end end -- Create a single %package section for a fonts subpackage local function singlepkg(forcemain, forcesub, suffix, verbose) local fedora = require "fedora.common" local sub = (not forcemain) and (forcesub or ((suffix ~= nil) and (suffix ~= "") and (suffix ~= "0"))) env(suffix, verbose, {}) name = sub and "%package -n " or "Name: " print( name .. rpm.expand( "%{currentfontpkgname}\n" .. "Summary: %{currentfontsummary}\n" .. "License: %{currentfontlicense}\n" .. "BuildArch: noarch\n" .. "BuildRequires: fonts-rpm-macros\n" .. "Requires: fontpackages-filesystem\n" .. "%{?currentfontpkgheader}\n" .. "%description -n %{currentfontpkgname}\n") .. fedora.wordwrap("%{?currentfontdescription}") .. "\n") end -- Create one or all %package sections for fonts subpackages local function pkg(forcemain, forcesub, suffix, processall, verbose) local fedora = require "fedora.common" if processall then for _, suffix in pairs(fedora.getsuffixes("fontfamily")) do singlepkg(forcemain, forcesub, suffix, verbose) end else singlepkg(forcemain, forcesub, suffix, verbose) end end -- Create a font (sub)metapackage header local function metapkg(name, summary, description, suffixes) local fedora = require "fedora.common" local fontpkgs = fedora.getsuffixed("fontpkgname") if (name == "") then name, _ = string.gsub(rpm.expand("%{name}"), "-fonts$", "") name = name .. "-fonts-all" end if (summary == "") then summary = "All the font packages, generated from %{name}" end if (description == "") then description = "This meta-package installs all the font packages, generated from the %{name} source package." end description = fedora.wordwrap(description) print(rpm.expand( "%package -n " .. name .. "\n" .. "Summary: " .. summary .. "\n")) if (suffixes == "") then for _, fontpkg in pairs(fontpkgs) do print(rpm.expand( "Requires(meta): " .. fontpkg .. " = %{version}-%{release}\n")) end else for suffix in string.gmatch(rpm.expand(suffixes), "[^%s%p]+") do local fontpkg = fontpkgs[suffix] if (fontpkg ~= nil) then print(rpm.expand("Requires(meta): " .. fontpkg .. " = %{version}-%{release}\n")) end end end print(rpm.expand( "BuildArch: noarch\n" .. "%description -n " .. name .. "\n" .. description .. "\n" .. "%files -n " .. name .. "\n\n")) end return { globargs = globargs, rpmname = rpmname, env = env, pkg = pkg, metapkg = metapkg, } srpm/go.lua000064400000040025151074713450006645 0ustar00-- Copyright (c) 2017-2019 Nicolas Mailhot -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . -- -- SPDX-License-Identifier: GPL-3.0-or-later -- This file contains Lua code used in rpm macros needed to create and process -- source rpm (srpm) Go (golang) packages. -- -- The resulting code must not use any package except redhat-rpm-macros -- Sanitize a Go import path that can then serve as rpm package name -- Mandatory parameter: a Go import path local function rpmname(goipath, compatid) -- lowercase and end with '/' local goname = string.lower(rpm.expand(goipath) .. "/") -- remove eventual protocol prefix goname = string.gsub(goname, "^http(s?)://", "") -- remove eventual .git suffix goname = string.gsub(goname, "%.git/+", "") -- remove eventual git. prefix goname = string.gsub(goname, "^git%.", "") -- remove FQDN root (.com, .org, etc) -- will also remove vanity FQDNs such as "tools" goname = string.gsub(goname, "^([^/]+)%.([^%./]+)/", "%1/") -- add golang prefix goname = "golang-" .. goname -- compat naming additions local compatid = string.lower(rpm.expand(compatid)) if (compatid ~= nil) and (compatid ~= "") then goname = "compat-" .. goname .. "-" .. compatid end -- special-case x.y.z number-strings as that’s an exception in our naming -- guidelines repeat goname, i = string.gsub(goname, "(%d)%.(%d)", "%1:%2") until i == 0 -- replace various separators rpm does not like with - goname = string.gsub(goname, "[%._/%-~]+", "-") -- because of the Azure sdk goname = string.gsub(goname, "%-for%-go%-", "-") -- Tokenize along - separators and remove duplicates to avoid -- golang-foo-foo-bar-foo names local result = "" local tokens = {} tokens["go"] = true for token in string.gmatch(goname, "[^%-]+") do if not tokens[token] then result = result .. "-" .. token tokens[token] = true end end -- reassemble the string, restore x.y.z runs, convert the vx.y.z -- Go convention to x.y.z as prefered in rpm naming result = string.gsub(result, "^-", "") result = string.gsub(result, ":", ".") -- some projects have a name that end up in a number, and *also* add release -- numbers on top of it, keep a - prefix before version strings result = string.gsub(result, "%-v([%.%d]+)$", "-%1") result = string.gsub(result, "%-v([%.%d]+%-)", "-%1") if rpm.expand("%{?go_use_new_versioning}") ~= "" then -- according to the guidelines, if the base package name does not end with -- a digit, the version MUST be directly appended to the package name with -- no intervening separator. -- If the base package name ends with a digit, a single underscore (_) MUST -- be appended to the name, and the version MUST be appended to that, in -- order to avoid confusion over where the name ends and the version begins. result = string.gsub(result, "([^-]*)(%-)([%.%d]+)$", function(prior, hyphen, version) if string.find(prior, "%d$") then return prior .. "_" .. version else return prior .. version end end) end return(result) end -- The gometa macro main processing function -- See the documentation in the macros.go-srpm file for argument description local function meta(suffix, verbose, informative, silent) local fedora = require "fedora.common" local forge = require "fedora.srpm.forge" local zsuffix = "" if (suffix ~= "") then zsuffix = " -z " .. suffix end local ismain = (suffix == "") or (suffix == "0") if ismain then fedora.zalias({"forgeurl", "goipath", "gocid", "goname", "gourl", "gosource"}, verbose) end local spec = {} for _, v in ipairs({'goipath', 'forgeurl'}) do spec[v] = rpm.expand("%{?" .. v .. suffix .. "}") end -- All the Go packaging automation relies on goipath being set if (spec["goipath"] == "") then rpm.expand("%{error:Please set the Go import path in the %%{goipath" .. suffix .. "} variable before calling %%gometa" .. zsuffix .. "!}") end local cleangoipath = string.gsub(spec["goipath"], "^http(s?)://", "") cleangoipath = string.gsub(cleangoipath, "/+$", "") if (cleangoipath ~= spec["goipath"]) then fedora.explicitset(goipath .. suffix, cleangoipath) end if (spec["forgeurl"] == "") then fedora.safeset("forgeurl" .. suffix, "https://%{goipath" .. suffix .. "}",verbose) end forge.meta(suffix, verbose, informative, silent) fedora.safeset("gourl" .. suffix, "%{forgeurl" .. suffix .. "}",verbose) if (rpm.expand("%{?forgesource" .. suffix .. "}") ~= "") then fedora.safeset("gosource" .. suffix, "%{forgesource" .. suffix .. "}",verbose) else fedora.safeset("gosource" .. suffix, "%{gourl" .. suffix .. "}/%{archivename" .. suffix .. "}.%{archiveext" .. suffix .. "}",verbose) end fedora.safeset( "goname" .. suffix, rpmname("%{goipath" .. suffix .. "}", "%{?gocid" .. suffix .. "}") ,verbose) fedora.zalias({"forgeurl","goname","gourl","gosource"},verbose) -- Final spec variable summary if the macro was called with -i if informative then rpm.expand("%{echo:Packaging variables read or set by %%gometa}") fedora.echovars({"goipath","goname","gourl","gosource"}, suffix) end end -- Pivot variable definitions for each kind of Go package local pivot = {devel = "goipaths", alt = "goaltipaths"} -- Default argument flag for each kind of list local listflags = {goipaths = "-i", goipathsex = "-t", goextensions = "-e"} -- Convert a space-separated list of import paths to a table indexed by their -- rpmname version, to handle upstreams that play naming games local function indexedgoipaths(goipaths, gocid) local go = require "fedora.srpm.go" local giptable = {} for goipath in string.gmatch(rpm.expand(goipaths), "[^%s,]+") do local key = go.rpmname(goipath, gocid) if (not string.match(key, "^compat-")) then key = "compat-" .. key end if (giptable[key] == nil) then giptable[key] = {} end table.insert(giptable[key], goipath) end return giptable end -- Create fallbacks to goipath variables if godevelipath variables are missing local function develenvinit() local fedora = require "fedora.common" if (next(fedora.getsuffixes("goipaths")) == nil) then for _, suffix in pairs(fedora.getsuffixes("goipath")) do fedora.safeset("goipaths" .. suffix, "%{goipath" .. suffix .. "}") end end end -- Set rpm variables related to the processing of a golang-*-devel subpackage local function develenv(suffix, verbose) local fedora = require "fedora.common" local go = require "fedora.srpm.go" local ismain = (suffix == "") or (suffix == "0") if ismain then fedora.zalias( {"goipath", "gocid", "gofilelist", "godevelname", "godevelcid", "godevelfilelist", "godevelsummary", "godeveldescription", "godevelheader", "goextensions", "gosupfiles", "gosupfilesex", "goipaths", "goipathsex", "golicenses", "golicensesex", "godocs", "godocsex"}, verbose) end for list, flag in pairs(listflags) do local l = rpm.expand("%{?" .. list .. suffix .. "}") if (l ~= "") then l = string.gsub(" " .. l, "%s+%" .. flag .. "%s+", " ") l = string.gsub(l, "%s+", " ") l = string.gsub(l, "^ ", "") l = string.gsub(l, " $", "") if (list ~= "goipaths") then l = string.gsub(l, "([^%s]+)", flag .. " %1") end fedora.explicitset(list .. suffix, l) end end local goipaths = rpm.expand("%{?goipaths" .. suffix .. "}") local goipath = string.match(goipaths, "[^%s]+") fedora.safeset("godevelcid" .. suffix, "%{?gocid" .. suffix .. "}", verbose) local rpmname = go.rpmname(goipath, "%{?godevelcid" .. suffix .. "}") fedora.safeset("godevelname" .. suffix, rpmname .. "-devel", verbose) fedora.safeset("godevelfilelist" .. suffix, rpmname .. "-%{gofilelist}", verbose) fedora.safeset("godevelsummary" .. suffix, "%{summary}", verbose) fedora.safeset("godeveldescription" .. suffix, "%{?common_description}", verbose) local postdescr = "\n\nThis package contains the source code needed for building packages that reference " .. "the following Go import paths:" postdescr = postdescr .. string.gsub(goipaths, "([^%s]+)", "\n – %1") fedora.explicitset("currentgodeveldescription", "%{expand:%{godeveldescription" .. suffix .. "}" .. postdescr .. "}", verbose) fedora.setcurrent({"godevelname", "godevelcid", "godevelfilelist", "godevelsummary", "godevelheader", "goextensions", "gosupfiles", "gosupfilesex", "goipaths", "goipathsex", "golicenses", "golicensesex", "godocs", "godocsex"}, suffix, verbose) if ismain then fedora.zalias( {"godevelname", "godevelcid", "godevelfilelist", "godevelsummary", "godeveldescription"}, verbose) end end -- Set rpm variables related to the processing of a compat-golang-*-devel subpackage local function altenv(suffix, rpmname, goaltipaths, verbose) local fedora = require "fedora.common" local go = require "fedora.srpm.go" local ismain = (suffix == "") or (suffix == "0") if ismain then fedora.zalias( {"goipath", "gocanonipath", "goaltdescription", "goaltsummary", "goaltheader"}, verbose) end fedora.safeset("gocanonipath" .. suffix, "%{goipath" .. suffix .. "}", verbose) fedora.safeset("goaltsummary" .. suffix, "%{summary}", verbose) fedora.safeset("goaltdescription" .. suffix, "%{?common_description}", verbose) fedora.setcurrent( {"gocanonipath", "goaltcid", "goaltsummary"}, suffix, verbose) local postdescr = "\n\nThis package provides symbolic links that alias the following Go import paths " .. "to %{currentgocanonipath}:" local posthead = "" for _, goaltipath in ipairs(goaltipaths) do postdescr = postdescr .. "\n – " .. goaltipath posthead = "\nObsoletes: " .. go.rpmname(goaltipath, "") .. "-devel < %{version}-%{release}" end postdescr = postdescr .. "\n\nAliasing Go import paths via symbolic links or http redirects is fragile. " .. "If your Go code depends on this package, you should patch it to import " .. "directly %{currentgocanonipath}." fedora.explicitset("currentgoaltdescription", "%{expand:%{?goaltdescription" .. suffix .. "}" .. postdescr .. "}", verbose) fedora.explicitset("currentgoaltheader", "%{expand:%{?goaltheader" .. suffix .. "}" .. posthead .. "}", verbose) fedora.explicitset("currentgoaltname", rpmname .. "-devel", verbose) fedora.explicitset("currentgoaltfilelist", rpmname .. "-%{gofilelist}", verbose) if ismain then fedora.zalias( {"gocanonipath", "goaltsummary", "goaltdescription"}, verbose) end end -- Create a single %package section for a known kind of Go subpackage local function singlepkg(kind, suffix, verbose) local fedora = require "fedora.common" if (kind == "devel") then develenv(suffix, verbose) print( rpm.expand( "%package -n %{currentgodevelname}\n" .. "Summary: %{currentgodevelsummary}\n" .. "BuildRequires: go-rpm-macros\n" .. "BuildArch: noarch\n" .. "%{?currentgodevelheader}\n" .. "%description -n %{currentgodevelname}\n") .. fedora.wordwrap("%{?currentgodeveldescription}") .. "\n") elseif (kind == "alt") then local ismain = (suffix == "") or (suffix == "0") if ismain then fedora.zalias({"goaltipaths","gocid","goaltcid"}, verbose) end fedora.safeset("goaltcid" .. suffix, "%{?gocid" .. suffix .. "}", verbose) if ismain then fedora.zalias({"goaltcid"}, verbose) end for rpmname, goaltipaths in pairs(indexedgoipaths("%{goaltipaths" .. suffix .. "}", "%{goaltcid" .. suffix .. "}")) do altenv(suffix, rpmname, goaltipaths, verbose) print( rpm.expand( "%package -n %{currentgoaltname}\n" .. "Summary: %{currentgoaltsummary}\n" .. "BuildRequires: go-rpm-macros\n" .. "BuildArch: noarch\n" .. "%{?currentgoaltheader}\n" .. "%description -n %{currentgoaltname}\n") .. fedora.wordwrap("%{?currentgoaltdescription}") .. "\n") end else rpm.expand("%{error:Unknown kind of Go subpackage: " .. kind .. "}") end end -- Create one or all %package sections for a known kind of go subpackage local function pkg(kind, suffix, processall, verbose) local fedora = require "fedora.common" if (kind == "devel") then develenvinit() end if processall then for _, suffix in pairs(fedora.getsuffixes(pivot[kind])) do singlepkg(kind, suffix, verbose) end else singlepkg(kind, suffix, verbose) end end -- Create a single %files section for a known kind of Go subpackage local function singlefiles(kind, suffix, verbose) if (kind == "devel") then develenv(suffix, verbose) print(rpm.expand('%files -n %{currentgodevelname} -f "%{goworkdir}/%{currentgodevelfilelist}"\n')) elseif (kind == "alt") then local fedora = require "fedora.common" local ismain = (suffix == "") or (suffix == "0") if ismain then fedora.zalias({"goaltipaths","gocid","goaltcid"}, verbose) end fedora.safeset("goaltcid" .. suffix, "%{?gocid" .. suffix .. "}", verbose) if ismain then fedora.zalias({"goaltcid"}, verbose) end for rpmname, goaltipaths in pairs(indexedgoipaths("%{goaltipaths" .. suffix .. "}", "%{goaltcid" .. suffix .. "}")) do altenv(suffix, rpmname, goaltipaths, verbose) print(rpm.expand('%files -n %{currentgoaltname} -f "%{goworkdir}/%{currentgoaltfilelist}"\n')) end else rpm.expand("%{error:Unknown kind of Go subpackage: " .. kind .. "}") end end -- Create one or all %files sections for a known kind of go subpackage local function files(kind, suffix, processall, verbose) local fedora = require "fedora.common" if (kind == "devel") then develenvinit() end if processall then for _, suffix in pairs(fedora.getsuffixes(pivot[kind])) do singlefiles(kind, suffix, verbose) end else singlefiles(kind, suffix, verbose) end end return { rpmname = rpmname, meta = meta, pivot = pivot, indexedgoipaths = indexedgoipaths, develenvinit = develenvinit, develenv = develenv, altenv = altenv, pkg = pkg, files = files, } srpm/python.lua000064400000007775151074713450007600 0ustar00-- Convenience Lua functions that can be used within Python srpm/rpm macros -- Determine alternate names provided from the given name. -- Used in pythonname provides generator, python_provide and py_provides. -- If only_3_to_3_X is false/nil/unused there are 2 rules: -- python3-foo -> python-foo, python3.X-foo -- python3.X-foo -> python-foo, python3-foo -- If only_3_to_3_X is true there is only 1 rule: -- python3-foo -> python3X-foo -- There is no python-foo -> rule, python-foo packages are version agnostic. -- Returns a table/array with strings. Empty when no rule matched. local function python_altnames(name, only_3_to_3_X) local xy if only_3_to_3_X then -- Here we hardcode the xy prefix we want to obsolete to "39", because: -- 1. Python 3.9 will remain the main Python version in RHEL 9 -- 2. python39 in RHEL 8 is still using the dotless naming (as opposed to -- python3.9) xy = "39" else xy = rpm.expand('%{__default_python3_pkgversion}') end local altnames = {} local replaced -- NB: dash needs to be escaped! if name:match('^python3%-') then local prefixes = only_3_to_3_X and {} or {'python-'} for i, prefix in ipairs({'python' .. xy .. '-', table.unpack(prefixes)}) do replaced = name:gsub('^python3%-', prefix) table.insert(altnames, replaced) end elseif name:match('^python' .. xy .. '%-') and not only_3_to_3_X then for i, prefix in ipairs({'python-', 'python3-'}) do replaced = name:gsub('^python' .. xy .. '%-', prefix) table.insert(altnames, replaced) end end return altnames end local function __python_alttags(name, evr, tag_type) -- for the "provides" tag_type we want also unversioned provides local only_3_to_3_X = tag_type ~= "provides" local operator = tag_type == "provides" and ' = ' or ' < ' -- global cache that tells what package NEVRs were already processed for the -- given tag type if __python_alttags_beenthere == nil then __python_alttags_beenthere = {} end if __python_alttags_beenthere[tag_type] == nil then __python_alttags_beenthere[tag_type] = {} end __python_alttags_beenthere[tag_type][name .. ' ' .. evr] = true local alttags = {} for i, altname in ipairs(python_altnames(name, only_3_to_3_X)) do table.insert(alttags, altname .. operator .. evr) end return alttags end -- For any given name and epoch-version-release, return provides except self. -- Uses python_altnames under the hood -- Returns a table/array with strings. local function python_altprovides(name, evr) return __python_alttags(name, evr, "provides") end -- For any given name and epoch-version-release, return versioned obsoletes except self. -- Uses python_altnames under the hood -- Returns a table/array with strings. local function python_altobsoletes(name, evr) return __python_alttags(name, evr, "obsoletes") end local function __python_alttags_once(name, evr, tag_type) -- global cache that tells what provides were already processed if __python_alttags_beenthere == nil or __python_alttags_beenthere[tag_type] == nil or __python_alttags_beenthere[tag_type][name .. ' ' .. evr] == nil then return __python_alttags(name, evr, tag_type) else return nil end end -- Like python_altprovides but only return something once. -- For each argument can only be used once, returns nil otherwise. -- Previous usage of python_altprovides counts as well. local function python_altprovides_once(name, evr) return __python_alttags_once(name, evr, "provides") end -- Like python_altobsoletes but only return something once. -- For each argument can only be used once, returns nil otherwise. -- Previous usage of python_altobsoletes counts as well. local function python_altobsoletes_once(name, evr) return __python_alttags_once(name, evr, "obsoletes") end return { python_altnames = python_altnames, python_altprovides = python_altprovides, python_altobsoletes = python_altobsoletes, python_altprovides_once = python_altprovides_once, python_altobsoletes_once = python_altobsoletes_once, } srpm/forge.lua000064400000036406151074713450007352 0ustar00-- Lua code used by macros.forge and derivatives -- 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 -- Check if an identified url is sane local function checkforgeurl(url, id, silent) local checkedurl = nil local checkedid = nil local urlpatterns = { gitlab = { pattern = 'https://[^/]+/[^/]+/[^/#?]+', description = 'https://(…[-.])gitlab[-.]…/owner/repo'}, pagure = { pattern = 'https://[^/]+/[^/#?]+', description = 'https://pagure.io/repo'}, pagure_ns = { pattern = 'https://[^/]+/[^/]+/[^/#?]+', description = 'https://pagure.io/namespace/repo'}, pagure_fork = { pattern = 'https://[^/]+/fork/[^/]+/[^/#?]+', description = 'https://pagure.io/fork/owner/repo'}, pagure_ns_fork = { pattern = 'https://[^/]+/fork/[^/]+/[^/]+/[^/#?]+', description = 'https://pagure.io/fork/owner/namespace/repo'}, ["gitea.com"] = { pattern = 'https://[^/]+/[^/]+/[^/#?]+', description = 'https://gitea.com/owner/repo'}, github = { pattern = 'https://[^/]+/[^/]+/[^/#?]+', description = 'https://(…[-.])github[-.]…/owner/repo'}, ["code.googlesource.com"] = { pattern = 'https://code.googlesource.com/[^#?]*[^/#?]+', description = 'https://code.googlesource.com/…/repo'}, ["bitbucket.org"] = { pattern = 'https://[^/]+/[^/]+/[^/#?]+', description = 'https://bitbucket.org/owner/repo'}} if (urlpatterns[id] ~= nil) then checkedurl = string.match(url,urlpatterns[id]["pattern"]) if (checkedurl == nil) then if not silent then rpm.expand("%{error:" .. id .. " URLs must match " .. urlpatterns[id]["description"] .. " !}") end else checkedid = id end end return checkedurl, checkedid end -- Check if an url matches a known forge local function idforge(url, silent) local forgeurl = nil local forge = nil if (url ~= "") then forge = string.match(url, "^[^:]+://([^/]+)/") if (forge == nil) then if not silent then rpm.expand("%{error:URLs must include a protocol such as https:// and a path starting with / !}") end else if (forge == "pagure.io") then if string.match(url, "[^:]+://pagure.io/fork/[^/]+/[^/]+/[^/]+") then forge = "pagure_ns_fork" elseif string.match(url, "[^:]+://pagure.io/fork/[^/]+/[^/]+") then forge = "pagure_fork" elseif string.match(url, "[^:]+://pagure.io/[^/]+/[^/]+") then forge = "pagure_ns" elseif string.match(url, "[^:]+://pagure.io/[^/]+") then forge = "pagure" end elseif (string.match(forge, "^gitlab[%.-]") or string.match(forge, "[%.-]gitlab[%.]")) then forge = "gitlab" elseif (string.match(forge, "^github[%.-]") or string.match(forge, "[%.-]github[%.]")) then forge = "github" end forgeurl, forge = checkforgeurl(url, forge, silent) end end return forgeurl, forge end -- The forgemeta macro main processing function -- See the documentation in the macros.forge file for argument description -- Also called directly by gometa local function meta(suffix, verbose, informative, silent) local fedora = require "fedora.common" local ismain = (suffix == "") or (suffix == "0") if ismain then fedora.zalias({"forgeurl", "forgesource", "forgesetupargs", "archivename", "archiveext", "archiveurl", "topdir", "extractdir", "repo", "owner", "namespace", "scm", "tag", "commit", "shortcommit", "branch", "version", "date", "distprefix"}, verbose) end local variables = { default = { scm = "git", archiveext = "tar.bz2", repo = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "^[^:]+://[^/]+/[^/]+/([^/?#]+)"))}', archivename = "%{repo" .. suffix .. "}-%{ref" .. suffix .. "}", topdir = "%{archivename" .. suffix .. "}" }, gitlab = { archiveurl = "%{forgeurl" .. suffix .. "}/-/archive/%{ref" .. suffix .. "}/%{archivename" .. suffix .. "}.%{archiveext" .. suffix .. "}" }, pagure = { archiveext = "tar.gz", repo = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "^[^:]+://[^/]+/([^/?#]+)"))}', archiveurl = "%{forgeurl" .. suffix .. "}/archive/%{ref" .. suffix .. "}/%{archivename" .. suffix .. "}.%{archiveext" .. suffix .. "}" }, pagure_ns = { archiveext = "tar.gz", namespace = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "^[^:]+://[^/]+/([^/]+)/[^/?#]+"))}', repo = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "^[^:]+://[^/]+/[^/]+/([^/?#]+)"))}', archivename = "%{namespace" .. suffix .. "}-%{repo" .. suffix .. "}-%{ref" .. suffix .. "}", archiveurl = "%{forgeurl" .. suffix .. "}/archive/%{ref" .. suffix .. "}/%{archivename" .. suffix .. "}.%{archiveext" .. suffix .. "}" }, pagure_fork = { archiveext = "tar.gz", owner = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "https://[^/]+/fork/([^/]+)/[^/?#]+"))}', repo = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "https://[^/]+/fork/[^/]+/([^/?#]+)"))}', archivename = "%{owner" .. suffix .. "}-%{repo" .. suffix .. "}-%{ref" .. suffix .. "}", archiveurl = "%{forgeurl" .. suffix .. "}/archive/%{ref" .. suffix .. "}/%{archivename" .. suffix .. "}.%{archiveext" .. suffix .. "}" }, pagure_ns_fork = { owner = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "https://[^/]+/fork/([^/]+)/[^/]+/[^/?#]+"))}', namespace = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "https://[^/]+/fork/[^/]+/([^/]+)/[^/?#]+")}', repo = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "https://[^/]+/fork/[^/]+/[^/]+/([^/?#]+)")}', archivename = "%{owner" .. suffix .. "}-%{namespace" .. suffix .. "}-%{repo" .. suffix .. "}-%{ref" .. suffix .. "}", archiveurl = "%{forgeurl" .. suffix .. "}/archive/%{ref" .. suffix .. "}/%{archivename" .. suffix .. "}.%{archiveext" .. suffix .. "}" }, ["gitea.com"] = { archiveext = "tar.gz", archivename = "%{fileref" .. suffix .. "}", archiveurl = "%{forgeurl" .. suffix .. "}/archive/%{ref" .. suffix .. "}.%{archiveext" .. suffix .. "}", topdir = "%{repo}" }, github = { archiveext = "tar.gz", archivename = "%{repo" .. suffix .. "}-%{fileref" .. suffix .. "}", archiveurl = "%{forgeurl" .. suffix .. "}/archive/%{ref" .. suffix .. "}/%{archivename" .. suffix .. "}.%{archiveext" .. suffix .. "}" }, ["code.googlesource.com"] = { archiveext = "tar.gz", repo = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "^[^:]+://.+/([^/?#]+)"))}', archiveurl = "%{forgeurl" .. suffix .. "}/+archive/%{ref" .. suffix .. "}.%{archiveext" .. suffix .. "}", topdir = "" }, ["bitbucket.org"] = { shortcommit = '%{lua:print(string.sub(rpm.expand("%{commit' .. suffix .. '}"), 1, 12))}', owner = '%{lua:print(string.match(rpm.expand("%{forgeurl' .. suffix .. '}"), "^[^:]+://[^/]+/([^/?#]+)"))}', archivename = "%{owner" .. suffix .. "}-%{repo" .. suffix .. "}-%{shortcommit" .. suffix .. "}", archiveurl = "%{forgeurl" .. suffix .. "}/get/%{ref" .. suffix .. "}.%{archiveext" .. suffix .. "}" } } -- 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 spec = {} for _, v in ipairs({'forgeurl','tag','commit','branch','version'}) do spec[v] = rpm.expand("%{?" .. v .. suffix .. "}") end -- Compute the reference of the object to fetch local isrelease = false if (spec["tag"] ~= "") then ref = "%{?tag" .. suffix .. "}" elseif (spec["commit"] ~= "") then ref = "%{?commit" .. suffix .. "}" elseif (spec["branch"] ~= "") then ref = "%{?branch" .. suffix .. "}" else ref = "%{?version" .. suffix .. "}" isrelease = true end if (rpm.expand(ref) == "") then if (suffix == "") then rpm.expand("%{error:You need to define Version:, %{commit} or %{tag} before the macro invocation !}") else rpm.expand("%{error:You need to define %{version" .. suffix .. "}, %{commit" .. suffix .. "} or %{tag" .. suffix .. "} before the macro invocation !}") end end local forgeurl = spec["forgeurl"] -- For backwards compatibility only local expliciturl = rpm.expand("%{?-u*}") if (expliciturl ~= "") then rpm.expand("%{warn:-u use in %%forgemeta is deprecated, use -z instead to select a separate set of rpm variables!}") forgeurl = expliciturl end local forge forgeurl, forge = idforge(forgeurl, silent) if (forge ~= nil) then fedora.explicitset("forgeurl" .. suffix, forgeurl, verbose) -- Custom processing of quirky forges that can not be handled with simple variables if (forge == "github") then -- 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" .. suffix .. "}") then ref = "v" .. ref elseif (fileref ~= "%{?commit" .. suffix .. "}") and string.match(rpm.expand(fileref), "^v[%d]") then fileref = string.gsub(rpm.expand(fileref), "^v", "") elseif (string.match(rpm.expand(fileref), "/")) then fileref = string.gsub(rpm.expand(fileref), "/", "-") end fedora.safeset("fileref" .. suffix, fileref, verbose) elseif (forge == "gitea.com") then -- Workaround the way gitea mangles /s in ref names local fileref = ref fileref = string.gsub(rpm.expand(fileref), "/", "-") fedora.safeset("fileref" .. suffix, fileref, verbose) elseif (forge == "code.googlesource.com") then if (ref == "%{?version" .. suffix .. "}") then ref = "v" .. ref end elseif (forge == "bitbucket.org") then if (spec["commit"] == "") then rpm.expand("%{error:All BitBucket URLs require commit value knowledge: you need to define %{commit}!}") end end fedora.safeset("ref" .. suffix, ref, verbose) -- Mass setting of the remaining variables for k,v in pairs(variables[forge]) do fedora.safeset(k .. suffix, variables[forge][k], verbose) end for k,v in pairs(variables["default"]) do if (variables[forge][k] == nil) then fedora.safeset(k .. suffix, variables["default"][k], verbose) end end end -- Generic rules for _, v in ipairs({'archiveurl','archivename','archiveext','topdir'}) do spec[v] = rpm.expand("%{?" .. v .. suffix .. "}") end -- Source URL processing (computing the forgesource spec variable) local forgesource = "%{archiveurl" .. suffix .. "}" if (string.match(spec["archiveurl"], "/([^/]+)$") ~= spec["archivename"] .. "." .. spec["archiveext"]) then forgesource = "%{?archiveurl" .. suffix .. "}#/%{?archivename" .. suffix .. "}.%{archiveext" .. suffix .. "}" end fedora.safeset("forgesource" .. suffix, forgesource, verbose) -- Setup processing (computing the forgesetup and extractdir variables) local forgesetupargs = "-n %{extractdir" .. suffix .. "}" local extractdir = "%{topdir" .. suffix .. "}" if (spec["topdir"] == "") then forgesetupargs = "-c " .. forgesetupargs extractdir = "%{archivename" .. suffix .. "}" end if not ismain then if (spec["topdir"] ~= "") then forgesetupargs = "-T -D -b " .. suffix .. " " .. forgesetupargs else forgesetupargs = "-T -D -a " .. suffix .. " " .. forgesetupargs end end fedora.safeset("forgesetupargs" .. suffix, forgesetupargs, verbose) fedora.safeset("extractdir" .. suffix, extractdir, verbose) -- dist processing (computing the correct prefix for snapshots) local distprefix = "" if not isrelease then distprefix = string.lower(rpm.expand(ref)) if (ref == "%{?commit" .. suffix .. "}") then distprefix = string.sub(distprefix, 1, 7) elseif (ref ~= "%{?branch" .. suffix .. "}") then distprefix = string.gsub(distprefix, "[%p%s]+", ".") distprefix = string.gsub(distprefix, "^" .. string.lower(rpm.expand("%{?repo}")) .. "%.?", "") local v = string.gsub(rpm.expand("%{version}"), "[%p%s]+", ".") for _, p in ipairs({'','v','v.','version','version.','tags.v', 'tags.v.'}) do distprefix = getversionsuffix(distprefix, p .. v) end distprefix = string.gsub(distprefix, "^%.", "") end if (distprefix ~= "") then distprefix = "%{scm" .. suffix .. "}" .. distprefix date = rpm.expand("%{?date" .. suffix .. "}") if (date ~= "") then distprefix = date .. distprefix else distprefix = "%([ -r %{_sourcedir}/%{archivename" .. suffix .. "}.%{archiveext" .. suffix .. "} ] && date +%Y%m%d -u -r %{_sourcedir}/%{archivename" .. suffix .. "}.%{archiveext" .. suffix .. "})" .. distprefix end distprefix = "." .. distprefix end end if (spec["version"] ~= "") and (spec["version"] ~= "0") and (spec["version"] ~= rpm.expand("%{?version}")) then distprefix = ".%{version" .. suffix .. "}" .. distprefix end if (rpm.expand(distprefix) ~= "") then if not ismain then distprefix = string.gsub(distprefix, "^%.", ".s") end fedora.safeset ("distprefix" .. suffix, distprefix, verbose) end if ismain then fedora.zalias({"forgeurl", "forgesource", "forgesetupargs", "archivename", "archiveext", "archiveurl", "topdir", "extractdir", "repo", "owner", "namespace", "scm", "shortcommit", "distprefix"}, verbose) end -- Final spec variable summary if the macro was called with -i if informative then rpm.expand("%{echo:Packaging variables read or set by %%forgemeta}") fedora.echovars({"forgeurl", "forgesource", "forgesetupargs", "archivename", "archiveext", "archiveurl", "topdir", "extractdir", "repo", "owner", "namespace", "scm", "tag", "commit", "shortcommit", "branch", "version", "date", "distprefix"}, suffix) fedora.echovars({"dist"},"") rpm.expand("%{echo: (snapshot date is either manually supplied or computed once %%{_sourcedir}/%%{archivename" .. suffix .. "}.%%{archiveext" .. suffix .. "} is available)}") end end return { meta = meta, } common.lua000064400000022771151074713450006557 0ustar00-- Convenience Lua functions that can be used within rpm macros -- Reads an rpm variable. Unlike a basic rpm.expand("{?foo}"), returns nil if -- the variable is unset, which is convenient in lua tests and enables -- differentiating unset variables from variables set to "" local function read(rpmvar) if not rpmvar or (rpm.expand("%{" .. rpmvar .. "}") == "%{" .. rpmvar .. "}") then return nil else return rpm.expand("%{?" .. rpmvar .. "}") end 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 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 local function readflag(flag) if not hasflag(flag) then return nil else local a = rpm.expand("%{-" .. flag .. "*}") -- Handle "" and '' as empty strings if (a == '""') or (a == "''") then a = '' end return a end end -- Sets a spec variable; echoes the result if verbose local function explicitset(rpmvar, value, verbose) local value = value if (value == nil) or (value == "") then value = "%{nil}" end rpm.define(rpmvar .. " " .. value) if verbose then rpm.expand("%{warn:Setting %%{" .. rpmvar .. "} = " .. value .. "}") end end -- 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}") if verbose then rpm.expand("%{warn:Unsetting %%{" .. rpmvar .. "}}") end end end -- 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 -- 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 local toalias = "%{?" .. rpmvar .. sfx[1] .. "}" if (rpm.expand(toalias) ~= "") then safeset(rpmvar .. sfx[2], toalias, verbose) end end end end -- Takes a list of rpm variable roots and a suffix and alias current to -- if it resolves to something not empty local function setcurrent(rpmvars, suffix, verbose) for _, rpmvar in ipairs(rpmvars) do if (rpm.expand("%{?" .. rpmvar .. suffix .. "}") ~= "") then explicitset( "current" .. rpmvar, "%{" .. rpmvar .. suffix .. "}", verbose) else explicitunset("current" .. rpmvar, verbose) end end end -- Echo the list of rpm variables, with suffix, if set local function echovars(rpmvars, suffix) for _, rpmvar in ipairs(rpmvars) do rpmvar = rpmvar .. suffix local header = string.sub(" " .. rpmvar .. ": ",1,21) rpm.expand("%{?" .. rpmvar .. ":%{echo:" .. header .. "%{?" .. rpmvar .. "}}}") end end -- Returns an array, indexed by suffix, containing the non-empy values of -- , with suffix an integer string or the empty string local function getsuffixed(rpmvar) local suffixes = {} zalias({rpmvar}) for suffix=0,9999 do local value = rpm.expand("%{?" .. rpmvar .. suffix .. "}") if (value ~= "") then suffixes[tostring(suffix)] = value end end -- rpm convention is to alias no suffix to zero suffix -- only add no suffix if zero suffix is different local value = rpm.expand("%{?" .. rpmvar .. "}") if (value ~= "") and (value ~= suffixes["0"]) then suffixes[""] = value end return suffixes end -- Returns the list of suffixes, including the empty string, for which -- is set to a non empty value local function getsuffixes(rpmvar) suffixes = {} for suffix in pairs(getsuffixed(rpmvar)) do table.insert(suffixes,suffix) end table.sort(suffixes, function(a,b) return (tonumber(a) or 0) < (tonumber(b) or 0) end) return suffixes end -- Returns the suffix for which has a non-empty value that -- matches best the beginning of the value string local function getbestsuffix(rpmvar, value) local best = nil local currentmatch = "" for suffix, setvalue in pairs(getsuffixed(rpmvar)) do if (string.len(setvalue) > string.len(currentmatch)) and (string.find(value, "^" .. setvalue)) then currentmatch = setvalue best = suffix end end return best end -- %writevars core local function writevars(macrofile, rpmvars) for _, rpmvar in ipairs(rpmvars) do print("sed -i 's\029" .. string.upper("@@" .. rpmvar .. "@@") .. "\029" .. rpm.expand( "%{" .. rpmvar .. "}" ) .. "\029g' " .. macrofile .. "\n") end end -- https://github.com/rpm-software-management/rpm/issues/566 -- Reformat a text intended to be used used in a package description, removing -- rpm macro generation artefacts. -- – remove leading and ending empty lines -- – trim intermediary empty lines to a single line -- – fold on spaces -- Should really be a %%{wordwrap:…} verb local function wordwrap(text) text = rpm.expand(text .. "\n") text = string.gsub(text, "\t", " ") text = string.gsub(text, "\r", "\n") text = string.gsub(text, " +\n", "\n") text = string.gsub(text, "\n+\n", "\n\n") text = string.gsub(text, "^\n", "") text = string.gsub(text, "\n( *)[-*—][  ]+", "\n%1– ") output = "" for line in string.gmatch(text, "[^\n]*\n") do local pos = 0 local advance = "" for word in string.gmatch(line, "%s*[^%s]*\n?") do local wl, bad = utf8.len(word) if not wl then print("%{warn:Invalid UTF-8 sequence detected in:}" .. "%{warn:" .. word .. "}" .. "%{warn:It may produce unexpected results.}") wl = bad end if (pos == 0) then advance, n = string.gsub(word, "^(%s*– ).*", "%1") if (n == 0) then advance = string.gsub(word, "^(%s*).*", "%1") end advance = string.gsub(advance, "– ", " ") pos = pos + wl elseif (pos + wl < 81) or ((pos + wl == 81) and string.match(word, "\n$")) then pos = pos + wl else word = advance .. string.gsub(word, "^%s*", "") output = output .. "\n" pos = utf8.len(word) end output = output .. word if pos > 80 then pos = 0 if not string.match(word, "\n$") then output = output .. "\n" end end end end output = string.gsub(output, "\n*$", "\n") return output end -- Because rpmbuild will fail if a subpackage is declared before the source -- package itself, provide a source package declaration shell as fallback. local function srcpkg(verbose) if verbose then rpm.expand([[ %{echo:Creating a header for the SRPM from %%{source_name}, %%{source_summary} and} %{echo:%%{source_description}. If that is not the intended result, please declare the} %{echo:SRPM header and set %%{source_name} in your spec file before calling a macro} %{echo:that creates other package headers.} ]]) end print(rpm.expand([[ Name: %{source_name} Summary: %{source_summary} %description %wordwrap -v source_description ]])) explicitset("currentname", "%{source_name}", verbose) end -- %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 rpm.expand([[ %{warn:Something already set a package name. However, %%{source_name} is not set.} %{warn:Please set %%{source_name} to the SRPM name to ensure reliable processing.} ]]) if name_suffix then print(rpm.expand("%package " .. name_suffix)) else print(rpm.expand("%package -n " .. pkg_name)) end return end -- New processing if not (pkg_name or name_suffix or source_name) then rpm.expand([[ %{error:You need to set %%{source_name} or provide explicit package naming!} ]]) end if name_suffix then print(rpm.expand("%package " .. name_suffix)) explicitset("currentname", "%{source_name}-" .. name_suffix, verbose) else if not source_name then source_name = pkg_name end if (pkg_name == source_name) then safeset("source_name", source_name, verbose) print(rpm.expand("Name: %{source_name}")) else if source_name and first then srcpkg(verbose) end print(rpm.expand("%package -n " .. pkg_name)) end explicitset("currentname", pkg_name, verbose) end end return { read = read, hasflag = hasflag, readflag = readflag, explicitset = explicitset, explicitunset = explicitunset, safeset = safeset, zalias = zalias, setcurrent = setcurrent, echovars = echovars, getsuffixed = getsuffixed, getsuffixes = getsuffixes, getbestsuffix = getbestsuffix, writevars = writevars, wordwrap = wordwrap, new_package = new_package, }