aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis R. Rodriguez <mcgrof@kernel.org>2016-06-29 18:14:56 -0400
committerMichal Marek <mmarek@suse.com>2016-07-22 06:13:39 -0400
commitdd951fc1b67b6511d6c8f0449f3d451df374ebce (patch)
treea37f752cbb85cdd88b68937e80f2277206ea1746
parent5c384dba979f7aa57d1f09a6ca1a7cd486e7caba (diff)
scripts: add Linux .cocciconfig for coccinelle
Coccinelle supports reading .cocciconfig, the order of precedence for variables for .cocciconfig is as follows: o Your current user's home directory is processed first o Your directory from which spatch is called is processed next o The directory provided with the --dir option is processed last, if used Since coccicheck runs through make, it naturally runs from the kernel proper dir, as such the second rule above would be implied for picking up a .cocciconfig when using 'make coccicheck'. 'make coccicheck' also supports using M= targets.If you do not supply any M= target, it is assumed you want to target the entire kernel. The kernel coccicheck script has: if [ "$KBUILD_EXTMOD" = "" ] ; then OPTIONS="--dir $srctree $COCCIINCLUDE" else OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE" fi KBUILD_EXTMOD is set when an explicit target with M= is used. For both cases the spatch --dir argument is used, as such third rule applies when whether M= is used or not, and when M= is used the target directory can have its own .cocciconfig file. When M= is not passed as an argument to coccicheck the target directory is the same as the directory from where spatch was called. If not using the kernel's coccicheck target, keep the above precedence order logic of .cocciconfig reading. If using the kernel's coccicheck target, override any of the kernel's .coccicheck's settings using SPFLAGS. We help Coccinelle when used against Linux with a set of sensible defaults options for Linux with our own Linux .cocciconfig. This hints to coccinelle git can be used for 'git grep' queries over coccigrep. A timeout of 200 seconds should suffice for now. The options picked up by coccinelle when reading a .cocciconfig do not appear as arguments to spatch processes running on your system, to confirm what options will be used by Coccinelle run: spatch --print-options-only You can override with your own preferred index option by using SPFLAGS. Coccinelle supports both glimpse and idutils. Glimpse had historically provided the best performance, however recent benchmarks reveal idutils is performing just as well. Due to some recent fixes however you however will need at least coccinelle >= 1.0.6 if using idutils. Coccinelle carries a script scripts/idutils_index.sh which creates the idutils database with as follows: mkid -i C --output .id-utils.index If using just "--use-idutils" coccinelle expects your idutils database to be on the top level of the kernel as a file named ".id-utils.index". If you do not use this you can symlink your database file to it, or you can specify the database file following the "--use-idutils" argument. Examples: make SPFLAGS=--use-idutils coccicheck This assumes you have $srctree/.id-utils.index, where $srctree is the top level of the kernel. make SPFLAGS="--use-idutils /full-path/to/ID" coccicheck Here you specify the full path of the idutils ID database. Using .cocciconfig is possible, however given the order of precedence followed by Coccinelle, and since the kernel now carries its own .cocciconfig, you will need to use SPFLAGS to use idutils if desired. v4: o Recommend upgrade for using idutils with coccinelle due to some recent fixes. o Refer to using --print-options-only for testing what options are picked up by .cocciconfig reading. o Expand commit log considerably explaining *why* .cocconfig from two precedence rules are used when using coccicheck, and how to properly override these if needed. o Expand Documentation/coccinelle.txt v3: Expand commit log a bit more Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Michal Marek <mmarek@suse.com>
-rw-r--r--.cocciconfig3
-rw-r--r--.gitignore1
-rw-r--r--Documentation/coccinelle.txt70
3 files changed, 74 insertions, 0 deletions
diff --git a/.cocciconfig b/.cocciconfig
new file mode 100644
index 000000000000..43967c6b2015
--- /dev/null
+++ b/.cocciconfig
@@ -0,0 +1,3 @@
1[spatch]
2 options = --timeout 200
3 options = --use-gitgrep
diff --git a/.gitignore b/.gitignore
index 0c320bf02586..038ae7a397cd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -66,6 +66,7 @@ Module.symvers
66# 66#
67!.gitignore 67!.gitignore
68!.mailmap 68!.mailmap
69!.cocciconfig
69 70
70# 71#
71# Generated include files 72# Generated include files
diff --git a/Documentation/coccinelle.txt b/Documentation/coccinelle.txt
index 66e822f8caee..b50ac7e126e8 100644
--- a/Documentation/coccinelle.txt
+++ b/Documentation/coccinelle.txt
@@ -189,6 +189,60 @@ work.
189 189
190DEBUG_FILE support is only supported when using coccinelle >= 1.2. 190DEBUG_FILE support is only supported when using coccinelle >= 1.2.
191 191
192 .cocciconfig support
193~~~~~~~~~~~~~~~~~~~~~~
194
195Coccinelle supports reading .cocciconfig for default Coccinelle options that
196should be used every time spatch is spawned, the order of precedence for
197variables for .cocciconfig is as follows:
198
199 o Your current user's home directory is processed first
200 o Your directory from which spatch is called is processed next
201 o The directory provided with the --dir option is processed last, if used
202
203Since coccicheck runs through make, it naturally runs from the kernel
204proper dir, as such the second rule above would be implied for picking up a
205.cocciconfig when using 'make coccicheck'.
206
207'make coccicheck' also supports using M= targets.If you do not supply
208any M= target, it is assumed you want to target the entire kernel.
209The kernel coccicheck script has:
210
211 if [ "$KBUILD_EXTMOD" = "" ] ; then
212 OPTIONS="--dir $srctree $COCCIINCLUDE"
213 else
214 OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE"
215 fi
216
217KBUILD_EXTMOD is set when an explicit target with M= is used. For both cases
218the spatch --dir argument is used, as such third rule applies when whether M=
219is used or not, and when M= is used the target directory can have its own
220.cocciconfig file. When M= is not passed as an argument to coccicheck the
221target directory is the same as the directory from where spatch was called.
222
223If not using the kernel's coccicheck target, keep the above precedence
224order logic of .cocciconfig reading. If using the kernel's coccicheck target,
225override any of the kernel's .coccicheck's settings using SPFLAGS.
226
227We help Coccinelle when used against Linux with a set of sensible defaults
228options for Linux with our own Linux .cocciconfig. This hints to coccinelle
229git can be used for 'git grep' queries over coccigrep. A timeout of 200
230seconds should suffice for now.
231
232The options picked up by coccinelle when reading a .cocciconfig do not appear
233as arguments to spatch processes running on your system, to confirm what
234options will be used by Coccinelle run:
235
236 spatch --print-options-only
237
238You can override with your own preferred index option by using SPFLAGS. Take
239note that when there are conflicting options Coccinelle takes precedence for
240the last options passed. Using .cocciconfig is possible to use idutils, however
241given the order of precedence followed by Coccinelle, since the kernel now
242carries its own .cocciconfig, you will need to use SPFLAGS to use idutils if
243desired. See below section "Additional flags" for more details on how to use
244idutils.
245
192 Additional flags 246 Additional flags
193~~~~~~~~~~~~~~~~~~ 247~~~~~~~~~~~~~~~~~~
194 248
@@ -197,8 +251,24 @@ variable. This works as Coccinelle respects the last flags
197given to it when options are in conflict. 251given to it when options are in conflict.
198 252
199 make SPFLAGS=--use-glimpse coccicheck 253 make SPFLAGS=--use-glimpse coccicheck
254
255Coccinelle supports idutils as well but requires coccinelle >= 1.0.6.
256When no ID file is specified coccinelle assumes your ID database file
257is in the file .id-utils.index on the top level of the kernel, coccinelle
258carries a script scripts/idutils_index.sh which creates the database with
259
260 mkid -i C --output .id-utils.index
261
262If you have another database filename you can also just symlink with this
263name.
264
200 make SPFLAGS=--use-idutils coccicheck 265 make SPFLAGS=--use-idutils coccicheck
201 266
267Alternatively you can specify the database filename explicitly, for
268instance:
269
270 make SPFLAGS="--use-idutils /full-path/to/ID" coccicheck
271
202See spatch --help to learn more about spatch options. 272See spatch --help to learn more about spatch options.
203 273
204Note that the '--use-glimpse' and '--use-idutils' options 274Note that the '--use-glimpse' and '--use-idutils' options