ccls icon indicating copy to clipboard operation
ccls copied to clipboard

can`t not use compile_commands.json with relative path

Open findNextStep opened this issue 5 years ago • 4 comments

Observed behavior

when we use build system link ninja and the ninja generator compile database with relative path, and ccls just can`t use this json as input

{
  "directory": "/data00/home/panxueqian/development/ccls/build/clang-ninja",
  "command": "/usr/bin/clang++-9   -I../../src -isystem ../../third_party -isystem /usr/lib/llvm-8/include -isystem ../../third_party/rapidjson/include  -O3 -DNDEBUG   -Wall -Wno-sign-compare -pthread -std=c++17 -o CMakeFiles/ccls.dir/src/messages/workspace.cc.o -c /data00/home/panxueqian/development/ccls/src/messages/workspace.cc",
  "file": "/data00/home/panxueqian/development/ccls/src/messages/workspace.cc"
}

Steps to reproduce

for example, cmake generator with ninja

CMAKE_PREFIX_PATH=/usr/lib/llvm-7/lib/cmake/clang cmake -H. -Bbuild/clang-ninja -DCMAKE_CXX_COMPILER=clang++-9 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja

the key is -G Ninja and set compilationDatabaseDirector as ./build/clang-ninja and ccls can`t find system include it happen both in debain and macos, i think it should be easy to recurrent

System information

  • ccls version (0.20190823.5-17-g41e7d6a7 ): # just master
  • OS: mac / linux
  • Editor: vim / vscode
  • Language client (and version): coc.nvim/vscode-ccls

findNextStep avatar Feb 11 '20 07:02 findNextStep

src/project.cc Project::loadDirectory:

  if (g_config->compilationDatabaseCommand.empty()) {
    cdbDir = root;
    if (g_config->compilationDatabaseDirectory.size()) {
      if (sys::path::is_absolute(g_config->compilationDatabaseDirectory))
        cdbDir = g_config->compilationDatabaseDirectory;
      else
////////////// relative compilationDatabaseDirectory is supported
        sys::path::append(cdbDir, g_config->compilationDatabaseDirectory);
    }
    sys::path::append(path, cdbDir, "compile_commands.json");

MaskRay avatar Apr 29 '20 15:04 MaskRay

I found it happend when the first arg in compile_commmans.json is not clang++ In mac the first arg is /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++, if we replace with /usr/local/opt/llvm/bin/clang++, the -I../ arg will work

findNextStep avatar Aug 31 '20 03:08 findNextStep

Having the same issue but I am working in a nix environment where I don't have clang installed since I use gcc. Is there any way I can get ccls working since it prints errors for every header and type used ,which isn't helpful and inhibits all the features and funtionality of ccls .I have clang in my system environment thou.

bernardassan avatar Sep 15 '21 04:09 bernardassan

:smile: for my case it so happens that there was an issue with my path. So to however has a similar issue check and make sure that there are no errors in your include path

bernardassan avatar Sep 16 '21 01:09 bernardassan