-
Notifications
You must be signed in to change notification settings - Fork 3
/
make-srpm.sh
executable file
·231 lines (186 loc) · 6.72 KB
/
make-srpm.sh
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
#!/bin/bash
# Copyright (C) 2012-2022 Red Hat, Inc.
#
# This file is part of cscppc.
#
# cscppc 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.
#
# cscppc 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 cscppc. If not, see <http://www.gnu.org/licenses/>.
SELF="$0"
PKG="cscppc"
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 "%s: preparing a release of \033[1;32m%s\033[0m\n" "$SELF" "$NV"
SPEC="$PKG.spec"
TMP="$(mktemp -d)"
trap "rm -rf '$TMP'" EXIT
pushd "$TMP" >/dev/null || die "mktemp failed"
# clone the repository
git clone --recurse-submodules "$REPO" "$PKG" \
|| die "git clone failed"
pushd "$PKG" || die "git clone failed"
if [[ "$1" != "--generate-sources" ]]; then
make distcheck || die "'make distcheck' has failed"
fi
SRC_TAR="${NV}.tar"
SRC="${SRC_TAR}.xz"
git archive --prefix="$NV/" --format="tar" HEAD -- . > "${TMP}/${SRC_TAR}" \
|| die "failed to export sources"
(cd cswrap && git archive --prefix="$NV/cswrap/" --format="tar" HEAD -- \
src/cswrap-util.{c,h} > ../cswrap-util.tar) \
|| die "failed to export submodule"
tar -Af "${TMP}/${SRC_TAR}" cswrap-util.tar \
|| die "failed to concatenate TAR"
popd >/dev/null || die "mktemp failed"
xz -c "${TMP}/${SRC_TAR}" > "${TMP}/${SRC}" \
|| die "failed to compress sources"
if [[ "$1" == "--generate-sources" ]]; then
popd > /dev/null
mv "${TMP}/${SRC}" .
else
SPEC="$TMP/$SPEC"
fi
cat > "$SPEC" << EOF
# Disable in source builds on EPEL <9
%undefine __cmake_in_source_build
%undefine __cmake3_in_source_build
Name: $PKG
Version: $VER
Release: 1%{?dist}
Summary: A compiler wrapper that runs Cppcheck in background
License: GPL-3.0-or-later
URL: https://github.com/csutils/%{name}
Source0: https://github.com/csutils/%{name}/releases/download/%{name}-%{version}/%{name}-%{version}.tar.xz
BuildRequires: asciidoc
BuildRequires: cmake3
BuildRequires: gcc
# csmock copies the resulting cscppc binary into mock chroot, which may contain
# an older (e.g. RHEL-7) version of glibc, and it would not dynamically link
# against the old version of glibc if it was built against a newer one.
# Therefore, we link glibc statically.
BuildRequires: glibc-static
# The test-suite runs automatically trough valgrind if valgrind is available
# on the system. By not installing valgrind into mock's chroot, we disable
# this feature for production builds on architectures where valgrind is known
# to be less reliable, in order to avoid unnecessary build failures (see RHBZ
# #810992, #816175, and #886891). Nevertheless developers are free to install
# valgrind manually to improve test coverage on any architecture.
%ifarch %{ix86} x86_64
BuildRequires: valgrind
%endif
%if 0%{?rhel} != 7
# cscppc is linked statically and can be used by csmock in chroot environment
# the {cwe} field in --template option is supported since cppcheck-1.85
Recommends: cppcheck >= 1.85
%endif
# older versions of csdiff do not read CWE numbers from Cppcheck output
Conflicts: csdiff < 1.8.0
%description
This package contains the cscppc compiler wrapper that runs Cppcheck in
background fully transparently.
%package -n csclng
Summary: A compiler wrapper that runs Clang in background
Requires: clang
Conflicts: csmock-plugin-clang < 1.5.0
%description -n csclng
This package contains the csclng compiler wrapper that runs the Clang analyzer
in background fully transparently.
%package -n csgcca
Summary: A compiler wrapper that runs GCC analyzer in background
Requires: gcc
%description -n csgcca
This package contains the csgcca compiler wrapper that runs GCC analyzer
in background fully transparently.
%package -n csmatch
Summary: A compiler wrapper that runs Smatch in background
%if 0%{?rhel} != 7
Recommends: smatch
%endif
%description -n csmatch
This package contains the csmatch compiler wrapper that runs the Smatch analyzer
in background fully transparently.
%prep
%autosetup
%build
%cmake3 \\
-DPATH_TO_CSCPPC=\"%{_libdir}/cscppc\" \\
-DPATH_TO_CSCLNG=\"%{_libdir}/csclng\" \\
-DPATH_TO_CSGCCA=\"%{_libdir}/csgcca\" \\
-DPATH_TO_CSMATCH=\"%{_libdir}/csmatch\" \\
-DSTATIC_LINKING=ON
%cmake3_build
%check
%ctest3
%install
%cmake3_install
install -m0755 -d "%{buildroot}%{_libdir}"{,/cs{cppc,clng,gcca,match}}
for i in {,g}cc clang %{_arch}-redhat-linux-gcc
do
ln -s ../../bin/cscppc "%{buildroot}%{_libdir}/cscppc/\$i"
ln -s ../../bin/csclng "%{buildroot}%{_libdir}/csclng/\$i"
ln -s ../../bin/csgcca "%{buildroot}%{_libdir}/csgcca/\$i"
ln -s ../../bin/csmatch "%{buildroot}%{_libdir}/csmatch/\$i"
done
for i in {c,g,clang}++ %{_arch}-redhat-linux-{c,g}++
do
ln -s ../../bin/cscppc "%{buildroot}%{_libdir}/cscppc/\$i"
ln -s ../../bin/csclng++ "%{buildroot}%{_libdir}/csclng/\$i"
done
%files
%license COPYING
%doc README
%{_bindir}/cscppc
%{_datadir}/cscppc
%{_libdir}/cscppc
%{_mandir}/man1/%{name}.1*
%files -n csclng
%license COPYING
%{_bindir}/csclng
%{_bindir}/csclng++
%{_libdir}/csclng
%{_mandir}/man1/csclng.1*
%files -n csgcca
%license COPYING
%{_bindir}/csgcca
%{_libdir}/csgcca
%{_mandir}/man1/csgcca.1*
%files -n csmatch
%license COPYING
%{_bindir}/csmatch
%{_libdir}/csmatch
%{_mandir}/man1/csmatch.1*
EOF
if [[ "$1" != "--generate-sources" ]]; then
rpmbuild -bs "$SPEC" \
--define "_sourcedir $TMP" \
--define "_specdir $TMP" \
--define "_srcrpmdir $DST"
fi