-
Notifications
You must be signed in to change notification settings - Fork 2
/
make-srpm.sh
executable file
·177 lines (140 loc) · 5 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
#!/bin/bash
# Copyright (C) 2013-2022 Red Hat, Inc.
#
# This file is part of cswrap.
#
# cswrap 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.
#
# cswrap 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 cswrap. If not, see <http://www.gnu.org/licenses/>.
SELF="$0"
PKG="cswrap"
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"
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 -- . > "${TMP}/${SRC_TAR}" \
|| die "failed to export sources"
cd "$TMP" >/dev/null || die "mktemp failed"
xz -c "$SRC_TAR" > "$SRC" || die "failed to compress sources"
SPEC="$TMP/$SPEC"
fi
cat > "$SPEC" << EOF
# Disable in source builds on EPEL <9
%undefine __cmake_in_source_build
%undefine __cmake3_in_source_build
%define csexec_archs aarch64 ppc64le s390x x86_64
Name: $PKG
Version: $VER
Release: 1%{?dist}
Summary: Generic compiler wrapper
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 cswrap 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
%description
Generic compiler wrapper used by csmock to capture diagnostic messages.
# csexec is available on architectures defined in %%{csexec_archs} only
%ifarch %{csexec_archs}
%package -n csexec
Summary: Dynamic linker wrapper
Conflicts: csexec < %{version}-%{release}
%description -n csexec
This package contains csexec - a dynamic linker wrapper. The wrapper can
be used to run dynamic analyzers and formal verifiers on source RPM package
fully automatically.
%endif
%prep
%autosetup
%build
%cmake3 \\
-DPATH_TO_WRAP=\"%{_libdir}/cswrap\" \\
-DSTATIC_LINKING=ON
%cmake3_build
%check
%ctest3
%install
%cmake3_install
install -m0755 -d "%{buildroot}%{_libdir}"{,/cswrap}
for i in c++ cc g++ gcc clang clang++ cppcheck smatch \\
divc++ divcc diosc++ dioscc gclang++ gclang goto-gcc \\
%{_arch}-redhat-linux-c++ \\
%{_arch}-redhat-linux-g++ \\
%{_arch}-redhat-linux-gcc
do
ln -s ../../bin/cswrap "%{buildroot}%{_libdir}/cswrap/\$i"
done
%files
%license COPYING
%doc README
%{_bindir}/cswrap
%{_libdir}/cswrap
%{_mandir}/man1/%{name}.1*
%ifarch %{csexec_archs}
%files -n csexec
%license COPYING
%{_bindir}/csexec
%{_bindir}/csexec-loader
%{_libdir}/libcsexec-preload.so
%{_mandir}/man1/csexec.1*
%endif
EOF
if [[ "$1" != "--generate-spec" ]]; then
rpmbuild -bs "$SPEC" \
--define "_sourcedir $TMP" \
--define "_specdir $TMP" \
--define "_srcrpmdir $DST"
fi