Skip to content

Commit 52f5282

Browse files
Merge drbd-9.2/6535593f3 'build: test for working coccinelle instead of version'
2 parents 305736e + 6535593 commit 52f5282

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

drbd/drbd-kernel-compat/gen_compat_patch.sh

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#!/bin/bash
22

3+
# actually, the 1.1 in fedora 40 seems to have the relevant patches backported.
4+
SUGGESTED_SPATCH_VERSION=1.2
35
[[ ${V:-0} != [02] ]] && set -x
46

57
# to be passed in via environment
68
: ${sources[@]?}
79
: ${compat_patch?}
810
: ${chksum?}
911

10-
function die_no_spatch() {
11-
echo "ERROR: no suitable spatch found in \$PATH. Install package 'coccinelle'!"
12-
exit 1
13-
}
14-
1512
# generate compat patches by using the cache,
1613
# or using spatch,
1714
# or using curl to fetch it from spatch-as-a-service
@@ -20,17 +17,17 @@ function die_no_spatch() {
2017

2118
set -e
2219

20+
# compat with older checkouts
2321
if test -e .compat_patches_applied; then
2422
echo "Removing compat patches"
2523
patch -R -p0 --batch --reject-file=- < .compat_patches_applied
2624
rm -f .compat_patches_applied
2725
fi
2826

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
3230

33-
if hash spatch && drbd-kernel-compat/spatch_works.sh drbd-kernel-compat/cocci/*.cocci >/dev/null 2>&1 ; then
3431
K=$(cat $incdir/kernelrelease.txt || echo unknown kernel release)
3532
echo " GENPATCHNAMES "$K
3633
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/*.
6663

6764
if [ -s $incdir/.compat.cocci ]; then
6865
# 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
7075
set +e
7176
spatch --sp-file "$incdir/.compat.cocci" "${sources[@]}" \
7277
--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/*.
8489
# spatch warnings fatal? not yet.
8590
# exit 1
8691
fi
87-
[[ $ex != 0 ]] && exit $ex
8892
set -e
93+
[[ $ex != 0 ]] && return $ex
8994
else
9095
echo " SPATCH $chksum "$K" - nothing to do"
9196
fi
@@ -105,26 +110,38 @@ if hash spatch && drbd-kernel-compat/spatch_works.sh drbd-kernel-compat/cocci/*.
105110
# to better be able to match the "stderr" warnings to their source files
106111
# rm -f $incdir/.compat.cocci
107112
rm -f $incdir/.compat.patch
113+
return 0
114+
}
115+
116+
if try_spatch ; then
117+
: local spatch run successful or not necessary.
108118
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+
109126
if test -e ../.git; then
110127
echo " INFO: not trying spatch-as-a-service because you are trying"
111128
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"
113130
echo " release tarball."
114-
die_no_spatch
131+
exit 1
115132
fi
116133

117134
if [[ $SPAAS != true ]]; then
118135
echo " INFO: spatch-as-a-service was disabled by your package"
119136
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"
121138
echo " setting \$SPAAS = true"
122-
die_no_spatch
139+
exit 1
123140
fi
124141

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."
128145
echo " SPAAS $chksum"
129146

130147
# check if SPAAS is even reachable
@@ -152,6 +169,8 @@ else
152169
else
153170
mv $compat_patch.tmp $compat_patch
154171
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\""
157172
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

Comments
 (0)