Bug 371565 - KDevelop can't find header files if the project path contains spaces
Summary: KDevelop can't find header files if the project path contains spaces
Status: REOPENED
Alias: None
Product: kdevelop
Classification: Applications
Component: Build tools: CMake (show other bugs)
Version: 5.0.2
Platform: Neon Linux
: HI normal
Target Milestone: 5.0.4
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-10-24 10:58 UTC by Bernhard Scheirle
Modified: 2017-03-20 20:27 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Example project (1.37 KB, application/x-zip-compressed)
2016-10-24 10:58 UTC, Bernhard Scheirle
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Scheirle 2016-10-24 10:58:18 UTC
In some cases KDevelop can't find header files if the project path contains spaces.
Building such project works fine.

As far as I can tell this only happens:
- for header files of the current source file (in header.cpp it can't find header.hpp)
- the include string contains a path (not only the file name) (#include "folder/header.hpp")


Reproducible: Always

Steps to Reproduce:
1. Open the attached project in kdevelop (there must be a space in the path to the project)
2. Open the "folder/header.cpp" file

Actual Results:  
KDevelop reports a "file not found" error (in "folder/header.cpp" Line 1)

Expected Results:  
KDevelop does not report an "file not found" error
Comment 1 Bernhard Scheirle 2016-10-24 10:58:46 UTC
Created attachment 101737 [details]
Example project
Comment 2 Bernhard Scheirle 2016-10-24 11:05:09 UTC
Running kdevelop with KDEV_CLANG_DISPLAY_ARGS=1 outputs:

Invocation: clang -ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11 -nostdinc -nostdinc++ -xc++ -isystem/usr/include/c++/5 -isystem/usr/include/x86_64-linux-gnu/c++/5 -isystem/usr/include/c++/5/backward -isystem/usr/local/include -isystem/usr/lib/llvm-3.8/lib/clang/3.8.0/include -isystem/usr/include/x86_64-linux-gnu -isystem/usr/include -I/path with spaces/build" -I"/path with spaces -imacros /tmp/kdevelop.J31470 /path with spaces/folder/header.cpp

As you can see some paths are not escaped properly!
Comment 3 Kevin Funk 2017-03-19 20:41:37 UTC
I can't reproduce your problem, using latest KDevelop with Clang 3.9. All works fine for me.

This is what I get:
```
Invocation: clang -ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11 -nostdinc -nostdinc++ -xc++ -isystem/home/kfunk/Downloads/path with spaces build -isystem/usr/include/c++/6 -isystem/usr/include/x86_64-linux-gnu/c++/6 -isystem/usr/include/c++/6/backward -isystem/usr/local/include -isystem/usr/lib/llvm-3.9/lib/clang/3.9.0/include -isystem/usr/include/x86_64-linux-gnu -isystem/usr/include -I/home/kfunk/Downloads/path with spaces -imacros /tmp/kdevelop.U27790 /home/kfunk/Downloads/path with spaces/folder/header.cpp
```

Note that the output here is slightly misleading, there are no '"' around the include paths. Internally, the arguments are passed as a list of arguments, thus spacing in one argument is not a problem.

Anyhow, in your case, the quoting indeed looks wrong:
```
-I/path with spaces/build" -I"/path with spaces
```

That's either because CMake creates a bogus compile_commands.json file or we fail to parse it properly.

Could you please 
a) Check out the newest AppImage on https://www.kdevelop.org/download and try to reproduce?
b) Post the contents of the compile_commands.json in the build directory?
Comment 4 Bernhard Scheirle 2017-03-20 07:53:13 UTC
KDevelop: 5.0.4 from KDE Neon
Clang: 3.8.0

After importing the project KDevelop found the header file with no errors/warnings.
But then after pruning the project the header file can't be found anymore.

After importing the project:

compile_commands.json:
[
{
  "directory": "/path with spaces/build",
  "command": "/usr/bin/c++    -I. -I../  -g   -o CMakeFiles/space.dir/main.cpp.o -c \"/path with spaces/main.cpp\"",
  "file": "/path with spaces/main.cpp"
},

{
  "directory": "/path with spaces/build",
  "command": "/usr/bin/c++    -I. -I../  -g   -o CMakeFiles/space.dir/folder/header.cpp.o -c \"/path with spaces/folder/header.cpp\"",
  "file": "/path with spaces/folder/header.cpp"
}
]

Log:
Invocation: clang -ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11 -nostdinc -nostdinc++ -xc++ -isystem/usr/include/c++/5 -isystem/usr/include/x86_64-linux-gnu/c++/5 -isystem/usr/include/c++/5/backward -isystem/usr/local/include -isystem/usr/lib/llvm-3.8/lib/clang/3.8.0/include -isystem/usr/include/x86_64-linux-gnu -isystem/usr/include -I/path with spaces/build -I/path with spaces -imacros /tmp/kdevelop.XM8558 /path with spaces/folder/header.cpp


Every (especially quoting) looks right.

Now prune the project (Project->Prune Selection) and reload header.cpp (Hit F5):

compile_commands.json:
[
{
  "directory": "/path with spaces/build",
  "command": "/usr/bin/c++    -I\"/path with spaces/build\" -I\"/path with spaces\"  -g   -o CMakeFiles/space.dir/main.cpp.o -c \"/path with spaces/main.cpp\"",
  "file": "/path with spaces/main.cpp"
},
{
  "directory": "/path with spaces/build",
  "command": "/usr/bin/c++    -I\"/path with spaces/build\" -I\"/path with spaces\"  -g   -o CMakeFiles/space.dir/folder/header.cpp.o -c \"/path with spaces/folder/header.cpp\"",
  "file": "/path with spaces/folder/header.cpp"
}
]

Log:
Invocation: clang -ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11 -nostdinc -nostdinc++ -xc++ -isystem/usr/include/c++/5 -isystem/usr/include/x86_64-linux-gnu/c++/5 -isystem/usr/include/c++/5/backward -isystem/usr/local/include -isystem/usr/lib/llvm-3.8/lib/clang/3.8.0/include -isystem/usr/include/x86_64-linux-gnu -isystem/usr/include -I/path with spaces/build" -I"/path with spaces -imacros /tmp/kdevelop.UJ9631 /path with spaces/folder/header.cpp


Note:
* compile_commands.json uses absolute paths after pruning the project for the build and project root directory.
* After pruning the quoting is wrong (build" -I"/path)
* The KDevelop-5.0.4-x86_64.AppImage behaves exactly the same.
Comment 5 Kevin Funk 2017-03-20 20:26:58 UTC
Thanks. I'll check again.