Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header Search Paths Broken #2285

Open
cpsauer opened this issue Jan 8, 2021 · 4 comments
Open

Header Search Paths Broken #2285

cpsauer opened this issue Jan 8, 2021 · 4 comments
Assignees
Labels
awaiting-maintainer Awaiting review from Bazel team on issues lang: c++ C++ rules integration os: macos macOS support P3 We're not considering working on this, but happy to review a PR. (No assignee) product: Android Studio Android Studio plugin type: bug

Comments

@cpsauer
Copy link
Contributor

cpsauer commented Jan 8, 2021

Summary: Plugin seems to provide no header search paths to the editor, breaking #include and autocomplete for C++.

Symptoms:

  • All headers #included via non-relative paths are underlined in red ("file not found") in the editor. CMD+click, file details on hover, and build all still work; the file is in the right place and included correctly. Relative paths work fine, since they don't depend on header search paths
  • Not being able to find headers breaks autocomplete for types #included through them.

Suspected Causes
The plugin seems to be failing to set any "Header Search paths".

Running "Show Compiler Info" (via Help->Find Action) shows an empty list of "Header Search paths" for all files examined.
"Compiler switches" contains isystem/iquote flags for all the correct directories, but that doesn't seem to be enough.

I think I can see where the switches--but not the search paths--are set in BlazeCWorkspace.java.

Platform details that shouldn't matter, but I'll include for completeness:
Latest released Android Studio, 4.1.1.
Using a working version of the plugin, patched as in #2265
Latest macOS, 11.1.
Latest Bazel, 3.7.2
Build setup is Android Library that depends on cc_libraries.

Related to, but not the same as #330, since the switches are not null.

Thanks!
Chris
(ex-Googler)

P.S. If, in the meantime, anyone knows a workaround for overriding the header search paths and adding them, I'd love to hear it. This is the last major bug we don't have a workaround for.

@cpsauer
Copy link
Contributor Author

cpsauer commented Feb 3, 2021

Okay, figured out the real issue with the plugin causing this problem.
(I'd written myself a cross-platform Bazel<->VSCode plugin using clangd, and my newfound knowledge about code completion internals let me back out the issue.)

The problem is this plugin wraps clang in a shell script without properly configuring the code-completion system to understand the wrapping. Then, clangd, which Android Studio (and Jetbrains stuff more generally) uses for C-language-family autocomplete, can't introspect that compiler driver well enough to provide autocomplete.

You can make things work by just disabling the wrapper. Fastest way is to just set the compiler to cppExecutable in the following line. I patched my plugin with that change and everything works correctly.

If the blaze_compiler.sh wrapper is important and shouldn't be bypassed, passing the wrapped compiler shell script to to JetBrains's bundled clangd via the --query-driver flag should also do the trick. Not sure if there's a way to do that in the plugin API...I definitely didn't see one in the Android Studio settings GUI.

cpsauer added a commit to hedronvision/bazelbuild-intellij that referenced this issue Feb 4, 2021
See bazelbuild#2285.
Temporary workaround; a real fix should remove the compilerWrapper, use query-driver, or do something more elegant.
@cpsauer
Copy link
Contributor Author

cpsauer commented Feb 4, 2021

Update: Because I needed this change--and some others--to make the the plugin run, I made a temporary fork.

While we're waiting for an official response, check it out if you want this workaround (and others). https://github.com/hedronvision/bazelbuild-intellij

@mai93 mai93 added product: Android Studio Android Studio plugin lang: c++ C++ rules integration type: bug os: macos macOS support labels Feb 8, 2021
cpsauer added a commit to hedronvision/bazelbuild-intellij that referenced this issue Apr 26, 2022
See bazelbuild#2285.
Temporary workaround; a real fix should remove the compilerWrapper, use query-driver, or do something more elegant.
@physxP
Copy link

physxP commented Aug 8, 2022

@cpsauer Thank you so much for the fork! It's working great. Fixes so many of the issues I had with the original plugin.

@cpsauer
Copy link
Contributor Author

cpsauer commented Aug 8, 2022

Glad to hear it! You're very welcome, @physxP!

@sgowroji sgowroji added the awaiting-maintainer Awaiting review from Bazel team on issues label Nov 18, 2022
@mai93 mai93 assigned sgowroji and unassigned mai93 Jan 16, 2023
@sgowroji sgowroji added the P3 We're not considering working on this, but happy to review a PR. (No assignee) label Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-maintainer Awaiting review from Bazel team on issues lang: c++ C++ rules integration os: macos macOS support P3 We're not considering working on this, but happy to review a PR. (No assignee) product: Android Studio Android Studio plugin type: bug
Projects
None yet
Development

No branches or pull requests

4 participants