Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Luis R. Rodriguez and committed by
Michal Marek
a9e064c0 dd951fc1

+33
+19
Documentation/coccinelle.txt
··· 277 277 one of these tools, and according to the cocci file used, 278 278 spatch could proceed the entire code base more quickly. 279 279 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 + 280 299 Proposing new semantic patches 281 300 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 282 301
+14
scripts/coccicheck
··· 5 5 # version 1.0.0-rc11. 6 6 # 7 7 8 + DIR="$(dirname $(readlink -f $0))/.." 8 9 SPATCH="`which ${SPATCH:=spatch}`" 9 10 10 11 if [ ! -x "$SPATCH" ]; then 11 12 echo 'spatch is part of the Coccinelle project and is available at http://coccinelle.lip6.fr/' 12 13 exit 1 13 14 fi 15 + 16 + SPATCH_VERSION=$($SPATCH --version | head -1 | awk '{print $3}') 17 + SPATCH_VERSION_NUM=$(echo $SPATCH_VERSION | ${DIR}/scripts/ld-version.sh) 14 18 15 19 USE_JOBS="no" 16 20 $SPATCH --help | grep "\-\-jobs" > /dev/null && USE_JOBS="yes" ··· 175 171 COCCI="$1" 176 172 177 173 OPT=`grep "Option" $COCCI | cut -d':' -f2` 174 + REQ=`grep "Requires" $COCCI | cut -d':' -f2 | sed "s| ||"` 175 + REQ_NUM=$(echo $REQ | ${DIR}/scripts/ld-version.sh) 176 + if [ "$REQ_NUM" != "0" ] ; then 177 + if [ "$SPATCH_VERSION_NUM" -lt "$REQ_NUM" ] ; then 178 + echo "Skipping coccinele SmPL patch: $COCCI" 179 + echo "You have coccinelle: $SPATCH_VERSION" 180 + echo "This SmPL patch requires: $REQ" 181 + return 182 + fi 183 + fi 178 184 179 185 # The option '--parse-cocci' can be used to syntactically check the SmPL files. 180 186 #