Sometimes compile_commands.json databases are created without an
absolute path for the driver in the command field. By default the driver
name is appended to the current directory, however if no driver is found
in that location assume it was in the default PATH and try finding it
there
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Just wanted to say that this is my first patch submission to the LLVM/clangd project, so please call me out on any mistake!
The arc tool caught me by surprise by opening the revision before I could double check it, hence the rename and edits...
Thanks, this looks like a good idea to me, but some quibbles with the details:
- for any string, we statically know whether it's path or WD-relative
- we should make sure all the IO gets cached
clang-tools-extra/clangd/QueryDriverDatabase.cpp | ||
---|---|---|
350 | Oops, this has come up before (in CommandMangler). However when we think more carefully, by allowing the driver to be both WD-relative and dir-relative, we're emulating shell behavior (which makes sense, we have an argv!).
So I think we'd rather have something like: if (llvm::none_of(Driver, [](char C) { return llvm::sys::path::is_separator(C); })) { // resolve against path } else { make_absolute(Cmd->Directory, Driver); } | |
357 | I'm not sure it's reasonable to do IO like this before we have a chance to hit the cache (but see above comment, I don't think we need the exists() at all) | |
359 | hmm, this also does IO, and we obviously do need this. I think we need to move this into the cached lookup, so:
|
I think I have fixed what you asked!
About the test, I thought it would be reasonable to test the three cases separately, however I cannot get it to work with a single test file (I think it's some problem with the generated files). Should I duplicate it or is there any way to do it better?
Sorry for my trivial question, but I'm still learning to navigate the codebase...
Thanks, this looks good, just a couple of nits.
I guess you don't have commit access, I'm happy to land this for you when you're happy with it. Just need an email address to associate the commit with.
Yeah, these tests are a pain. I think you'd have to duplicate it, but honestly that's a maintenance trap, and it's really hard to factor out common logic in lit tests.
I think folding in the complicated case into the existing test as you've done is probably best.
clang-tools-extra/clangd/QueryDriverDatabase.cpp | ||
---|---|---|
145 | maybe add an assert inside this if that there are no separators? | |
151 | else log and return none? | |
351–355 | nit: !llvm::none_of -> llvm::any_of |
Done! My email is:
Giulio Girardi <giulio.girardi@protechgroup.it>
Thank you for your help!
Sorry for the delay getting this landed, and thanks for the patch!
It'll be part of the clangd 12 release.
maybe add an assert inside this if that there are no separators?