niosus / EasyClangComplete

:boom: Robust C/C++ code completion for Sublime Text 3/4
https://niosus.github.io/EasyClangComplete/
MIT License
575 stars 78 forks source link

Fails to normalize relative include paths from compile_commands.json. #313

Closed tillt closed 7 years ago

tillt commented 7 years ago

Please do this before submitting:

Please state the following:

What I need to help you:

Excerpt from huge compile_commands.json located at "/Users/till/Development/mesos-private/build", created using Bear:

    {
        "arguments": [
            "c++",
            "-c",
            "-Qunused-arguments",
            "-fcolor-diagnostics",
            "-fvisibility-inlines-hidden",
            "-Wno-deprecated-declarations",
            "-DPACKAGE_NAME=\"mesos\"",
            "-DPACKAGE_TARNAME=\"mesos\"",
            "-DPACKAGE_VERSION=\"1.5.0\"",
            "-DPACKAGE_STRING=\"mesos 1.5.0\"",
            "-DPACKAGE_BUGREPORT=\"\"",
            "-DPACKAGE_URL=\"\"",
            "-DPACKAGE=\"mesos\"",
            "-DVERSION=\"1.5.0\"",
            "-DSTDC_HEADERS=1",
            "-DHAVE_SYS_TYPES_H=1",
            "-DHAVE_SYS_STAT_H=1",
            "-DHAVE_STDLIB_H=1",
            "-DHAVE_STRING_H=1",
            "-DHAVE_MEMORY_H=1",
            "-DHAVE_STRINGS_H=1",
            "-DHAVE_INTTYPES_H=1",
            "-DHAVE_STDINT_H=1",
            "-DHAVE_UNISTD_H=1",
            "-DHAVE_DLFCN_H=1",
            "-DLT_OBJDIR=\".libs/\"",
            "-DHAVE_CXX11=1",
            "-DHAVE_PTHREAD_PRIO_INHERIT=1",
            "-DHAVE_PTHREAD=1",
            "-DHAVE_FTS_H=1",
            "-DHAVE_APR_POOLS_H=1",
            "-DHAVE_LIBAPR_1=1",
            "-DHAVE_LIBCURL=1",
            "-DHAVE_EVENT2_EVENT_H=1",
            "-DHAVE_LIBEVENT=1",
            "-DHAVE_EVENT2_THREAD_H=1",
            "-DHAVE_LIBEVENT_PTHREADS=1",
            "-DHAVE_GOOGLE_PROTOBUF_MESSAGE_H=1",
            "-DHAVE_LIBSASL2=1",
            "-DHAVE_OPENSSL_SSL_H=1",
            "-DHAVE_EVENT2_BUFFEREVENT_SSL_H=1",
            "-DHAVE_LIBEVENT_OPENSSL=1",
            "-DUSE_SSL_SOCKET=1",
            "-DHAVE_SVN_VERSION_H=1",
            "-DHAVE_LIBSVN_SUBR_1=1",
            "-DHAVE_SVN_DELTA_H=1",
            "-DHAVE_LIBSVN_DELTA_1=1",
            "-DHAVE_ZLIB_H=1",
            "-DHAVE_LIBZ=1",
            "-I.",
            "-I../../src",
            "-Werror",
            "-DLIBDIR=\"/usr/local/lib\"",
            "-DPKGLIBEXECDIR=\"/usr/local/libexec/mesos\"",
            "-DPKGDATADIR=\"/usr/local/share/mesos\"",
            "-DPKGMODULEDIR=\"/usr/local/lib/mesos/modules\"",
            "-I../../include",
            "-I../include",
            "-I../include/mesos",
            "-DPICOJSON_USE_INT64",
            "-D__STDC_FORMAT_MACROS",
            "-isystem",
            "../3rdparty/boost-1.53.0",
            "-isystem",
            "../3rdparty/concurrentqueue-1.0.0-beta",
            "-I../3rdparty/elfio-3.2",
            "-I../3rdparty/glog-0.3.3/src",
            "-I../3rdparty/leveldb-1.19/include",
            "-I../../3rdparty/libprocess/include",
            "-I../3rdparty/nvml-352.79",
            "-I../3rdparty/picojson-1.3.0",
            "-I../../3rdparty/stout/include",
            "-I../3rdparty/zookeeper-3.4.8/src/c/include",
            "-I../3rdparty/zookeeper-3.4.8/src/c/generated",
            "-DHAS_AUTHENTICATION=1",
            "-isystem",
            "/usr/local/opt/subversion/include/subversion-1",
            "-isystem",
            "/usr/local/opt/openssl/include",
            "-isystem",
            "/usr/local/include",
            "-isystem",
            "/usr/local/opt/libevent/include",
            "-isystem",
            "/usr/local/opt/apr/libexec/include/apr-1",
            "-isystem",
            "/usr/local/opt/apr/libexec/include/apr-1.0",
            "-isystem",
            "/usr/local/include",
            "-D_THREAD_SAFE",
            "-pthread",
            "-Wall",
            "-Wsign-compare",
            "-Wformat-security",
            "-fstack-protector-strong",
            "-fPIC",
            "-g",
            "-O0",
            "-Wno-unused-local-typedef",
            "-std=c++11",
            "-stdlib=libc++",
            "-fno-common",
            "-DPIC",
            "-o",
            "docker/.libs/libmesos_no_3rdparty_la-docker.o",
            "../../src/docker/docker.cpp"
        ],
        "directory": "/Users/till/Development/mesos-private/build/src",
        "file": "../../src/docker/docker.cpp"
    },

Output from verbose logging:

[ECC:DEBUG]:[lib_complete.py]:[__init__]:[Thread-12]: using bundled cindex: EasyClangComplete.plugin.clang.cindex40
[ECC:DEBUG]:[compilation_db.py]:[get_flags]:[Thread-12]: [db]:[get]: for file /Users/till/Development/mesos-private/src/docker/docker
[ECC:DEBUG]:[compilation_db.py]:[get_flags]:[Thread-12]: [db]:[cached]: 'None'
[ECC:DEBUG]:[tools.py]:[search]:[Thread-12]: searching 'compile_commands.json' from '/Users/till/Development/mesos-private/build' to '/'
[ECC:DEBUG]:[tools.py]:[search]:[Thread-12]: found 'compile_commands.json' file: /Users/till/Development/mesos-private/build/compile_commands.json
[ECC:DEBUG]:[compilation_db.py]:[get_flags]:[Thread-12]: [db]:[current]: '/Users/till/Development/mesos-private/build/compile_commands.json'
[ECC:DEBUG]:[compilation_db.py]:[get_flags]:[Thread-12]: [db]: found cached compile_commands.json
[ECC:DEBUG]:[compilation_db.py]:[get_flags]:[Thread-12]: [db]:[load cached]
[ECC:DEBUG]:[compilation_db.py]:[get_flags]:[Thread-12]: [db]: return entry for 'all'.
[ECC:DEBUG]:[view_config.py]:[__load_source_flags]:[Thread-12]: flags generated from 'compile_commands.json'.
[ECC:DEBUG]:[lib_complete.py]:[update]:[Thread-12]: view is 143
[ECC:DEBUG]:[lib_complete.py]:[update]:[Thread-12]: translation unit does not exist. Creating.
[ECC:DEBUG]:[lib_complete.py]:[parse_tu]:[Thread-12]: clang flags are: ['-c', '-fsyntax-only', '-x', 'c++', '-std=c++11', '-I/usr/include', '-I/Users/till/Development/mesos-private/src', '-I/usr/lib/clang/4.0.1/include', '-I/Users/till/Development/mesos-private/src/docker', '-Qunused-arguments', '-fcolor-diagnostics', '-fvisibility-inlines-hidden', '-Wno-deprecated-declarations', '-std=c++0x', '-O0', '-Wno-unused-local-typedef', '-fPIC', '-g', '-I/Users/till/Development/mesos-private/build', '-I/Users/till/Development/mesos-private/build/include', '-DOS_MACOSX', '-DLEVELDB_PLATFORM_POSIX', '-DLEVELDB_ATOMIC_PRESENT', '-stdlib=libc++', '-DPACKAGE_NAME="mesos"', '-DPACKAGE_TARNAME="mesos"', '-DPACKAGE_VERSION="1.5.0"', '-DPACKAGE_STRING="mesos 1.5.0"', '-DPACKAGE_BUGREPORT=""', '-DPACKAGE_URL=""', '-DPACKAGE="mesos"', '-DVERSION="1.5.0"', '-DSTDC_HEADERS=1', '-DHAVE_SYS_TYPES_H=1', '-DHAVE_SYS_STAT_H=1', '-DHAVE_STDLIB_H=1', '-DHAVE_STRING_H=1', '-DHAVE_MEMORY_H=1', '-DHAVE_STRINGS_H=1', '-DHAVE_INTTYPES_H=1', '-DHAVE_STDINT_H=1', '-DHAVE_UNISTD_H=1', '-DHAVE_DLFCN_H=1', '-DLT_OBJDIR=".libs/"', '-DHAVE_CXX11=1', '-DHAVE_PTHREAD_PRIO_INHERIT=1', '-DHAVE_PTHREAD=1', '-DHAVE_FTS_H=1', '-DHAVE_APR_POOLS_H=1', '-DHAVE_LIBAPR_1=1', '-DHAVE_LIBCURL=1', '-DHAVE_EVENT2_EVENT_H=1', '-DHAVE_LIBEVENT=1', '-DHAVE_EVENT2_THREAD_H=1', '-DHAVE_LIBEVENT_PTHREADS=1', '-DHAVE_GOOGLE_PROTOBUF_MESSAGE_H=1', '-DHAVE_LIBSASL2=1', '-DHAVE_OPENSSL_SSL_H=1', '-DHAVE_EVENT2_BUFFEREVENT_SSL_H=1', '-DHAVE_LIBEVENT_OPENSSL=1', '-DUSE_SSL_SOCKET=1', '-DHAVE_SVN_VERSION_H=1', '-DHAVE_LIBSVN_SUBR_1=1', '-DHAVE_SVN_DELTA_H=1', '-DHAVE_LIBSVN_DELTA_1=1', '-DHAVE_ZLIB_H=1', '-DHAVE_LIBZ=1', '-I/Users/till/3rdparty/libprocess', '-DBUILD_DIR="/Users/till/Development/mesos-private/build/3rdparty/libprocess"', '-I/Users/till/3rdparty/libprocess/include', '-isystem', '/Users/till/Development/mesos-private/boost-1.53.0', '-isystem', '/Users/till/Development/mesos-private/concurrentqueue-1.0.0-beta', '-I/Users/till/Development/mesos-private/elfio-3.2', '-I/Users/till/Development/mesos-private/glog-0.3.3/src', '-I/Users/till/Development/mesos-private/http-parser-2.6.2', '-DPICOJSON_USE_INT64', '-D__STDC_FORMAT_MACROS', '-I/Users/till/Development/mesos-private/picojson-1.3.0', '-I/Users/till/3rdparty/stout/include', '-isystem', '/usr/local/opt/subversion/include/subversion-1', '-isystem', '/usr/local/opt/openssl/include', '-isystem', '/usr/local/include', '-isystem', '/usr/local/opt/libevent/include', '-isystem', '/usr/local/opt/apr/libexec/include/apr-1', '-isystem', '/usr/local/opt/apr/libexec/include/apr-1.0', '-Wall', '-Wsign-compare', '-Wformat-security', '-fstack-protector-strong', '-fno-common', '-DPIC', '-I/Users/till/Development/src', '-Werror', '-DLIBDIR="/usr/local/lib"', '-DPKGLIBEXECDIR="/usr/local/libexec/mesos"', '-DPKGDATADIR="/usr/local/share/mesos"', '-DPKGMODULEDIR="/usr/local/lib/mesos/modules"', '-I/Users/till/Development/include', '-I/Users/till/Development/mesos-private/include', '-I/Users/till/Development/mesos-private/include/mesos', '-isystem', '/Users/till/Development/mesos-private/3rdparty/boost-1.53.0', '-isystem', '/Users/till/Development/mesos-private/3rdparty/concurrentqueue-1.0.0-beta', '-I/Users/till/Development/mesos-private/3rdparty/elfio-3.2', '-I/Users/till/Development/mesos-private/3rdparty/glog-0.3.3/src', '-I/Users/till/Development/mesos-private/3rdparty/leveldb-1.19/include', '-I/Users/till/Development/3rdparty/libprocess/include', '-I/Users/till/Development/mesos-private/3rdparty/nvml-352.79', '-I/Users/till/Development/mesos-private/3rdparty/picojson-1.3.0', '-I/Users/till/Development/3rdparty/stout/include', '-I/Users/till/Development/mesos-private/3rdparty/zookeeper-3.4.8/src/c/include', '-I/Users/till/Development/mesos-private/3rdparty/zookeeper-3.4.8/src/c/generated', '-DHAS_AUTHENTICATION=1', '-D_THREAD_SAFE', '-pthread', '-fPIE', '-I/Users/till/3rdparty/libprocess/src', '-I/Users/till/Development/mesos-private/googletest-release-1.8.0/googlemock/include', '-I/Users/till/Development/mesos-private/googletest-release-1.8.0/googletest/include', '-DSOURCE_DIR="/Users/till/Development/mesos-private/build/.."', '-DBUILD_DIR="/Users/till/Development/mesos-private/build"', '-I/Users/till/Development/mesos-private/3rdparty/googletest-release-1.8.0/googletest/include', '-isystem', '/Users/till/Development/mesos-private/3rdparty/googletest-release-1.8.0/googlemock/include', '-DTESTLIBEXECDIR="/usr/local/libexec/mesos/tests"', '-DSBINDIR="/usr/local/sbin"', '-I/Users/till/3rdparty/stout', '-Wwrite-strings', '-Woverloaded-virtual', '-Wno-sign-compare', '-DHAVE_CONFIG_H', '-I/Users/till/Development/mesos-private/build/src', '-DNO_FRAME_POINTER', '-DNDEBUG', '-I/Users/till/Development/mesos-private/build/tests', '-I/Users/till/Development/mesos-private/build/generated', '-D_GNU_SOURCE', '-DTHREADED', '-DBUILD_DATE="2017-09-02 23:16:48"', '-DBUILD_TIME="1504387008"', '-DBUILD_USER="till"', '-DBUILD_JAVA_JVM_LIBRARY=""', '-DBUILD_GIT_SHA="899950df2ae6cfc48f0c845176605367cd52c845"', '-DBUILD_GIT_BRANCH="refs/heads/master"', '-DBUILD_FLAGS=""', '-I/Users/till/Development/3rdparty', '-I/Users/till/Development/mesos-private/build/http-parser-2.6.2', '-DHTTP_PARSER_STRICT=0', '-I/Users/till/Development/mesos-private/build/googletest-release-1.8.0/googletest/include', '-I/Users/till/Development/mesos-private/build/googletest-release-1.8.0/googletest', '-I/Users/till/Development/mesos-private/build/googletest-release-1.8.0/googletest/src', '-I/Users/till/Development/mesos-private/build/googletest-release-1.8.0/googlemock/include', '-I/Users/till/Development/mesos-private/build/googletest-release-1.8.0/googlemock', '-I/Users/till/Development/mesos-private/build/googletest-release-1.8.0/googlemock/src', '-O3']
[ECC:DEBUG]:[lib_complete.py]:[parse_tu]:[Thread-12]: compilation started for view id: 143
[ECC:DEBUG]:[lib_complete.py]:[parse_tu]:[Thread-12]: compilation done in 1.3426098823547363 seconds
[ECC:DEBUG]:[lib_complete.py]:[update]:[Thread-12]: reparsing translation_unit for view 143
[ECC:DEBUG]:[lib_complete.py]:[update]:[Thread-12]: reparsed in 1.9788830280303955 seconds
[ECC:DEBUG]:[popup_error_vis.py]:[generate]:[Thread-12]: generating error regions for view 143
[ECC:DEBUG]:[popup_error_vis.py]:[generate]:[Thread-12]: 1 error regions ready
[ECC:DEBUG]:[popup_error_vis.py]:[show_errors]:[Thread-12]: showing error regions: [(1767, 1773), (1767, 1773), (842, 844), (1613, 1620)]
[ECC:DEBUG]:[view_config.py]:[load_for_view]:[Thread-12]: starting timer to remove old configs.
[ECC:DEBUG]:[view_config.py]:[__start_timer]:[Thread-12]: [timer]: start for view: 143
[ECC:DEBUG]:[view_config.py]:[__start_timer]:[Thread-12]: [timer]: active for views: dict_keys([144, 145, 146, 147, 148, 141, 143])
[ECC:DEBUG]:[EasyClangComplete.py]:[config_updated]:[Thread-12]: updated config: <EasyClangComplete.plugin.view_config.ViewConfig object at 0x108a3c650>
[ECC:DEBUG]:[thread_pool.py]:[__stop_progress_animation]:[Thread-12]: Jobs still running: 0
[ECC:DEBUG]:[thread_pool.py]:[__stop_progress_animation]:[Thread-12]: Stopping progress animation.

Note how for example the include original compile_commands.json entry argument:

"-I../../3rdparty/libprocess/include",

Gets transformed into the flags argument:

'-I/Users/till/Development/3rdparty/libprocess/include'

ECC assumed the base path to be the location of the compile_commands.json file - which is, as mentioned above "/Users/till/Development/mesos-private/build".

That assumption is incorrect as the base path should not allways be the location of compile_commands.json but, if available, the entry directory of that compile_commands.json record - that would be "/Users/till/Development/mesos-private/build/src" in my example. Hence the correct flags argument would be:

'-I/Users/till/Development/mesos-private/3rdparty/libprocess/include'

See https://clang.llvm.org/docs/JSONCompilationDatabase.html#format for more.

niosus commented 7 years ago

Thanks! I never say the directory entry, but this is completely valid. We can continue the discussion in the PR. Thanks a lot for this contribution!