-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmake-srpm.sh
More file actions
executable file
·280 lines (236 loc) · 7.01 KB
/
make-srpm.sh
File metadata and controls
executable file
·280 lines (236 loc) · 7.01 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/bash
# Copyright (C) 2014 - 2022 Red Hat, Inc.
#
# This file is part of csdiff.
#
# csdiff 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
# any later version.
#
# csdiff 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 csdiff. If not, see <http://www.gnu.org/licenses/>.
SELF="$0"
PKG="csdiff"
die() {
echo "$SELF: error: $1" >&2
exit 1
}
match() {
grep "$@" > /dev/null
}
DST="$(readlink -f "$PWD")"
REPO="$(git rev-parse --show-toplevel)"
test -d "$REPO" || die "not in a git repo"
NV="$(git describe --tags)"
echo "$NV" | match "^$PKG-" || die "release tag not found"
VER="$(echo "$NV" | sed "s/^$PKG-//")"
TIMESTAMP="$(git log --pretty="%cd" --date=iso -1 \
| tr -d ':-' | tr ' ' . | cut -d. -f 1,2)"
VER="$(echo "$VER" | sed "s/-.*-/.$TIMESTAMP./")"
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
test -n "$BRANCH" || die "failed to get current branch name"
test "main" = "${BRANCH}" || VER="${VER}.${BRANCH//[\/-]/_}"
test -z "$(git diff HEAD)" || VER="${VER}.dirty"
NV="${PKG}-${VER}"
printf "\n%s: preparing a release of \033[1;32m%s\033[0m\n\n" "$SELF" "$NV"
if [[ "$1" != "--generate-spec" ]]; then
TMP="$(mktemp -d)"
trap "rm -rf '$TMP'" EXIT
cd "$TMP" >/dev/null || die "mktemp failed"
# clone the repository
git clone "$REPO" "$PKG" || die "git clone failed"
cd "$PKG" || die "git clone failed"
make distcheck || die "'make distcheck' has failed"
SRC_TAR="${NV}.tar"
SRC="${SRC_TAR}.xz"
git archive --prefix="$NV/" --format="tar" HEAD -- . > "$SRC_TAR" \
|| die "failed to export sources"
# use pxz (threaded xz) if available to speed up the compression
if pxz --version | grep '^Parallel PXZ' > /dev/null; then
XZ=pxz
else
XZ=xz
fi
$XZ -c "$SRC_TAR" > "$SRC" || die "failed to compress sources with ${XZ}"
fi
SPEC="./$PKG.spec"
cat > "$SPEC" << EOF
# disable in source builds on EPEL <9
%undefine __cmake_in_source_build
# python2 is not available on RHEL > 7 and Fedora
%if 0%{?rhel} > 7 || 0%{?fedora}
%bcond_with python2
%else
%bcond_without python2
%endif
# build csdiff-static on 64bit RHEL-8+ and Fedora
%if 0%{?__isa_bits} == 64 && (0%{?rhel} > 7 || 0%{?fedora})
%bcond_without static
%else
%bcond_with static
%endif
# python3 support is optional
%bcond_without python3
Name: $PKG
Version: $VER
Release: 1%{?dist}
Summary: Non-interactive tools for processing code scan results in plain-text
License: GPL-3.0-or-later
URL: https://github.com/csutils/csdiff
Source0: https://github.com/csutils/csdiff/releases/download/%{name}-%{version}/%{name}-%{version}.tar.xz
# the following upstream commit is needed to work with up2date csdiff/csgrep
# https://github.com/csutils/csmock/commit/48b09b3a
Conflicts: csmock-plugin-shellcheck <= 2.5
# Use Boost 1.69 on EPEL 7
%if 0%{?rhel} == 7
BuildRequires: boost169-devel
%endif
# Use Boost 1.78 on EPEL 8 and 9
%if 0%{?rhel} == 8 || 0%{?rhel} == 9
BuildRequires: boost1.78-devel
%endif
# Use boost-devel everywhere else
%if 0%{?rhel} > 9 || 0%{?fedora}
BuildRequires: boost-devel
%endif
%if 0%{?rhel} == 7
BuildRequires: cmake3
%else
BuildRequires: cmake
%endif
BuildRequires: gcc-c++
BuildRequires: help2man
BuildRequires: make
%if 0%{?rhel} == 7
Provides: bundled(boost_json)
Provides: bundled(boost_nowide)
%else
# needed for csfilter-kfp --kfp-git-url
Recommends: git-core
%endif
%description
This package contains the csdiff tool for comparing code scan defect lists in
order to find out added or fixed defects, and the csgrep utility for filtering
defect lists using various filtering predicates.
%if %{with static}
%package static
Summary: Statically linked csgrep-static executable
%if 0%{?rhel} == 8 || 0%{?rhel} == 9
BuildRequires: boost1.78-static
%else
BuildRequires: boost-static
%endif
BuildRequires: glibc-static
BuildRequires: libstdc++-static
%description static
This pacakge contains a statically linked csgrep-static executable needed
for context embedding in legacy build environments.
%endif
%if %{with python2}
%package -n python2-%{name}
Summary: Python interface to csdiff for Python 2
BuildRequires: python2-devel
%{?python_provide:%python_provide python2-%{name}}
%description -n python2-%{name}
This package contains the Python 2 binding for the csdiff tool for comparing
code scan defect lists to find out added or fixed defects.
%endif
%if %{with python3}
%package -n python3-%{name}
Summary: Python interface to csdiff for Python 3
BuildRequires: python3-devel
%if 0%{?rhel} == 7
# fallback for epel7 buildroots with outdated RPM macros
%{?python_provide:%python_provide python3-%{name}}
%else
%py_provides python3-%{name}
%endif
%description -n python3-%{name}
This package contains the Python 3 binding for the csdiff tool for comparing
code scan defect lists to find out added or fixed defects.
%endif
%prep
%autosetup
%build
%if 0%{?rhel} == 7
# Set paths for CMake's FindBoost
export BOOST_INCLUDEDIR=/usr/include/boost169
export BOOST_LIBRARYDIR=/usr/lib64/boost169
%endif
%if 0%{?rhel} == 8 || 0%{?rhel} == 9
# Set paths for CMake's FindBoost
export BOOST_INCLUDEDIR=/usr/include/boost1.78
export BOOST_LIBRARYDIR=/usr/lib64/boost1.78
%endif
make version.cc
%if 0%{?rhel} == 7
%cmake3 \\
%else
%cmake \\
%endif
-DCSGREP_STATIC=%{?with_static:ON} \\
-DPYCSDIFF_PYTHON2=%{?with_python2:ON} \\
-DPYCSDIFF_PYTHON3=%{?with_python3:ON} \\
-DVERSION='%{name}-%{version}-%{release}'
%if 0%{?rhel} == 7
%cmake3_build
%else
%cmake_build
%endif
%install
%if 0%{?rhel} == 7
%cmake3_install
%else
%cmake_install
%endif
%check
%if 0%{?rhel} == 7
%ctest3
%else
%ctest
%endif
%files
%doc README
%license COPYING
%{_bindir}/csdiff
%{_bindir}/csfilter-kfp
%{_bindir}/csgrep
%{_bindir}/cshtml
%{_bindir}/cslinker
%{_bindir}/cssort
%{_bindir}/cstrans-df-run
%{_datadir}/%{name}
%{_mandir}/man1/csdiff.1*
%{_mandir}/man1/csfilter-kfp.1*
%{_mandir}/man1/csgrep.1*
%{_mandir}/man1/cshtml.1*
%{_mandir}/man1/cslinker.1*
%{_mandir}/man1/cssort.1*
%{_mandir}/man1/cstrans-df-run.1*
%if %{with static}
%files static
%{_libexecdir}/csgrep-static
%endif
%if %{with python2}
%files -n python2-%{name}
%license COPYING
%{python2_sitearch}/pycsdiff.so
%endif
%if %{with python3}
%files -n python3-%{name}
%license COPYING
%{python3_sitearch}/pycsdiff.so
%endif
EOF
if [[ "$1" != "--generate-spec" ]]; then
rpmbuild -bs "$SPEC" \
--define "_sourcedir ." \
--define "_specdir ." \
--define "_srcrpmdir $DST"
fi