Load std.cfg before all other libraries (#1740)

- CLI: Save the libraries that should be loaded to a list and load them
after the std.cfg has been loaded.
- GUI: Load std.cfg (and windows.cfg / posix.cfg when applicable) before
setting other options and loading the other libraries.
In the project-file-dialog the std.cfg is searched first. If some
other library fails to load is is retried with first loading std.cfg.
- boost.cfg: Enable containers that depend on std containers.
This commit is contained in:
Sebastian 2019-03-15 06:59:37 +01:00 committed by GitHub
parent 3615eac347
commit 08d41ab8af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 24 deletions

View File

@ -826,15 +826,13 @@
<not-uninit/> <not-uninit/>
</arg> </arg>
</function> </function>
<!-- boost containers that are similar to std containers, commented out due to dependency on std --> <!-- boost containers that are similar to std containers -->
<!--
<container id="boostArray" startPattern="boost :: array|scoped_array &lt;" inherits="stdArray"/> <container id="boostArray" startPattern="boost :: array|scoped_array &lt;" inherits="stdArray"/>
<container id="boostCircularBuffer" startPattern="boost :: circular_buffer &lt;" inherits="stdContainer"/> <container id="boostCircularBuffer" startPattern="boost :: circular_buffer &lt;" inherits="stdContainer"/>
<container id="boostList" startPattern="boost :: list|slist &lt;" inherits="stdList"/> <container id="boostList" startPattern="boost :: list|slist &lt;" inherits="stdList"/>
<container id="boostMap" startPattern="boost :: map|flat_map|flat_multimap|multimap|unordered_map|unordered_multimap &lt;" inherits="stdMap"/> <container id="boostMap" startPattern="boost :: map|flat_map|flat_multimap|multimap|unordered_map|unordered_multimap &lt;" inherits="stdMap"/>
<container id="boostSet" startPattern="boost :: set|flat_set|flat_multiset|multiset|unordered_set &lt;" inherits="stdSet"/> <container id="boostSet" startPattern="boost :: set|flat_set|flat_multiset|multiset|unordered_set &lt;" inherits="stdSet"/>
<container id="boostVectorDeque" startPattern="boost :: deque|vector|small_vector|stable_vector|static_vector &lt;" inherits="stdVectorDeque"/> <container id="boostVectorDeque" startPattern="boost :: deque|vector|small_vector|stable_vector|static_vector &lt;" inherits="stdVectorDeque"/>
-->
<!-- Tell cppcheck to interpret BOOST_AUTO_TEST_CASE as a function definition --> <!-- Tell cppcheck to interpret BOOST_AUTO_TEST_CASE as a function definition -->
<define name="BOOST_AUTO_TEST_CASE(str)" value="void BOOST_AUTO_TEST_CASE_run(str)"/> <define name="BOOST_AUTO_TEST_CASE(str)" value="void BOOST_AUTO_TEST_CASE_run(str)"/>
<define name="BOOST_FIXTURE_TEST_CASE(str1, str2)" value="void BOOST_FIXTURE_TEST_CASE_run(str1,str2)"/> <define name="BOOST_FIXTURE_TEST_CASE(str1, str2)" value="void BOOST_FIXTURE_TEST_CASE_run(str1,str2)"/>

View File

@ -532,8 +532,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
// --library // --library
else if (std::strncmp(argv[i], "--library=", 10) == 0) { else if (std::strncmp(argv[i], "--library=", 10) == 0) {
if (!CppCheckExecutor::tryLoadLibrary(mSettings->library, argv[0], argv[i]+10)) std::string lib(argv[i] + 10);
return false; mSettings->libraries.push_back(lib);
} }
// --project // --project

View File

@ -811,6 +811,17 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
Settings& settings = cppcheck.settings(); Settings& settings = cppcheck.settings();
_settings = &settings; _settings = &settings;
const bool std = tryLoadLibrary(settings.library, argv[0], "std.cfg"); const bool std = tryLoadLibrary(settings.library, argv[0], "std.cfg");
for (const std::string &lib : settings.libraries) {
if (!tryLoadLibrary(settings.library, argv[0], lib.c_str())) {
const std::string msg("Failed to load the library " + lib);
const std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
ErrorLogger::ErrorMessage errmsg(callstack, emptyString, Severity::information, msg, "failedToLoadCfg", false);
reportErr(errmsg);
return EXIT_FAILURE;
}
}
bool posix = true; bool posix = true;
if (settings.standards.posix) if (settings.standards.posix)
posix = tryLoadLibrary(settings.library, argv[0], "posix.cfg"); posix = tryLoadLibrary(settings.library, argv[0], "posix.cfg");

View File

@ -827,6 +827,17 @@ Settings MainWindow::getCppcheckSettings()
Settings result; Settings result;
const bool std = tryLoadLibrary(&result.library, "std.cfg");
bool posix = true;
if (result.standards.posix)
posix = tryLoadLibrary(&result.library, "posix.cfg");
bool windows = true;
if (result.isWindowsPlatform())
windows = tryLoadLibrary(&result.library, "windows.cfg");
if (!std || !posix || !windows)
QMessageBox::critical(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken. You can use --data-dir=<directory> at the command line to specify where this file is located. Please note that --data-dir is supposed to be used by installation scripts and therefore the GUI does not start when it is used, all that happens is that the setting is configured.").arg(!std ? "std.cfg" : !posix ? "posix.cfg" : "windows.cfg"));
// If project file loaded, read settings from it // If project file loaded, read settings from it
if (mProjectFile) { if (mProjectFile) {
QStringList dirs = mProjectFile->getIncludeDirs(); QStringList dirs = mProjectFile->getIncludeDirs();
@ -920,17 +931,6 @@ Settings MainWindow::getCppcheckSettings()
result.standards.posix = mSettings->value(SETTINGS_STD_POSIX, false).toBool(); result.standards.posix = mSettings->value(SETTINGS_STD_POSIX, false).toBool();
result.enforcedLang = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); result.enforcedLang = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
const bool std = tryLoadLibrary(&result.library, "std.cfg");
bool posix = true;
if (result.standards.posix)
posix = tryLoadLibrary(&result.library, "posix.cfg");
bool windows = true;
if (result.isWindowsPlatform())
windows = tryLoadLibrary(&result.library, "windows.cfg");
if (!std || !posix || !windows)
QMessageBox::critical(this, tr("Error"), tr("Failed to load %1. Your Cppcheck installation is broken. You can use --data-dir=<directory> at the command line to specify where this file is located. Please note that --data-dir is supposed to be used by installation scripts and therefore the GUI does not start when it is used, all that happens is that the setting is configured.").arg(!std ? "std.cfg" : !posix ? "posix.cfg" : "windows.cfg"));
if (result.jobs <= 1) { if (result.jobs <= 1) {
result.jobs = 1; result.jobs = 1;
} }

View File

@ -89,6 +89,30 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent)
if (!datadir.isEmpty()) if (!datadir.isEmpty())
searchPaths << datadir << datadir + "/cfg"; searchPaths << datadir << datadir + "/cfg";
QStringList libs; QStringList libs;
// Search the std.cfg first since other libraries could depend on it
QString stdLibraryFilename;
foreach (const QString sp, searchPaths) {
QDir dir(sp);
dir.setSorting(QDir::Name);
dir.setNameFilters(QStringList("*.cfg"));
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot);
foreach (QFileInfo item, dir.entryInfoList()) {
QString library = item.fileName();
if (library.compare("std.cfg", Qt::CaseInsensitive) != 0)
continue;
Library lib;
const QString fullfilename = sp + "/" + library;
const Library::Error err = lib.load(nullptr, fullfilename.toLatin1());
if (err.errorcode != Library::OK)
continue;
// Working std.cfg found
stdLibraryFilename = fullfilename;
break;
}
if (!stdLibraryFilename.isEmpty())
break;
}
// Search other libraries
foreach (const QString sp, searchPaths) { foreach (const QString sp, searchPaths) {
QDir dir(sp); QDir dir(sp);
dir.setSorting(QDir::Name); dir.setSorting(QDir::Name);
@ -99,7 +123,12 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, QWidget *parent)
{ {
Library lib; Library lib;
const QString fullfilename = sp + "/" + library; const QString fullfilename = sp + "/" + library;
const Library::Error err = lib.load(nullptr, fullfilename.toLatin1()); Library::Error err = lib.load(nullptr, fullfilename.toLatin1());
if (err.errorcode != Library::OK) {
// Some libraries depend on std.cfg so load it first and test again
lib.load(nullptr, stdLibraryFilename.toLatin1());
err = lib.load(nullptr, fullfilename.toLatin1());
}
if (err.errorcode != Library::OK) if (err.errorcode != Library::OK)
continue; continue;
} }

View File

@ -255,7 +255,10 @@ public:
/** @brief --report-progress */ /** @brief --report-progress */
bool reportProgress; bool reportProgress;
/** Library (--library) */ /** @brief --library= */
std::list<std::string> libraries;
/** Library */
Library library; Library library;
/** Rule */ /** Rule */