Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13040 (Import project: compile_commands.json, fail to include header in project root folder) #6724

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void ImportProject::fsSetIncludePaths(FileSettings& fs, const std::string &basep
}

if (endsWith(s,'/')) // this is a temporary hack, simplifyPath can crash if path ends with '/'
s.erase(s.size() - 1U); // TODO: Use std::string::pop_back() as soon as travis supports it
s.pop_back();

if (s.find("$(") == std::string::npos) {
s = Path::simplifyPath(basepath + s);
Expand All @@ -174,7 +174,7 @@ void ImportProject::fsSetIncludePaths(FileSettings& fs, const std::string &basep
}
if (s.empty())
continue;
fs.includePaths.push_back(s + '/');
fs.includePaths.push_back(s.back() == '/' ? s : (s + '/'));
}
}

Expand Down
18 changes: 18 additions & 0 deletions test/testimportproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class TestImportProject : public TestFixture {
TEST_CASE(importCompileCommands9);
TEST_CASE(importCompileCommands10); // #10887: include path with space
TEST_CASE(importCompileCommands11); // include path order
TEST_CASE(importCompileCommands12); // #13040: "directory" is parent directory, relative include paths
TEST_CASE(importCompileCommandsArgumentsSection); // Handle arguments section
TEST_CASE(importCompileCommandsNoCommandSection); // gracefully handles malformed json
TEST_CASE(importCppcheckGuiProject);
Expand Down Expand Up @@ -319,6 +320,23 @@ class TestImportProject : public TestFixture {
ASSERT_EQUALS("/x/abc/", fs.includePaths.back());
}

void importCompileCommands12() const { // #13040
REDIRECT;
constexpr char json[] =
R"([{
"file": "/x/src/1.c" ,
"directory": "/x",
"command": "cc -c -I. src/1.c"
}])";
std::istringstream istr(json);
TestImporter importer;
ASSERT_EQUALS(true, importer.importCompileCommands(istr));
ASSERT_EQUALS(1, importer.fileSettings.size());
const FileSettings &fs = importer.fileSettings.front();
ASSERT_EQUALS(1, fs.includePaths.size());
ASSERT_EQUALS("/x/", fs.includePaths.front());
}

void importCompileCommandsArgumentsSection() const {
REDIRECT;
constexpr char json[] = "[ { \"directory\": \"/tmp/\","
Expand Down
Loading