atilaneves/cmake-ide

-DQT_TESTCASE_BUILDDIR option in compile line breaks cmake-ide

sbroberg opened this issue · 13 comments

Hi,

I've recently upgraded to cmake 3.10 from cmake 2.8, and qt 5.5 to qt 5.9, and one of the things that has changed is that this line now appears in my compilation:

-DQT_TESTCASE_BUILDDIR=\\\"/Users/stebro/ourproject/build_debug\\\"

For reasons unknown to me, this is breaking cmake-ide when it does its analysis of the compile_commands.json file.

Under normal circumstances, this is what I see in Messages when opening a file in our project:

cmake-ide [Fri Dec 22 16:48:03 2017]: Making directory /var/folders/bv/5qmzyrw94_lbq7qpql9pykr4fm0g52/T/cmake48299_3u
cmake-ide [Fri Dec 22 16:48:03 2017]: Starting rdm server
cmake-ide [Fri Dec 22 16:48:03 2017]: Converting JSON CDB /Users/stebro/ourproject/build_debug/compile_commands.json to IDB
cmake-ide [Fri Dec 22 16:48:07 2017]: Setting flags for file /Users/stebro/ourproject/daemon/src/services/scan/DirectoryCache.cpp
cmake-ide [Fri Dec 22 16:48:07 2017]: Running rc for rtags

However, with the flag above in the compilation line, I get:

cmake-ide [Fri Dec 22 16:50:57 2017]: Making directory /var/folders/bv/5qmzyrw94_lbq7qpql9pykr4fm0g52/T/cmake49555v6u
cmake-ide [Fri Dec 22 16:50:57 2017]: Starting rdm server
cmake-ide [Fri Dec 22 16:50:57 2017]: Converting JSON CDB /Users/stebro/ourproject/build_debug/compile_commands.json to IDB
split-string-and-unquote: End of file during parsing

After putting some logging into the cmake-ide.el file, it appears that it is happening during the setting of all-commands in cmake-ide--set-flags-for-file.

Here is an example of the compile_commands.json that produces the error:

[ { "directory": "/Users/stebro/ourproject/build_debug/ui/tests", "command": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DPRODVER_BUILD_NO=9999 -DPRODVER_FULL=\\\"2.6.9999\\\" -DPRODVER_MAJOR=2 -DPRODVER_MINOR=6 -DPRODVER_STRING=\"\\\"2.6.1local build 9999 (2017-12-22 16:50:28)\\\"\" -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_TESTCASE_BUILDDIR=\\\"/Users/stebro/ourproject/build_debug\\\" -DQT_TESTLIB_LIB -DQT_WIDGETS_LIB -I/Users/stebro/ourproject/build_debug/ui/tests -I/Users/stebro/ourproject/ui/tests -I/Users/stebro/ourproject/build_debug/ui/tests/OurprojectUI.unit_test_autogen/include -isystem /Volumes/OurprojectToolChain/include -isystem /Volumes/OurprojectToolChain/include/log4qt -isystem /Volumes/OurprojectToolChain/include/log4qt/varia -I/Users/stebro/ourproject/ui -iframework /Volumes/OurprojectToolChain/qt-5.5/lib -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtCore.framework/Headers -isystem /Volumes/OurprojectToolChain/qt-5.5/./mkspecs/macx-clang -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtNetwork.framework/Headers -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtGui.framework/Headers -isystem /System/Library/Frameworks/OpenGL.framework/Headers -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtWidgets.framework/Headers -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtTest.framework/Headers -I/Users/stebro/ourproject/ClientShared/include -I/Users/stebro/ourproject/build_debug/ClientShared/include -stdlib=libc++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.7 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.7 -stdlib=libc++ -Werror -Wno-c99-extensions -Wno-c++98-compat -Wreorder -Wunused-variable -Woverloaded-virtual -Wno-unused-local-typedef -Wno-inconsistent-missing-override -Wunused-function -Wno-unknown-warning-option -Wno-nonportable-include-path -Wno-deprecated-declarations -Wno-unused-const-variable -Wno-redeclared-class-member -Wno-header-guard -Wno-logical-not-parentheses -Wno-#warnings -fPIC -std=gnu++11 -o CMakeFiles/OurprojectUI.unit_test.dir/__/ui/abstractinfoprovider.cpp.o -c /Users/stebro/ourproject/ui/ui/abstractinfoprovider.cpp", "file": "/Users/stebro/ourproject/ui/ui/abstractinfoprovider.cpp" } ]

Update: Moving the parameter around in the compile line eliminated the error, so I'm assuming that the real culprit is one of the other -D options that precedes this one that is confusing the cmake parser into becoming unbalanced.

Changing all the quoting of the -D parameters that use them to just " fixes the issue, although it may not work correctly for our build - I'll have to verify.

Hmm. It'd be interesting to just try and parse the JSON from elisp without cmake-ide being involved.

Can you give me some elisp that I can run to verify this?

json-read-from-string, json-read-file.

I put the example above into the file ~/Desktop/test.json, and ran the following elisp:

(defun get-string-from-file (filePath)
  (with-temp-buffer
    (insert-file-contents filePath)
    (buffer-string)))

(message "%s" (json-read-from-string (get-string-from-file "~/Desktop/test.json")))

It produced the following:

[((directory . /Users/stebro/ourproject/build_debug/ui/tests) (command . /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -DPRODVER_BUILD_NO=9999 -DPRODVER_FULL=\"2.6.9999\" -DPRODVER_MAJOR=2 -DPRODVER_MINOR=6 -DPRODVER_STRING="\"2.6.1local build 9999 (2017-12-22 16:50:28)\"" -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_TESTCASE_BUILDDIR=\"/Users/stebro/ourproject/build_debug\" -DQT_TESTLIB_LIB -DQT_WIDGETS_LIB -I/Users/stebro/ourproject/build_debug/ui/tests -I/Users/stebro/ourproject/ui/tests -I/Users/stebro/ourproject/build_debug/ui/tests/OurprojectUI.unit_test_autogen/include -isystem /Volumes/OurprojectToolChain/include -isystem /Volumes/OurprojectToolChain/include/log4qt -isystem /Volumes/OurprojectToolChain/include/log4qt/varia -I/Users/stebro/ourproject/ui -iframework /Volumes/OurprojectToolChain/qt-5.5/lib -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtCore.framework/Headers -isystem /Volumes/OurprojectToolChain/qt-5.5/./mkspecs/macx-clang -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtNetwork.framework/Headers -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtGui.framework/Headers -isystem /System/Library/Frameworks/OpenGL.framework/Headers -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtWidgets.framework/Headers -isystem /Volumes/OurprojectToolChain/qt-5.5/lib/QtTest.framework/Headers -I/Users/stebro/ourproject/ClientShared/include -I/Users/stebro/ourproject/build_debug/ClientShared/include -stdlib=libc++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.7 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -mmacosx-version-min=10.7 -stdlib=libc++ -Werror -Wno-c99-extensions -Wno-c++98-compat -Wreorder -Wunused-variable -Woverloaded-virtual -Wno-unused-local-typedef -Wno-inconsistent-missing-override -Wunused-function -Wno-unknown-warning-option -Wno-nonportable-include-path -Wno-deprecated-declarations -Wno-unused-const-variable -Wno-redeclared-class-member -Wno-header-guard -Wno-logical-not-parentheses -Wno-#warnings -fPIC -std=gnu++11 -o CMakeFiles/OurprojectUI.unit_test.dir/__/ui/abstractinfoprovider.cpp.o -c /Users/stebro/ourproject/ui/ui/abstractinfoprovider.cpp) (file . /Users/stebro/ourproject/ui/ui/abstractinfoprovider.cpp))]

Hmm, so it works then. I'll have to look at this when I have the time.

dfrib commented

I don't believe this depends on a migration to CMake 3.10, but rather a regression in cmake-ide.

I've had the same issue happen for me when I wiped my Emacs deps followed by installing the latest cmake-ide from (non-stable) melpa.org; cmake-ide-20171221.1616. My main project is using CMake 3.6, and saw cmake-ide run into the same (parsing?) issue:

cmake-ide [Tue Jan  9 14:50:48 2018]: Converting JSON CDB /path/to/build/compile_commands.json to IDB
split-string-and-unquote: End of file during parsing

I've since reverted myself to use cmake-ide-20171101.236, which I can verify does not produce the issue above. I haven't tried any releases between 20171101.236 and 20171221.1616.

@dfrib Thanks for the input. Do you happen to have a (preferably very small) JSON sample that causes the issue for you?

dfrib commented

@atilaneves I'm sorry to say that I do not: I've only ran into the issue (using cmake-ide-20171221.1616) for a quite a large project (from which I am not able to share snippets), whereas all my smaller projects using CMake run fine with the newer version. I haven't put any time into looking into why this particular project causes issue, but I would suspect that @sbroberg's update from CMake 2.8 -> 3.10 likewise resulted in some compile commands that smoked our this (possible regression) issue.

Maybe @sbroberg can verify that this his issue is not present if using an older cmake-ide (non-stable) releas (say, cmake-ide-20171101.236)?

Using cmake-ide from commit 114e2df (Wed Nov 1 10:36:54 2017) works correctly for me with the compile-commands.json listed above. I can stay at that version for now, as I don't need the subsequent fixes.

Hi,

I may have found the culprit for this issue.
if you give split-string-and-unquote something like this this is a quoted \\\"string\\\"" it will cause the above error. this function is too naive to handle \\\".
This function is used in cmake-ide--split-command

What about changing cide--split-command to the following?

(defun cide--split-command (command-string)
  "Split COMMAND-STRING and return a list of strings."
  (split-string-and-unquote (replace-regexp-in-string "\\\\\"" "\"" command-string)))

@SimonPP Huh, that works. Thanks!