There was a minor quirk for “--” arguments, but this was sufficient to handle everything I have seen CMake produce. However, it appears differing argument lists can be written by other tools. Specifically the one that led to this issue looks like:
<compiler> … ../foo/bar.c -o bar.o
▲ ▲
│ └─ arguments following source path
└─ path not absolute
This is perfectly reasonable and well within the compilation database specification, but just not something I believed tools produced.
This fix attempts to be more agnostic to the arguments, both their form and the order in which they appear. We now drop “--” and everything following it as well as dropping anything that looks like a source file. This is subject to both false positives:
cc -o bar.c …
▲
└─ this will be incorrectly dropped, as it looks like a source
and false negatives:
cc -x c my_source …
▲
└─ this will be incorrectly kept, as it does not look like a source
but it seems enough to cope with reasonable imagined real world use cases.
The compilation database parsing code was written assuming the format:
There was a minor quirk for “--” arguments, but this was sufficient to handle everything I have seen CMake produce. However, it appears differing argument lists can be written by other tools. Specifically the one that led to this issue looks like:
This is perfectly reasonable and well within the compilation database specification, but just not something I believed tools produced.
This fix attempts to be more agnostic to the arguments, both their form and the order in which they appear. We now drop “--” and everything following it as well as dropping anything that looks like a source file. This is subject to both false positives:
and false negatives:
but it seems enough to cope with reasonable imagined real world use cases.
Github: fixes https://github.com/Smattr/clink/issues/243 Reported-by: Timothy Madden