Smattr / clink

a modern re-implementation of Cscope
The Unlicense
38 stars 2 forks source link

clang can not find source file in compilation database #243

Closed terminatorul closed 3 weeks ago

terminatorul commented 2 months ago

Hello !

My work project has about 13000 source files in C (without the headers), and I generated a compilation database for them. I tried with absolute and relative paths, and also both formats in the compilation database (string vs array for the command line)

I built clink with latest clang 18 in openSUSE Tumbleweed.

When running clink with --parse-C=clang, , it says clang can not find the source files in the compilation database. But when I copy and search the source file name, it is right there in the .json file.

Is there a way to fix this, or is the issue directly from clang ?

Can clink also use (and document) the simpler alternative file compile_flags.txt, that can be used by clang instead of compile_commands.json ?

Smattr commented 2 months ago

Thanks for your interest in Clink!

string vs array for the command line

Sorry, what do you mean by this?

I think I’ll need more information about what your Clang database looks like to troubleshoot this one. You could also try running something like clink --debug --jobs=1 and see if there’s anything informative printed to stderr.

Can clink also use (and document) the simpler alternative file compile_flags.txt that can be used by clang instead of compile_commands.json ?

Can you elaborate on your use case for this? At the time I was implementing this feature, I looked at compile_flags.txt but concluded it seemed infeasible to use in any non-trivial project.

terminatorul commented 2 months ago

I have attached my compile database here: compile_commands.json.tar.gz and the namefile list here if it helps: namefile.files.tar.gz

You can look for the "arguments" field in the file format specification from clang (https://clang.llvm.org/docs/JSONCompilationDatabase.html), where I see it is a json array.

Here is the output from clink --debug --jobs 1 --parse-c=clang -i namefile.files >clink_outout.log 2>&1 , up until the first errors reported: clink_outout.log.tar.gz

If I can not use compile_commands.json (lets say because it is too large), maybe some alternatives can work:

Thank you for the support and hopefully this can be fixed or worked-around. This is such a great tool by the way ! Just amazing ... !

Smattr commented 2 months ago

Interesting. Clink claims it can’t find some of these files in the compile_commands.json database, even though they’re clearly there. It’s been a while since I looked at this part of the code base, but I thought it was just interacting with the libclang API, which means libclang can’t find these entries for some reason. I’ll have to debug this a bit further locally… Thanks for attaching those files.

This is such a great tool by the way ! Just amazing ... !

Thanks! Glad you like it :)

terminatorul commented 2 months ago

Is there a way in clang API to check for errors from parsing the compilation database ?

The file was generated by a manually crafted script: compile_commands.pl.gz , maybe I broke something

Smattr commented 4 weeks ago

Sorry it took a while to find time to investigate this one. The problem appears to be that the compilation database parsing code was simply too strict in what it would accept. Do you have time to see if the fix I posted in https://github.com/Smattr/clink/pull/248 works for you?

Smattr commented 4 weeks ago

It occurs to me just now that you also have relative -I… paths in your arguments. Not sure if this will cause problems as well, but lets see if this step gets us some progress first.

Smattr commented 3 weeks ago

I’ll merge the PR now and continue to refine that area going forwards. Let me know if there’s further things you need addressing here.