fixed issue 8661: Misleading error message when compilation database is not recognized
This commit is contained in:
parent
58c91c4645
commit
01ceb9bae7
|
@ -503,14 +503,23 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// --project
|
// --project
|
||||||
else if (std::strncmp(argv[i], "--project=", 10) == 0) {
|
else if (std::strncmp(argv[i], "--project=", 10) == 0) {
|
||||||
_settings->project.import(argv[i]+10);
|
const std::string projectFile = argv[i]+10;
|
||||||
if (std::strstr(argv[i], ".sln") || std::strstr(argv[i], ".vcxproj")) {
|
const ImportProject::Type projType = _settings->project.import(projectFile);
|
||||||
|
if (projType == ImportProject::VS_SLN || projType == ImportProject::VS_VCXPROJ) {
|
||||||
if (!CppCheckExecutor::tryLoadLibrary(_settings->library, argv[0], "windows.cfg")) {
|
if (!CppCheckExecutor::tryLoadLibrary(_settings->library, argv[0], "windows.cfg")) {
|
||||||
// This shouldn't happen normally.
|
// This shouldn't happen normally.
|
||||||
printMessage("cppcheck: Failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install.");
|
printMessage("cppcheck: Failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (projType == ImportProject::MISSING) {
|
||||||
|
printMessage("cppcheck: Failed to open project '" + projectFile + "'.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (projType == ImportProject::UNKNOWN) {
|
||||||
|
printMessage("cppcheck: Failed to load project '" + projectFile + "'. The format is unknown.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report progress
|
// Report progress
|
||||||
|
|
|
@ -167,24 +167,29 @@ void ImportProject::FileSettings::setIncludePaths(const std::string &basepath, c
|
||||||
includePaths.swap(I);
|
includePaths.swap(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportProject::import(const std::string &filename)
|
ImportProject::Type ImportProject::import(const std::string &filename)
|
||||||
{
|
{
|
||||||
std::ifstream fin(filename);
|
std::ifstream fin(filename);
|
||||||
if (!fin.is_open())
|
if (!fin.is_open())
|
||||||
return;
|
return MISSING;
|
||||||
if (filename.find("compile_commands.json") != std::string::npos) {
|
if (endsWith(filename, "compile_commands.json", 21)) {
|
||||||
importCompileCommands(fin);
|
importCompileCommands(fin);
|
||||||
} else if (filename.find(".sln") != std::string::npos) {
|
return COMPILE_DB;
|
||||||
|
} else if (endsWith(filename, ".sln", 4)) {
|
||||||
std::string path(Path::getPathFromFilename(Path::fromNativeSeparators(filename)));
|
std::string path(Path::getPathFromFilename(Path::fromNativeSeparators(filename)));
|
||||||
if (!path.empty() && !endsWith(path,'/'))
|
if (!path.empty() && !endsWith(path,'/'))
|
||||||
path += '/';
|
path += '/';
|
||||||
importSln(fin,path);
|
importSln(fin,path);
|
||||||
} else if (filename.find(".vcxproj") != std::string::npos) {
|
return VS_SLN;
|
||||||
|
} else if (endsWith(filename, ".vcxproj", 8)) {
|
||||||
std::map<std::string, std::string, cppcheck::stricmp> variables;
|
std::map<std::string, std::string, cppcheck::stricmp> variables;
|
||||||
importVcxproj(filename, variables, emptyString);
|
importVcxproj(filename, variables, emptyString);
|
||||||
} else if (filename.find(".bpr") != std::string::npos) {
|
return VS_VCXPROJ;
|
||||||
|
} else if (endsWith(filename, ".bpr", 4)) {
|
||||||
importBcb6Prj(filename);
|
importBcb6Prj(filename);
|
||||||
|
return BORLAND;
|
||||||
}
|
}
|
||||||
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportProject::importCompileCommands(std::istream &istr)
|
void ImportProject::importCompileCommands(std::istream &istr)
|
||||||
|
|
|
@ -47,6 +47,15 @@ namespace cppcheck {
|
||||||
*/
|
*/
|
||||||
class CPPCHECKLIB ImportProject {
|
class CPPCHECKLIB ImportProject {
|
||||||
public:
|
public:
|
||||||
|
enum Type {
|
||||||
|
UNKNOWN,
|
||||||
|
MISSING,
|
||||||
|
COMPILE_DB,
|
||||||
|
VS_SLN,
|
||||||
|
VS_VCXPROJ,
|
||||||
|
BORLAND
|
||||||
|
};
|
||||||
|
|
||||||
/** File settings. Multiple configurations for a file is allowed. */
|
/** File settings. Multiple configurations for a file is allowed. */
|
||||||
struct CPPCHECKLIB FileSettings {
|
struct CPPCHECKLIB FileSettings {
|
||||||
FileSettings() : platformType(cppcheck::Platform::Unspecified), msc(false), useMfc(false) {}
|
FileSettings() : platformType(cppcheck::Platform::Unspecified), msc(false), useMfc(false) {}
|
||||||
|
@ -73,7 +82,7 @@ public:
|
||||||
void ignoreOtherConfigs(const std::string &cfg);
|
void ignoreOtherConfigs(const std::string &cfg);
|
||||||
void ignoreOtherPlatforms(cppcheck::Platform::PlatformType platformType);
|
void ignoreOtherPlatforms(cppcheck::Platform::PlatformType platformType);
|
||||||
|
|
||||||
void import(const std::string &filename);
|
Type import(const std::string &filename);
|
||||||
protected:
|
protected:
|
||||||
void importCompileCommands(std::istream &istr);
|
void importCompileCommands(std::istream &istr);
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue