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

[RFC] Add system header directories to user flags #853

Closed
wants to merge 1 commit into from

Conversation

micbou
Copy link
Collaborator

@micbou micbou commented Oct 6, 2017

ycmd uses its own engine to complete and jump in include statements since libclang does not return completions in that scenario and the clang_getIncludedFile function behaves in a strange way (it returns nothing after the opening quote or angle bracket). This is done by looking at the include flags from the list of user flags. The issue is that system includes are generally not part of these flags and thus completion and jumping are not available for system headers. A workaround is to call Clang as follows:

clang -x c++ -E -v -

and copy the paths under the #include <...> search starts here: line to the list of flags. Unfortunately, this can't be done programmatically because Clang may not be available on the user system. But what if we provide our own executable that behaves like Clang when passing the -E and -v flags?

This is what the PR essentially does. A small program called ycm_fake_clang (name subject to change) is built along the YCM library. This program takes a list of flags and a filename as its arguments and create the corresponding translation unit. When retrieving the user flags, ycmd calls it like this:

ycm_fake_clang -E -v [flag ...] ycm_dummy_file[.ext]

where [flag ...] is a list of flags relevant to the system includes used to parse the translation unit and [.ext] is the extension of the current file (libclang deduces the language from the file extension when the -x flag is not given). ycmd then extracts the system header directories from the output of this command (as if Clang was called with the -E and -v flags) and adds them to the list of user flags.

This works great on Linux and Windows but is not enough on macOS. Additional include paths are needed on this platform:

  • clang_includes/include: this folder is not automatically added with the -resource-dir flag;
  • mac_includes/include: this one is from the Clang prebuilt binaries.

Fixes #844
Fixes ycm-core/YouCompleteMe#2536
Fixes ycm-core/YouCompleteMe#2790


This change is Reviewable

@puremourning
Copy link
Member

On first glance I think this will mean that it isn’t possible to use the iPhone platform and tool chain anymore?

@micbou
Copy link
Collaborator Author

micbou commented Oct 6, 2017

The --sysroot flag is passed to the fake clang executable so it should still be possible to use a different toolchain.

@bstaletic
Copy link
Collaborator

On first glance, this looks like a good idea, but since different toolchains are important to me, I'll wait for the weekend to properly test this.


Review status: 0 of 186 files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@micbou
Copy link
Collaborator Author

micbou commented Oct 6, 2017

So, it doesn't work when compiled with system libclang. In that case, ycm_fake_clang outputs:

./ycm_fake_clang -resource-dir=/Users/micbou/projects/YouCompleteMe/third_party/ycmd/clang_includes -x c++ -E -v test.cpp
...
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)

which looks good (the -resource-dir flag seems to be ignored). However, this breaks if we prepend mac_includes/include/c++/v1 and clang_includes/include to that list. Now, without --system-libclang, ycm_fake_clang returns:

./ycm_fake_clang -resource-dir=/Users/micbou/projects/YouCompleteMe/third_party/ycmd/clang_includes -x c++ -E -v test.cpp
...
ignoring nonexistent directory "/Users/micbou/projects/YouCompleteMe/third_party/include/c++/v1"
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/Users/micbou/projects/YouCompleteMe/third_party/ycmd/clang/5.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

See the two nonexistent directories include/c++/v1 and clang/5.0.0/include (-resource-dir is still ignored)? That's why we add mac_includes/include/c++/v1 and clang_includes/include in the first place.

If we compare to system Clang with -resource-dir:

echo | clang -resource-dir=/Users/micbou/projects/YouCompleteMe/third_party/ycmd/clang_includes -x c++ -E -v -
...
ignoring nonexistent directory "/Users/micbou/projects/YouCompleteMe/include/c++/v1"
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Users/micbou/projects/YouCompleteMe/third_party/ycmd/clang_includes/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)

Surprisingly,-resource-dir is not ignored. However, it won't work because clang didn't find include/c++/v1. And finally without -resource-dir:

echo | clang -x c++ -E -v -
...
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)

Same result as ycm_fake_clang if compiled with --system-libclang.

Given these results, I am tempted to use system Clang (without -resource-dir) instead of ycm_fake_clang on macOS (or maybe use Clang in priority then fall back to ycm_fake_clang if Clang cannot be found) and to not add the mac_includes/include/c++/v1 and clang_includes/include directories. Thoughts?


Reviewed 7 of 186 files at r1.
Review status: 7 of 186 files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@bstaletic
Copy link
Collaborator

Here are my first test results:

./build.py --system-boost --system-clang --clang-completer

'/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7',
'/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7/x86_64-pc-linux-gnu',
'/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7/backward',
'/home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/clang_includes/include',

./build.py --system-boost --clang-completer


'/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7',
'/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7/x86_64-pc-linux-gnu',
'/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7/backward',
'/home/bstaletic/.vim/pack/bundle/start/YouCompleteMe/third_party/ycmd/clang_includes/include',

echo | g++ -E -v -xc++

/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7/x86_64-pc-linux-gnu
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7/backward
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include-fixed
/usr/include

echo | clang++ -E -v -xc++

/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7/x86_64-pc-linux-gnu
/usr/lib/gcc/x86_64-pc-linux-gnu/7.2.0/include/g++-v7/backward
/usr/lib64/llvm/5/bin/../../../../lib/clang/5.0.0/include
/usr/include

Now can anyone explain why is clang++ looking inside /usr/lib/gcc?


Reviewed 186 of 186 files at r1.
Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@micbou
Copy link
Collaborator Author

micbou commented Oct 6, 2017

That's probably because it looks for the GCC standard library. Try to add the -stdlib=libc++ flag.


Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@codecov-io
Copy link

codecov-io commented Oct 6, 2017

Codecov Report

Merging #853 into master will decrease coverage by 0.06%.
The diff coverage is 100%.

@@            Coverage Diff            @@
##           master    #853      +/-   ##
=========================================
- Coverage   97.67%   97.6%   -0.07%     
=========================================
  Files          90      90              
  Lines        7039    7019      -20     
=========================================
- Hits         6875    6851      -24     
- Misses        164     168       +4

@micbou
Copy link
Collaborator Author

micbou commented Oct 6, 2017

Other than that, your results looks fine. Did you check that :YcmDiags returned no errors in the file?


Review status: 185 of 186 files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@bstaletic
Copy link
Collaborator

Yes, I checked :YcmDiags everything's fine. At least as long as netive comiling is ocncerned.

With arm-none-eabi things.

  • Adding only --sysroot resulted in clang++ and ycm_fake_clang finding only one out of five paths.
  • Either just adding --sysroot or additionally adding --isystem doesn't prevent ycmd from appending whatever "system flags" it finds.

More info about the first point:

What I'm expecting to be found for C:

 /home/bstaletic/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/include
 /home/bstaletic/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/include-fixed
 /home/bstaletic/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/include

What I'm expecting to be found for C++:

 /home/bstaletic/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/include/c++/5.4.1
 /home/bstaletic/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/include/c++/5.4.1/arm-none-eabi
 /home/bstaletic/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/include/c++/5.4.1/backward
 /home/bstaletic/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/include
 /home/bstaletic/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/include-fixed
 /home/bstaletic/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/include

What is clang and ycmd finding with --sysroot=/home/bstaletic/arm-none-eabi/arm-none-eabi? Nothing. At least not in the /home/bstaletic/arm-none-eabi.


Reviewed 1 of 1 files at r2.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@bstaletic
Copy link
Collaborator

For the record, old behaviour was better for cross toolchains as it didn't require --systemroot to stop ycmd from including wrong flags.

@puremourning
Copy link
Member

So I took a look. If I’m honest, my initial reaction is that i don’t really love it. I’m not super keen on shipping an arbitrary copy of the standard library with YCM and the fake clang driver + parsing the result still requires us to ship a (essentially) fake toolchain.

I realise that we have to hack this irritating macOS standard library path thing once a year with each new macOS/Xcode. But i’m convinced there is a canonical way to determine what we need to use programatically from the installed Xcode or command line tools.

For a start, I think we should ask Xcode-select which toolchain to use, then just use that one. That’s allows the user to determine whether to use Xcode or command line tools and avoids any conflict.

The second part of the problem (which I thought i fixed last year) is that the Xcode installation is fiddly and requires some logic that’s built in to the binrary installation location combined with an -isysroot flag for the particular platform target (macOS, iOS, etc.).

FWIW i did try YCM with high sierra when it was GM and it worked fine, and still does for me. So I’m a little perplexed by the current slew of issues.


Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@micbou
Copy link
Collaborator Author

micbou commented Oct 7, 2017

@bstaletic

For the record, old behaviour was better for cross toolchains as it didn't require --systemroot to stop ycmd from including wrong flags.

Are you currently adding the arm-none-eabi flags to your .ycm_extra_conf.py file? If that's the case then libclang is actually adding the wrong flags but internally so you don't see them in :YcmDebugInfo but I can assure you they are added. It works because your include flags take precedence.

@puremourning

I’m not super keen on shipping an arbitrary copy of the standard library with YCM and the fake clang driver + parsing the result still requires us to ship a (essentially) fake toolchain.

Yes, I don't like shipping the standard library either. That's why I am thinking of using system Clang on macOS.

For a start, I think we should ask Xcode-select which toolchain to use, then just use that one. That’s allows the user to determine whether to use Xcode or command line tools and avoids any conflict.

Do you mean running xcode-select with the -p option? If so, I don't see why we wouldn't run clang with the -E and -v options to get the system header paths instead.


Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@bstaletic
Copy link
Collaborator

Yes, I am currently adding -isystem flags to make cross compiled projects work properly. So the current solution is not better, jumt less ugly? Then it's fine, but I'd still like not to see the wrong flags in :YcmDebugInfo.

As for bundling a standard library, I am not a fan of that either, but I don't know much about macOS and how fiddly it is.


Review status: all files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

zzbot added a commit that referenced this pull request Oct 8, 2017
[READY] Only include one of the possible mac toolchains in the include paths

This is the yearly update to fix the latest macOS incompatibilities.

It seems with Xcode 9 (for reasons I really don't understand), having both the Xcode "command line tools" _and_ Xcode in your include paths leads to errors being raised in standard headers.

This change simply only adds a single set of system headers from a single toolchain on macOS.

Fixes ycm-core/YouCompleteMe#2790
Fixes #844
Fixes ycm-core/YouCompleteMe#2536

This is a quicker and probably less contentious solution than #853

This is sort of equivalent to #854, but the implementation is simpler and has working tests.

# Testing

Repro steps:

* with both Xcode and CLT installed create a trivial .ycm_extra_conf.py (flags -x c++ -Wall)
* create a trivial c++ file and `#include <sys/types.h>` and some other c++ headers.
* `:YcmDiags`

I've tested this:

* with both Xcode and CLT
* with just Xcode
* with just CLT

All work.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/valloric/ycmd/855)
<!-- Reviewable:end -->
@zzbot
Copy link
Contributor

zzbot commented Oct 8, 2017

☔ The latest upstream changes (presumably #855) made this pull request unmergeable. Please resolve the merge conflicts.

@micbou micbou force-pushed the fake-clang branch 3 times, most recently from 68599b5 to f62045c Compare October 10, 2017 12:56
@Valloric
Copy link
Member

@micbou Your heart is in the right place, but I don't think this is the best approach to the problem. :(

I'd be for this extra complexity if it would consistently improve the user experience on all OS's we support. But that doesn't appear to be the case.


Review status: 7 of 12 files reviewed at latest revision, all discussions resolved, some commit checks failed.


Comments from Reviewable

@zzbot
Copy link
Contributor

zzbot commented Oct 22, 2017

☔ The latest upstream changes (presumably #860) made this pull request unmergeable. Please resolve the merge conflicts.

@bstaletic
Copy link
Collaborator

Since we were talking about reviving this PR, how about doing what this PR suggests only on Windows and Linux?
For MacOS we can stick to the current heuristics and thus avoid bundling the standard library.


Reviewed 4 of 179 files at r3, 1 of 1 files at r4, 1 of 1 files at r5.
Review status: all files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


ycmd/completers/cpp/flags.py, line 548 at r5 (raw file):

    iter_flags = iter( flags )
    for flag in iter_flags:
      if flag in [ '-x', '--sysroot', '-gcc-toolchain' ]:

-xc++ is also a valid flag, so we would need it in the elif branch too.


Comments from Reviewable

@micbou micbou force-pushed the fake-clang branch 2 times, most recently from 6df29d2 to 8c33f43 Compare August 26, 2018 02:51
Copy link
Collaborator Author

@micbou micbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I revisited the PR and made some improvements:

  • the ycm_fake_clang executable now directly call the libclang routines so it's simpler to compile;
  • the -stdlib and -target flags have been added to the list of flags to pass to Clang;
  • -x<language> is supported (-xc, -xc++, etc.);
  • fully covered.

A summary of the benefits of this PR:

  • add out-of-the-box completion of system headers in include statements;
  • add out-of-the-box navigation to system headers on include statements;
  • remove the system headers code specific to macOS;
  • supersede clang -v -E -x c++ - workaround.

For MacOS we can stick to the current heuristics and thus avoid bundling the standard library.

We don't need to bundle the standard library anymore on macOS since we are using system Clang on this platform to get the system headers.

Reviewed 4 of 186 files at r1, 5 of 179 files at r3, 1 of 1 files at r4, 1 of 1 files at r5, 8 of 13 files at r6.
Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/cpp/flags.py, line 548 at r5 (raw file):

Previously, bstaletic (Boris Staletic) wrote…

-xc++ is also a valid flag, so we would need it in the elif branch too.

Done.

Copy link
Collaborator Author

@micbou micbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r7.
Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/cpp/flags.py, line 514 at r7 (raw file):

def _ExtraClangFlags():
  flags = [ CLANG_RESOURCE_DIR ]

With these changes, adding -resource-dir=clang_includes to the list of flags may not be required anymore since all system headers are already included.

Copy link
Collaborator Author

@micbou micbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failures on CircleCI are unrelated.

Reviewable status: 0 of 2 LGTMs obtained

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default system include paths can't easily change. So, instead of figuring out these paths for each file, maybe we should cache them.
Let's say we only encounter C++ files. The cache could hold only one set of these paths.
If later we encounter a C file, the clang -E -v should be called to add C include paths to the cache.

Another solution would be to eagerly populate the cache for all C-family languages, but that is complicated because cuda might not be set up and -xcuda will fail.

I'm not sure something along these lines is worth the effort, but it's something we should at least consider.

Reviewed 6 of 13 files at r6, 1 of 2 files at r7.
Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/cpp/flags.py, line 514 at r7 (raw file):

Previously, micbou wrote…

With these changes, adding -resource-dir=clang_includes to the list of flags may not be required anymore since all system headers are already included.

Since we're making sure we have some sort of clang executable, we can extract the -resource-dir with clang '-###' -v -xc /dev/null 2>&1 | grep resource.

The output is a long list of strings. Among the quoted strings are "-resource-dir" and "/path/to/resource/dir/".


ycmd/completers/cpp/flags.py, line 664 at r7 (raw file):

    iter_flags = iter( flags )
    for flag in iter_flags:
      if flag in [ '-gcc-toolchain', '--stdlib', '--sysroot', '-target', '-x' ]:

This list isn't done yet.

  • -nostdinc and -nostdinc++ are definitely needed for when an embedded project doesn't want to use system headers.
  • -nostdlib and -nodefaultlibs may not be needed. These change how an executable is linked, but don't seem to change the include path.

@midchildan
Copy link
Contributor


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Here we are talking about discovering default system include paths. Ones you don't specify explicitly, but would be added with -isystem, so replacing -xcuda with -xc++ is not right.

I figured that replacing -xcuda with -xc++ was a bad idea.

Is it possible to get clang to parse a file with -nocudainc, but without -nocudalib?

Only if clang finds the CUDA library location. Otherwise, clang refuses to do anything without -nocudalib.

@micbou micbou force-pushed the fake-clang branch 3 times, most recently from f336694 to fd485c0 Compare August 28, 2018 19:45
Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r13.
Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Previously, midchildan wrote…

Here we are talking about discovering default system include paths. Ones you don't specify explicitly, but would be added with -isystem, so replacing -xcuda with -xc++ is not right.

I figured that replacing -xcuda with -xc++ was a bad idea.

Is it possible to get clang to parse a file with -nocudainc, but without -nocudalib?

Only if clang finds the CUDA library location. Otherwise, clang refuses to do anything without -nocudalib.

I see @micbou added -nocudalib unconditionally in the latest revision. Can anyone confirm that it won't break when a user passes --cuda-path too? If doing that is okay thten this is LGTM. Even without the cache I mentioned.

Copy link
Collaborator Author

@micbou micbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r13, 1 of 1 files at r14.
Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Previously, bstaletic (Boris Staletic) wrote…

I see @micbou added -nocudalib unconditionally in the latest revision. Can anyone confirm that it won't break when a user passes --cuda-path too? If doing that is okay thten this is LGTM. Even without the cache I mentioned.

I was just going to comment about it. This flag is ignored for other languages (Clang just prints a warning that the flag is not used) so it shouldn't be a problem to always add it.

Copy link
Collaborator Author

@micbou micbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Can anyone confirm that it won't break when a user passes --cuda-path too?

Good point. Let me check.

@micbou micbou force-pushed the fake-clang branch 2 times, most recently from 25839f8 to e4d61e6 Compare August 28, 2018 20:26
Copy link
Collaborator Author

@micbou micbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r15, 1 of 1 files at r16.
Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Previously, micbou wrote…

Can anyone confirm that it won't break when a user passes --cuda-path too?

Good point. Let me check.

Seems to work. In fact, if Clang cannot find the CUDA installation path, passing --cuda-path is mandatory with or without -nocudalib.


ycmd/completers/cpp/flags.py, line 742 at r16 (raw file):

  if not match:
    _logger.error( 'Unable to parse system header directories from output '
                   '%s returned by the command %s', stderr, clang_command )

Added some logging when it fails to parse the paths.

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r14.
Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Previously, micbou wrote…

Seems to work. In fact, if Clang cannot find the CUDA installation path, passing --cuda-path is mandatory with or without -nocudalib.

Are you sure? I'm asking because I can get clang to print some paths if I pass -nocudalib and -nostdlib and I certainly did not install a CUDA library. Besides, @midchildan also said clang can work without --cuda-path if -nocudalib and -nocudainc are supplied.


ycmd/completers/cpp/flags.py, line 742 at r16 (raw file):

Previously, micbou wrote…

Added some logging when it fails to parse the paths.

Good idea.

@midchildan
Copy link
Contributor


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Previously, bstaletic (Boris Staletic) wrote…

Are you sure? I'm asking because I can get clang to print some paths if I pass -nocudalib and -nostdlib and I certainly did not install a CUDA library. Besides, @midchildan also said clang can work without --cuda-path if -nocudalib and -nocudainc are supplied.

--cuda-path can be omitted if both --nocudalib and -nocudainc is specified. This is especially useful when using the nvidia-cuda-toolkit package from Debian. Since Debian's version of CUDA change file locations to comply with FHS, supplying --cuda-path won't work.

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r16.
Reviewable status: 0 of 2 LGTMs obtained


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Previously, midchildan wrote…

--cuda-path can be omitted if both --nocudalib and -nocudainc is specified. This is especially useful when using the nvidia-cuda-toolkit package from Debian. Since Debian's version of CUDA change file locations to comply with FHS, supplying --cuda-path won't work.

@midchildan Could you give this PR a test and see if ycmd correctly discovers system include paths for valid CUDA flag configurations?

@midchildan
Copy link
Contributor


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Previously, bstaletic (Boris Staletic) wrote…

@midchildan Could you give this PR a test and see if ycmd correctly discovers system include paths for valid CUDA flag configurations?

I can confirm it works on:

  1. Ubuntu with the nvidia-cuda-toolkit package
  2. macOS

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 LGTMs obtained (and 1 stale)


ycmd/completers/cpp/flags.py, line 673 at r11 (raw file):

Previously, midchildan wrote…

I can confirm it works on:

  1. Ubuntu with the nvidia-cuda-toolkit package
  2. macOS

Thanks for checking.

That's good enough for me. :lgtm:

@zzbot
Copy link
Contributor

zzbot commented Sep 20, 2018

☔ The latest upstream changes (presumably #1103) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Collaborator Author

@micbou micbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the conflicts.

Reviewed 2 of 2 files at r18.
Reviewable status: 0 of 2 LGTMs obtained (and 1 stale)

@joelfrederico
Copy link

I'd like to request the ability to specify and/or deduce Clang. I have a non-standard clang installed by macports. It isn't available on the command line as anything intelligible. If I can specify clang, the includes will be correct for the compiler I'm actually using. Alternatively, clang can be deduced from my compile_commands.json and then the includes will be correct too.

Thoughts?

Copy link
Collaborator

@bstaletic bstaletic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First though: If your custom clang is the first clang in your $PATH everything works as is.

As for customizing the clang we use for flag discovery, here's an idea:

  • For compilation database users use the first argument. Problem is Windows and first argument possibly being cl.exe.
  • For extra conf users add another optional key whose value is the path to clang, falling back to the one in $PATH.

This doesn't work for clang-cl on posix operating systems, but we already don't support that.

Reviewed 1 of 1 files at r17, 2 of 2 files at r18.
Reviewable status: 0 of 2 LGTMs obtained (and 1 stale)

@zzbot
Copy link
Contributor

zzbot commented Oct 14, 2018

☔ The latest upstream changes (presumably #1121) made this pull request unmergeable. Please resolve the merge conflicts.

@zzbot
Copy link
Contributor

zzbot commented Dec 10, 2018

☔ The latest upstream changes (presumably #1118) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Collaborator Author

@micbou micbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't work on this PR anymore as I think the focus should be on the Clangd completer. Closing.

Reviewed 5 of 5 files at r19.
Reviewable status: 0 of 2 LGTMs obtained (and 1 stale)

@micbou micbou closed this Mar 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants