Re: [cocci] spatch #include statements and include search path

Julia Lawall
2025-01-13T12:09:35Z

On Mon, 13 Jan 2025, Jani Nikula wrote:

>
> I want to use a non-trivial match rule in multiple other rules, in
> multiple .cocci files. I'm trying put the match rule in a separate file,
> and #include that in the other files, to avoid duplication. (I'm
> referring to the "include_cocci ::= #include string" usage of #include,
> not transformations.)
>
> It works when the current working directory is the same as the file to
> be included, but I seem to be unable to make it work from another
> directory.
>
> It doesn't matter if the .cocci files are all in the same directory or
> not, it doesn't seem to matter what I pass as -I to spatch on the
> command-line. I see #include mentioned in the SmPL Grammar as well as
> some tutorials, but I can't find any proper, working examples for it.
>
> How is the #include and the search path supposed to work? There seems to
> be some conflation in the documentation about include_cocci in .cocci
> and #includes in the .c files.
>
> Specifically, I'm running spatch in my kernel repo, and I keep the
> .cocci files in a separate directory outside the kernel repo.

I don't think there is any search path for .cocci files.

I see an example in tests/gadget_soa_defs.cocci that contains

#include "tests/gadget_match.cocci"

There was a problem about the files coming in the wrong order in the case
of multiple included files. I've pushed the recent changes out to github
just now, so that fix should be there.

julia