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

Jani Nikula
2025-01-27T16:17:17Z

On Wed, 22 Jan 2025, Victor Gambier <victor.gambier@inria.fr> wrote:
> Hi Jani,
>
> Could you give me a precise example of what you're trying to do? The
> following works on my end (commit 8aa44ca):
>
> .
> ├── A
> │   ├── cocciincludemain.c
> │   └── cocciincludemain.cocci
> └── B
>     └── cocciinclude1.cocci
>
> (...)/A $ spatch --sp-file ./cocciincludemain.cocci ./cocciincludemain.c
>
> Absolute and relative includes in cocciincludemain.cocci both work:
>
> #include
> "/home/vgambier/Documents/git/coccinelle/playground/B/cocciinclude1.cocci"
>
> #include "../B/cocciinclude1.cocci"

This is what I'm trying to do:

+- A
| +- main.c
+- B
+- main.cocci
+- include.cocci

$ cd A
$ spatch --sp-file ../B/main.cocci main.c

With main.cocci having:

#include "include.cocci"

Currently spatch looks for the include in the CWD only, not next to the
.cocci being processed, nor does -I help in specifying where to look for
the include.

BR,
Jani.

>
> Thanks,
> Victor
>
> On 13/01/2025 17:59, Jani Nikula wrote:
>> On Mon, 13 Jan 2025, Julia Lawall <julia.lawall@inria.fr> wrote:
>>> On Mon, 13 Jan 2025, Jani Nikula wrote:
>>>
>>>> On Mon, 13 Jan 2025, Julia Lawall <julia.lawall@inria.fr> wrote:
>>>>> I don't think there is any search path for .cocci files.
>>>> Oh, so it's always relative to the current working directory? That's a
>>>> bit of a bummer.
>>> It's not a well developed feature. If an include path for it would be
>>> useful, we can add that.
>> It might be. Or do you have any other ideas for reusing match rules or,
>> say, "iterator name" lists, without duplicating them into all .cocci
>> files?
>>
>> So I guess I can try working around not having include search path by
>> running spatch outside of my kernel repo. Does spatch otherwise handle
>> that scenario well, or any caveats there?
>>
>>
>> BR,
>> Jani.
>>
>>

--
Jani Nikula, Intel