Fixed #8925 (compile_commands.json: False positives in .mm (Objective-C++) files, that file type should maybe just be ignored)
This commit is contained in:
parent
a26287f491
commit
91435310cb
|
@ -253,24 +253,28 @@ void ImportProject::FileSettings::parseCommand(const std::string &command)
|
||||||
|
|
||||||
void ImportProject::importCompileCommands(std::istream &istr)
|
void ImportProject::importCompileCommands(std::istream &istr)
|
||||||
{
|
{
|
||||||
picojson::value v;
|
picojson::value compileCommands;
|
||||||
istr >> v;
|
istr >> compileCommands;
|
||||||
if (!v.is<picojson::array>())
|
if (!compileCommands.is<picojson::array>())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (const picojson::value &fileInfo : v.get<picojson::array>()) {
|
for (const picojson::value &fileInfo : compileCommands.get<picojson::array>()) {
|
||||||
picojson::object obj = fileInfo.get<picojson::object>();
|
picojson::object obj = fileInfo.get<picojson::object>();
|
||||||
std::string dirpath = obj["directory"].get<std::string>();
|
std::string dirpath = Path::fromNativeSeparators(obj["directory"].get<std::string>());
|
||||||
|
|
||||||
/* CMAKE produces the directory without trailing / so add it if not
|
/* CMAKE produces the directory without trailing / so add it if not
|
||||||
* there - it is needed by setIncludePaths() */
|
* there - it is needed by setIncludePaths() */
|
||||||
if (!endsWith(dirpath, '/'))
|
if (!endsWith(dirpath, '/'))
|
||||||
dirpath += '/';
|
dirpath += '/';
|
||||||
|
|
||||||
const std::string directory = Path::fromNativeSeparators(dirpath);
|
const std::string directory = dirpath;
|
||||||
const std::string command = obj["command"].get<std::string>();
|
const std::string command = obj["command"].get<std::string>();
|
||||||
const std::string file = Path::fromNativeSeparators(obj["file"].get<std::string>());
|
const std::string file = Path::fromNativeSeparators(obj["file"].get<std::string>());
|
||||||
|
|
||||||
|
// Accept file?
|
||||||
|
if (!Path::acceptFile(file))
|
||||||
|
continue;
|
||||||
|
|
||||||
struct FileSettings fs;
|
struct FileSettings fs;
|
||||||
if (Path::isAbsolute(file) || Path::fileExists(file))
|
if (Path::isAbsolute(file) || Path::fileExists(file))
|
||||||
fs.filename = file;
|
fs.filename = file;
|
||||||
|
|
|
@ -46,6 +46,7 @@ private:
|
||||||
TEST_CASE(importCompileCommands1);
|
TEST_CASE(importCompileCommands1);
|
||||||
TEST_CASE(importCompileCommands2); // #8563
|
TEST_CASE(importCompileCommands2); // #8563
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDefines() const {
|
void setDefines() const {
|
||||||
|
@ -125,6 +126,16 @@ private:
|
||||||
ASSERT_EQUALS(1, importer.fileSettings.size());
|
ASSERT_EQUALS(1, importer.fileSettings.size());
|
||||||
ASSERT_EQUALS("/tmp/src.c", importer.fileSettings.begin()->filename);
|
ASSERT_EQUALS("/tmp/src.c", importer.fileSettings.begin()->filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void importCompileCommands4() const {
|
||||||
|
const char json[] = "[ { \"directory\": \"/tmp/\","
|
||||||
|
"\"command\": \"gcc -c src.mm\","
|
||||||
|
"\"file\": \"src.mm\" } ]";
|
||||||
|
std::istringstream istr(json);
|
||||||
|
TestImporter importer;
|
||||||
|
importer.importCompileCommands(istr);
|
||||||
|
ASSERT_EQUALS(0, importer.fileSettings.size());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestImportProject)
|
REGISTER_TEST(TestImportProject)
|
||||||
|
|
Loading…
Reference in New Issue