Skip to content

Commit a9e064c

Browse files
mcgrofMichal Marek
authored andcommitted
coccicheck: add support for requring a coccinelle version
Enable Coccinelle SmPL patches to require a specific version of Coccinelle. In the event that the version does not match we just inform the user, if the user asked to go through all SmPL patches we just inform them of the need for a new version of coccinelle for the SmPL patch and continue on with the rest. This uses the simple kernel scripts/ld-version.sh to create a weight on the version provided by spatch. The -dirty attribute is ignored if supplied, the benefit of scripts/ld-version.sh is it has a long history and well tested. While at it, document the // Options stuff as well. v4: Document // Options and // Requires as well on Documentation/coccinelle.txt. Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> Acked-by: Nicolas Palix <nicolas.palix@imag.fr> Signed-off-by: Michal Marek <mmarek@suse.com>
1 parent dd951fc commit a9e064c

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎Documentation/coccinelle.txt‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,25 @@ thus active by default. However, by indexing the code with
277277
one of these tools, and according to the cocci file used,
278278
spatch could proceed the entire code base more quickly.
279279

280+
SmPL patch specific options
281+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282+
283+
SmPL patches can have their own requirements for options passed
284+
to Coccinelle. SmPL patch specific options can be provided by
285+
providing them at the top of the SmPL patch, for instance:
286+
287+
// Options: --no-includes --include-headers
288+
289+
SmPL patch Coccinelle requirements
290+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291+
292+
As Coccinelle features get added some more advanced SmPL patches
293+
may require newer versions of Coccinelle. If an SmPL patch requires
294+
at least a version of Coccinelle, this can be specified as follows,
295+
as an example if requiring at least Coccinelle >= 1.0.5:
296+
297+
// Requires: 1.0.5
298+
280299
Proposing new semantic patches
281300
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282301

‎scripts/coccicheck‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
# version 1.0.0-rc11.
66
#
77

8+
DIR="$(dirname $(readlink -f $0))/.."
89
SPATCH="`which ${SPATCH:=spatch}`"
910

1011
if [ ! -x "$SPATCH" ]; then
1112
echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/'
1213
exit 1
1314
fi
1415

16+
SPATCH_VERSION=$($SPATCH --version | head -1 | awk '{print $3}')
17+
SPATCH_VERSION_NUM=$(echo $SPATCH_VERSION | ${DIR}/scripts/ld-version.sh)
18+
1519
USE_JOBS="no"
1620
$SPATCH --help | grep "\-\-jobs" > /dev/null && USE_JOBS="yes"
1721

@@ -171,6 +175,16 @@ coccinelle () {
171175
COCCI="$1"
172176

173177
OPT=`grep "Option" $COCCI | cut -d':' -f2`
178+
REQ=`grep "Requires" $COCCI | cut -d':' -f2 | sed "s| ||"`
179+
REQ_NUM=$(echo $REQ | ${DIR}/scripts/ld-version.sh)
180+
if [ "$REQ_NUM" != "0" ] ; then
181+
if [ "$SPATCH_VERSION_NUM" -lt "$REQ_NUM" ] ; then
182+
echo "Skipping coccinele SmPL patch: $COCCI"
183+
echo "You have coccinelle: $SPATCH_VERSION"
184+
echo "This SmPL patch requires: $REQ"
185+
return
186+
fi
187+
fi
174188

175189
# The option '--parse-cocci' can be used to syntactically check the SmPL files.
176190
#

0 commit comments

Comments
 (0)