~gotmax23/forge-srpm-macros

forge-srpm-macros/rpm/macros.d/macros.forge -rw-r--r-- 6.2 KiB
b4a5d463Maxwell G ci: awk -> gawk a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# SPDX-License-Identifier: GPL-1.0-or-later
# Copyright (C) 2018-2020 redhat-rpm-config contributors

# Computes forge-related variables for use in the rest of the spec file
# Control variables, flags and arguments:
#   %{forgeurl<number>}  the project url on the target forge
#   %{tag<number>}       the packaged tag, OR
#   %{commit<number>}    the packaged commit, OR
#   %{version<number>}   the packaged version
#                          – %{version}/%{version0} are set via:
#                              Version:
#                          – because git is lacking a built-in version
#                            reference, %{version<number>} will be translated
#                            into %{tag<number>} using unreliable heuristics;
#                            set %{tag<number>} directly if those fail
#   %{date<number>}      the packaged timestamp
#   …                    %forgemeta will compute a huge number of variables:
#                          — the packager can override it by setting some of
#                            those before the %forgemeta call
#                          – use the -i flag to list those variables
#   -z <number>          only process the zth block of definitions
#                        "" for the no-suffix block
#   -i                   list the resulting variable values
#   -s                   silently ignore problems in %{forgeurl<number>}
#   -v                   be verbose
#   -a                   process all sources in one go, instead of using
#                        separate -z calls
%forgemeta(z:isva) %{lua:
local      fedora = require "fedora.common"
local       forge = require "fedora.srpm.forge"
local     verbose =  rpm.expand("%{-v}") ~= ""
local informative =  rpm.expand("%{-i}") ~= ""
local      silent =  rpm.expand("%{-s}") ~= ""
local  processall = (rpm.expand("%{-a}") ~= "") and (rpm.expand("%{-z}") == "")
if processall then
  for _,s in pairs(fedora.getsuffixes("forgeurl")) do
    forge.meta(s,verbose,informative,silent)
  end
else
  forge.meta(rpm.expand("%{-z*}"),verbose,informative,silent)
end
}

# Unpacks sources computed by %forgemeta
#   - In most cases, it is recommended to instead use `%forgeautosetup -p1` so
#     patches are automatically applied.
# Control variables, flags and arguments:
#   %{forgesource<number>}       the source archive that will be processed
#   %{forgesetupargs<number>}    %setup arguments

#   -z <number>                  only process the zth block of definitions
#                                "" for the no-suffix block
#   -v                           be verbose
#   -a                   process all sources in one go, instead of using
#                        separate -z calls
%forgesetup(z:va) %{lua:
local fedora = require "fedora.common"
if (rpm.expand("%{-z}") == "") and (rpm.expand("%{-a}") ~= "") then
  for _,s in pairs(fedora.getsuffixes("forgesetupargs")) do
    print(rpm.expand("%setup %{!-v:-q} %{?forgesetupargs" .. s                     .. "}\\n"))
  end
else
  print(  rpm.expand("%setup %{!-v:-q} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n"))
end
}

# Calls %autosetup using %forgemeta results
#   – Using %forgeautosetup is not recommended in specfiles with multiple
#     %forgeurl definitions,
#     as %autosetup may produce strange results with multiple sources present.
#     If you have have muiltiple sources,
#     you can use `%forgesetup -a` to unpack them all at once and then apply
#     patches manually using the %patch macro.
# Control variables, flags and arguments:
#   -z <number>  process the zth block of definitions
#   -v -N -S -p  relayed to %autosetup
%forgeautosetup(z:vNS:p:q) %{lua:
print(rpm.expand("%autosetup %{-v} %{-N} %{?-S} %{?-p} %{?forgesetupargs" .. rpm.expand("%{-z*}") .. "}\\n"))
}

# Appends the values of %_forgeversionsuffix<number> that %forgemeta sets
# to Version.
# This follows the new Versioning Guidelines that discourage putting release
# snapshot info in Release.
#
# NOTE: %forgeversion MUST be invoked before setting Release.
#
# If no %forgeversionsuffix<number> is set,
# the value is equivalent to %version.
#
# By default, %version and the suffix are separated with a '^'.
#
# Control variables, flags and arguments:
#   -p           Use the pre-release separator '~' instead of '^'
#   -z <number>  Only add the release suffix for a specific block.
#                By default, -z0 is used.
#   -a           Concatenate the release suffixes for all blocks
#   -b           Base version to use. Defaults to %version0

# For example:
#   %global forgeurl https://github.com/foo/bar
#   %global version0 2.15.0
#   %global commit <POST RELEASE SNAPSHOT>
#   %forgemeta
#   [....]
#   Version: %{forgeversion}

%forgeversion(pz:ab:) %{lua:
local fedora = require "fedora.common"
local util = require "fedora.srpm._forge_util"
\
-- Zero-alias version/version0 macros
fedora.zalias({"version", "distprefix", "_forgeversionsuffix"}, nil)
\
-- Determine the seperator
local sep = "^"
if util.get_flag("p") then
    sep = "~"
end
\
-- Determine baseversion
local baseversion = util.get_flag("b", true) or util.get_macro("version0")
if not baseversion then
  rpm.expand(
    "%{error:You must define %%version0" ..
    " (%%global version0 <VERSION>) prior to invoking this macro.}"
  )
end
\
-- Concatenate parts. Clear out %distprefix* to avoid duplicating data in Release.
-- forgemeta stores the same values in _forgeversionsuffix so we can run
-- forgeversion multiple times.
local part = ""
rpm.undefine("distprefix")
if util.get_flag("a") then
  for i=0,9999 do
    local curpart = util.get_macro("_forgeversionsuffix" .. i)
    if curpart then
      part = part .. curpart
    end
    rpm.undefine("distprefix" .. i)
  end
else
  local i = util.get_flag("z", true) or ""
  part = part .. (util.get_macro("_forgeversionsuffix" .. i) or "")
  -- Regardless of whether -a is used, undefine all other distprefixes to avoid
  -- extra information in Release when forgeversion is already used.
  -- See https://bugzilla.redhat.com/show_bug.cgi?id=2359090.
  for i=0,9999 do
    rpm.undefine("distprefix" .. i)
  end
end
\
-- Strip any leading '.'
part = part:gsub("^%.", "")
\
-- Print final version
if part ~= "" then
  print(baseversion .. sep .. part)
else
  print(baseversion)
end
}