diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 72e683559..146456684 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -424,7 +424,15 @@ void ImportProject::importCompileCommands(std::istream &istr) continue; struct FileSettings fs; - fs.filename = Path::simplifyPath(directory + file); + if (Path::isAbsolute(file) || Path::fileExists(file)) + fs.filename = file; + else { + std::string path = directory; + if (!path.empty() && !endsWith(path,'/')) + path += '/'; + path += file; + fs.filename = Path::simplifyPath(path); + } fs.parseCommand(command); // read settings; -D, -I, -U, -std, -m*, -f* std::map variables; fs.setIncludePaths(directory, fs.includePaths, variables); diff --git a/test/cli/test-proj2.py b/test/cli/test-proj2.py index 63495690d..3918bf404 100644 --- a/test/cli/test-proj2.py +++ b/test/cli/test-proj2.py @@ -19,7 +19,7 @@ def realpath(s): def create_compile_commands(): j = [{'directory': realpath('proj2/a'), 'command': 'gcc -c a.c', 'file': 'a.c'}, - {'directory': realpath('proj2'), 'command': 'gcc -c b/b.c', 'file': 'b/b.c'}] + {'directory': realpath('proj2/b'), 'command': 'gcc -c b.c', 'file': 'b.c'}] f = open('proj2/' + COMPILE_COMMANDS_JSON, 'wt') f.write(json.dumps(j))