Fixed #10149 (compile database; incomplete handling of directory and file)
This commit is contained in:
parent
5810171336
commit
6a24b4f7c8
|
@ -424,15 +424,17 @@ void ImportProject::importCompileCommands(std::istream &istr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
struct FileSettings fs;
|
struct FileSettings fs;
|
||||||
if (Path::isAbsolute(file) || Path::fileExists(file))
|
if (Path::isAbsolute(file))
|
||||||
fs.filename = file;
|
fs.filename = Path::simplifyPath(file);
|
||||||
else {
|
#ifdef _WIN32
|
||||||
std::string path = directory;
|
else if (file[0] == '/' && directory.size() > 2 && std::isalpha(directory[0]) && directory[1] == ':')
|
||||||
if (!path.empty() && !endsWith(path,'/'))
|
// directory: C:\foo\bar
|
||||||
path += '/';
|
// file: /xy/z.c
|
||||||
path += file;
|
// => c:/xy/z.c
|
||||||
fs.filename = Path::simplifyPath(path);
|
fs.filename = Path::simplifyPath(directory.substr(0,2) + file);
|
||||||
}
|
#endif
|
||||||
|
else
|
||||||
|
fs.filename = Path::simplifyPath(directory + file);
|
||||||
fs.parseCommand(command); // read settings; -D, -I, -U, -std, -m*, -f*
|
fs.parseCommand(command); // read settings; -D, -I, -U, -std, -m*, -f*
|
||||||
std::map<std::string, std::string, cppcheck::stricmp> variables;
|
std::map<std::string, std::string, cppcheck::stricmp> variables;
|
||||||
fs.setIncludePaths(directory, fs.includePaths, variables);
|
fs.setIncludePaths(directory, fs.includePaths, variables);
|
||||||
|
|
|
@ -7,8 +7,8 @@ import re
|
||||||
from testutils import cppcheck
|
from testutils import cppcheck
|
||||||
|
|
||||||
def create_unused_function_compile_commands():
|
def create_unused_function_compile_commands():
|
||||||
compile_commands = os.path.join('proj-inline-suppress-unusedFunction', 'compile_commands.json')
|
prjpath = os.path.realpath('proj-inline-suppress-unusedFunction')
|
||||||
prjpath = os.path.join(os.getcwd(), 'proj-inline-suppress-unusedFunction')
|
compile_commands = os.path.join(prjpath, 'compile_commands.json')
|
||||||
j = [{'directory': prjpath,
|
j = [{'directory': prjpath,
|
||||||
'command': '/usr/bin/c++ -I"' + prjpath + '" -o "' + os.path.join(prjpath, 'B.cpp.o') + '" -c "' + os.path.join(prjpath, 'B.cpp') + '"',
|
'command': '/usr/bin/c++ -I"' + prjpath + '" -o "' + os.path.join(prjpath, 'B.cpp.o') + '" -c "' + os.path.join(prjpath, 'B.cpp') + '"',
|
||||||
'file': os.path.join(prjpath, 'B.cpp')},
|
'file': os.path.join(prjpath, 'B.cpp')},
|
||||||
|
|
|
@ -19,7 +19,7 @@ def realpath(s):
|
||||||
|
|
||||||
def create_compile_commands():
|
def create_compile_commands():
|
||||||
j = [{'directory': realpath('proj2/a'), 'command': 'gcc -c a.c', 'file': 'a.c'},
|
j = [{'directory': realpath('proj2/a'), 'command': 'gcc -c a.c', 'file': 'a.c'},
|
||||||
{'directory': realpath('proj2/b'), 'command': 'gcc -c b.c', 'file': 'b.c'}]
|
{'directory': realpath('proj2'), 'command': 'gcc -c b/b.c', 'file': 'b/b.c'}]
|
||||||
f = open('proj2/' + COMPILE_COMMANDS_JSON, 'wt')
|
f = open('proj2/' + COMPILE_COMMANDS_JSON, 'wt')
|
||||||
f.write(json.dumps(j))
|
f.write(json.dumps(j))
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ private:
|
||||||
TEST_CASE(setIncludePaths2);
|
TEST_CASE(setIncludePaths2);
|
||||||
TEST_CASE(setIncludePaths3); // macro names are case insensitive
|
TEST_CASE(setIncludePaths3); // macro names are case insensitive
|
||||||
TEST_CASE(importCompileCommands1);
|
TEST_CASE(importCompileCommands1);
|
||||||
TEST_CASE(importCompileCommands2); // #8563
|
TEST_CASE(importCompileCommands2); // #8563, #9567
|
||||||
TEST_CASE(importCompileCommands3); // check with existing trailing / in directory
|
TEST_CASE(importCompileCommands3); // check with existing trailing / in directory
|
||||||
TEST_CASE(importCompileCommands4); // only accept certain file types
|
TEST_CASE(importCompileCommands4); // only accept certain file types
|
||||||
TEST_CASE(importCompileCommands5); // Windows/CMake/Ninja generated comile_commands.json
|
TEST_CASE(importCompileCommands5); // Windows/CMake/Ninja generated comile_commands.json
|
||||||
|
@ -116,16 +116,30 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
void importCompileCommands2() const {
|
void importCompileCommands2() const {
|
||||||
|
// Absolute file path
|
||||||
|
#ifdef _WIN32
|
||||||
const char json[] = R"([{
|
const char json[] = R"([{
|
||||||
"directory": "/tmp",
|
"directory": "C:/foo",
|
||||||
"command": "gcc -c src.c",
|
"command": "gcc -c /bar.c",
|
||||||
"file": "src.c"
|
"file": "/bar.c"
|
||||||
}])";
|
}])";
|
||||||
std::istringstream istr(json);
|
std::istringstream istr(json);
|
||||||
TestImporter importer;
|
TestImporter importer;
|
||||||
importer.importCompileCommands(istr);
|
importer.importCompileCommands(istr);
|
||||||
ASSERT_EQUALS(1, importer.fileSettings.size());
|
ASSERT_EQUALS(1, importer.fileSettings.size());
|
||||||
ASSERT_EQUALS("/tmp/src.c", importer.fileSettings.begin()->filename);
|
ASSERT_EQUALS("C:/bar.c", importer.fileSettings.begin()->filename);
|
||||||
|
#else
|
||||||
|
const char json[] = R"([{
|
||||||
|
"directory": "/foo",
|
||||||
|
"command": "gcc -c bar.c",
|
||||||
|
"file": "/bar.c"
|
||||||
|
}])";
|
||||||
|
std::istringstream istr(json);
|
||||||
|
TestImporter importer;
|
||||||
|
importer.importCompileCommands(istr);
|
||||||
|
ASSERT_EQUALS(1, importer.fileSettings.size());
|
||||||
|
ASSERT_EQUALS("/bar.c", importer.fileSettings.begin()->filename);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void importCompileCommands3() const {
|
void importCompileCommands3() const {
|
||||||
|
|
Loading…
Reference in New Issue