cquery-project / emacs-cquery

Emacs client for cquery, a low-latency language server supporting multi-million line C++ code-bases
116 stars 14 forks source link

Cquery Error: Could not normalize path xxx #47

Open zhuzhongshu opened 6 years ago

zhuzhongshu commented 6 years ago

When I turn on the cquery mode, it will print huge amount of errors in lsp std error buffer, such as :

(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/bits/stringfwd.h
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/bits/stringfwd.h
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/bits/memoryfwd.h
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/iosfwd
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/bits/postypes.h
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/cwchar
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/cwchar
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/iomanip
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/bits/ios_base.h
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.1.1/../../../../include/c++/8.1.1/ext/atomicity.h
(   0.704s) [     FDAB2700]  file_consumer.cc:67    | Could not normalize path 
Silentd00m commented 6 years ago

I can confirm this behaviour under manjaro/arch linux.

Minimal code to trigger it:

test.cpp

#include <iostream>

int main()
{
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.4)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_executable(run test.cpp)

GCC: 8.1.1 20180531

lebyzhao commented 5 years ago

I got the same error, but sometimes it works.

rpav commented 5 years ago

I have this issue as well. This seems to be an issue with NormalizePath and RelPathNotExpandSymlink in platform_posix.cc. It seems this makes naive assumptions about paths, e.g.,

/bin/../lib64/gcc/x86_64-pc-linux-gnu/8.2.1/../../../..
  .. is the same as ..
/

One might assume counting up for and down for .. produces the correct path, and that's what the code seems to do:

    } else if (next_token == "..") {
      // Strip the last path component except when it is single "/"
      if (resolved.size() > 1)
        resolved.resize(resolved.rfind('/', resolved.size() - 2) + 1);
      continue;

However that's not the actual resolution of this path:

$ realpath /bin/../lib64/gcc/x86_64-pc-linux-gnu/8.2.1/../../../..
/usr

And indeed, replacing the call with a call to the "real" realpath(3) (yes it's broken/insecure/etc) fixes this issue for me.

Probably, this needs to find the canonical path of .. whenever it encounters one.

edit: i keep typing relpath :confused: