Clangd suggestions for third_party/abseil-cpp/* includes

53 views
Skip to first unread message

Roman Sorokin

unread,
Aug 4, 2022, 7:32:39 AM8/4/22
to cxx
Hi cxx!

I wonder why do we include files such as //third_party/abseil-cpp/absl/types/variant.h
as
#include "third_party/abseil-cpp/absl/types/variant.h"
and not as
#include "absl/types/variant.h"
?
It seems that clangd always suggests the latter for me because we have 
"... -I../../third_party/abseil-cpp ..."
for the compiler args.

I guess we're using the former because of the checkdeps for includes:

You added one or more #includes that violate checkdeps rules
...
Illegal include: "absl/types/variant.h"
Because of no rule applying.

Is there a way to fix clangd suggestion or are there any other workarounds? :)

--
Best regards,
Roman Sorokin

Jeroen Dhollander

unread,
Aug 5, 2022, 4:32:16 AM8/5/22
to cxx, Roman Sorokin
I'm also very interested in this as it also annoys me a lot :)

I do not think we need the `-I../../third_party/abseil-cpp` for every source file, as a direct include of absl (and not `third_party/abseil-cpp/absl`) only happens in `third_party/webrtc`.

However I am unable to find where this include rule is added. I only find one occurrence in base/BUILD.gn where it's added but only when enable_nocompile_tests is set. I guess maybe there's some magic to automatically add an include for all third_party directories?

Nico Weber

unread,
Aug 5, 2022, 9:03:05 AM8/5/22
to Jeroen Dhollander, cxx, Roman Sorokin
I don't know the answer to the question (I don't use clangd myself; I'd recommend asking on some clangd users list), but I imagine we have that -I flag because absl headers themselves can include other absl headers, and the absl headers use absl-relative includes.

So the fix here likely can't be "remove that -I flag" but instead will have the rough shape of "when there are multiple possible ways to get an include, tell clangd which one to prefer".

--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/ded6be1d-5919-4fb6-9d06-3a5f26771e30n%40chromium.org.

Peter Kasting

unread,
Aug 5, 2022, 9:06:20 AM8/5/22
to Jeroen Dhollander, cxx, Roman Sorokin
Wouldn't be surprised if this is some public_config leaking from an abseil implementation target.

PK

--

Roman Sorokin

unread,
Aug 5, 2022, 10:33:57 AM8/5/22
to Peter Kasting, Jeroen Dhollander, cxx
On Fri, Aug 5, 2022 at 3:06 PM 'Peter Kasting' via cxx <c...@chromium.org> wrote:
Wouldn't be surprised if this is some public_config leaking from an abseil implementation target.

Nico Weber

unread,
Aug 5, 2022, 11:17:43 AM8/5/22
to Roman Sorokin, Peter Kasting, Jeroen Dhollander, cxx
See my reply above -- I don't think this is leaking, but necessary.

Roman Sorokin

unread,
Aug 5, 2022, 12:00:25 PM8/5/22
to Nico Weber, Peter Kasting, Jeroen Dhollander, cxx
On Fri, Aug 5, 2022 at 5:17 PM Nico Weber <tha...@chromium.org> wrote:
See my reply above -- I don't think this is leaking, but necessary.
Ah, right. Missed it! Makes sense.

I guess for me the easiest solution would be to run a command to replace includes before submitting:
git upstream-diff --name-only -- :^third_party | xargs sed -i 's/\#include "absl/\#include "third_party\/abseil-cpp\/absl/g'


Christian Flach

unread,
Aug 5, 2022, 1:04:17 PM8/5/22
to Roman Sorokin, Nico Weber, Peter Kasting, Jeroen Dhollander, cxx
A similar thing happens when using base::expected - clangd will always auto-import "base/expected_internal.h" instead of "base/expected.h" for me.



--

Google Logo
Christian Flach (he/him)
Software Engineer
cmf...@google.com

Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Liana Sebastian

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls Sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde. 

     

This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.

K. Moon

unread,
Aug 5, 2022, 1:08:08 PM8/5/22
to Christian Flach, Roman Sorokin, Nico Weber, Peter Kasting, Jeroen Dhollander, cxx

Jeroen Dhollander

unread,
Aug 9, 2022, 5:16:15 AM8/9/22
to cxx, km...@chromium.org, Roman Sorokin, tha...@chromium.org, Peter Kasting, Jeroen Dhollander, cxx, Christian Flach
FYI clangd supports pragma's to control its include-what-you-use behavior; I didn't find any pragma to fix the `third_party/absl-cpp` issue, but I did create CL 3819265 to fix the `base/types/expected.h` issue.

Christian Flach

unread,
Sep 5, 2022, 5:31:01 AM9/5/22
to Jeroen Dhollander, cxx, km...@chromium.org, Roman Sorokin, tha...@chromium.org, Peter Kasting
I looked into this some more - here is what I learned:

- IWYU (Include What You Use) is separate from clangd's IncludeCleaner, which just so happens to support the IWYU pragmas.
- IWYU supports mapping files, which are made for exactly the use case brought up in this thread. They would allow you to specify that instead of including `absl/*`, it should include `third_party/abseil-cpp/absl/*`.
- However, there doesn't seem to be an equivalent to these mapping files for clangd's IncludeCleaner. I have opened a feature request for it here: https://github.com/clangd/clangd/issues/1276.
Reply all
Reply to author
Forward
0 new messages