1
1
#! /bin/bash
2
2
3
+ # actually, the 1.1 in fedora 40 seems to have the relevant patches backported.
4
+ SUGGESTED_SPATCH_VERSION=1.2
3
5
[[ ${V:- 0} != [02] ]] && set -x
4
6
5
7
# to be passed in via environment
6
8
: ${sources[@]?}
7
9
: ${compat_patch?}
8
10
: ${chksum?}
9
11
10
- function die_no_spatch() {
11
- echo " ERROR: no suitable spatch found in \$ PATH. Install package 'coccinelle'!"
12
- exit 1
13
- }
14
-
15
12
# generate compat patches by using the cache,
16
13
# or using spatch,
17
14
# or using curl to fetch it from spatch-as-a-service
@@ -20,17 +17,17 @@ function die_no_spatch() {
20
17
21
18
set -e
22
19
20
+ # compat with older checkouts
23
21
if test -e .compat_patches_applied; then
24
22
echo " Removing compat patches"
25
23
patch -R -p0 --batch --reject-file=- < .compat_patches_applied
26
24
rm -f .compat_patches_applied
27
25
fi
28
26
29
- if ! drbd-kernel-compat/spatch_works.sh drbd-kernel-compat/cocci/ * .cocci > /dev/null 2>&1 ; then
30
- echo " INFO: available spatch is not compatible with at least one patch "
31
- fi
27
+ try_spatch ()
28
+ {
29
+ tried_spatch=false
32
30
33
- if hash spatch && drbd-kernel-compat/spatch_works.sh drbd-kernel-compat/cocci/* .cocci > /dev/null 2>&1 ; then
34
31
K=$( cat $incdir /kernelrelease.txt || echo unknown kernel release)
35
32
echo " GENPATCHNAMES " $K
36
33
gcc -I $incdir -o $incdir /gen_patch_names -std=c99 drbd-kernel-compat/gen_patch_names.c
@@ -66,7 +63,15 @@ if hash spatch && drbd-kernel-compat/spatch_works.sh drbd-kernel-compat/cocci/*.
66
63
67
64
if [ -s $incdir /.compat.cocci ]; then
68
65
# sources=( ... ) passed in via environment
69
- echo " SPATCH $chksum " $K
66
+
67
+ hash spatch || return 1
68
+ echo " COCCISYN $chksum " $K
69
+ if ! spatch --very-quiet --parse-cocci " $incdir /.compat.cocci" > /dev/null 2>&1 ; then
70
+ return 1
71
+ fi
72
+
73
+ tried_spatch=true
74
+ echo " SPATCH $chksum " $K
70
75
set +e
71
76
spatch --sp-file " $incdir /.compat.cocci" " ${sources[@]} " \
72
77
--macro-file drbd-kernel-compat/cocci_macros.h \
@@ -84,8 +89,8 @@ if hash spatch && drbd-kernel-compat/spatch_works.sh drbd-kernel-compat/cocci/*.
84
89
# spatch warnings fatal? not yet.
85
90
# exit 1
86
91
fi
87
- [[ $ex != 0 ]] && exit $ex
88
92
set -e
93
+ [[ $ex != 0 ]] && return $ex
89
94
else
90
95
echo " SPATCH $chksum " $K " - nothing to do"
91
96
fi
@@ -105,26 +110,38 @@ if hash spatch && drbd-kernel-compat/spatch_works.sh drbd-kernel-compat/cocci/*.
105
110
# to better be able to match the "stderr" warnings to their source files
106
111
# rm -f $incdir/.compat.cocci
107
112
rm -f $incdir /.compat.patch
113
+ return 0
114
+ }
115
+
116
+ if try_spatch ; then
117
+ : local spatch run successful or not necessary.
108
118
else
119
+ if $tried_spatch ; then
120
+ echo " local spatch run failed; see above."
121
+ else
122
+ echo " ERROR: no (suitable) spatch found in \$ PATH."
123
+ fi
124
+ # but still try spatch-as-a-service, maybe?
125
+
109
126
if test -e ../.git; then
110
127
echo " INFO: not trying spatch-as-a-service because you are trying"
111
128
echo " to build DRBD from a git checkout. Please install a suitable"
112
- echo " version of coccinelle (>=1.2 ) or try building from a"
129
+ echo " version of coccinelle (>$SUGGESTED_SPATCH_VERSION ) or try building from a"
113
130
echo " release tarball."
114
- die_no_spatch
131
+ exit 1
115
132
fi
116
133
117
134
if [[ $SPAAS != true ]]; then
118
135
echo " INFO: spatch-as-a-service was disabled by your package"
119
136
echo " maintainer (\$ SPAAS = false). Install a suitable version"
120
- echo " of coccinelle (>=1.2 ) or allow spatch-as-a-service by"
137
+ echo " of coccinelle (>$SUGGESTED_SPATCH_VERSION ) or allow spatch-as-a-service by"
121
138
echo " setting \$ SPAAS = true"
122
- die_no_spatch
139
+ exit 1
123
140
fi
124
141
125
- echo " INFO: no suitable spatch found; trying spatch-as-a-service;"
126
- echo " be patient, may take up to 10 minutes"
127
- echo " if it is in the server side cache it might only take a second"
142
+ echo " INFO: spatch failed, or no suitable spatch found; trying spatch-as-a-service;"
143
+ echo " be patient, may take up to 10 minutes. "
144
+ echo " If it is in the server side cache it might only take a second. "
128
145
echo " SPAAS $chksum "
129
146
130
147
# check if SPAAS is even reachable
152
169
else
153
170
mv $compat_patch .tmp $compat_patch
154
171
fi
155
- echo " You can create a new .tgz including this pre-computed compat patch"
156
- echo " by calling \" echo drbd/$compat_patch >>.filelist ; make tgz\" "
157
172
fi
173
+
174
+ # still here?
175
+ echo " You can create a new .tgz including this pre-computed compat patch"
176
+ echo " by calling \" echo drbd/$compat_patch >>.filelist ; make tgz\" "
0 commit comments