Skip to content

Commit d5fbd55

Browse files
authored
Refactoring: Break out loadLibraries() function. (#5024)
No functional change is intended. This is a preparation to make qml handling work again
1 parent 4807bff commit d5fbd55

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed

cli/cppcheckexecutor.cpp

+37-28
Original file line numberDiff line numberDiff line change
@@ -255,36 +255,9 @@ bool CppCheckExecutor::reportSuppressions(const Settings &settings, bool unusedF
255255
int CppCheckExecutor::check_internal(CppCheck& cppcheck)
256256
{
257257
Settings& settings = cppcheck.settings();
258-
const bool std = tryLoadLibrary(settings.library, settings.exename, "std.cfg");
259258

260-
auto failed_lib = std::find_if(settings.libraries.begin(), settings.libraries.end(), [&](const std::string& lib) {
261-
return !tryLoadLibrary(settings.library, settings.exename, lib.c_str());
262-
});
263-
if (failed_lib != settings.libraries.end()) {
264-
const std::string msg("Failed to load the library " + *failed_lib);
265-
const std::list<ErrorMessage::FileLocation> callstack;
266-
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg, "failedToLoadCfg", Certainty::normal);
267-
reportErr(errmsg);
259+
if (!loadLibraries(settings))
268260
return EXIT_FAILURE;
269-
}
270-
271-
if (!std) {
272-
const std::list<ErrorMessage::FileLocation> callstack;
273-
const std::string msg("Failed to load std.cfg. Your Cppcheck installation is broken, please re-install.");
274-
#ifdef FILESDIR
275-
const std::string details("The Cppcheck binary was compiled with FILESDIR set to \""
276-
FILESDIR "\" and will therefore search for "
277-
"std.cfg in " FILESDIR "/cfg.");
278-
#else
279-
const std::string cfgfolder(Path::fromNativeSeparators(Path::getPathFromFilename(settings.exename)) + "cfg");
280-
const std::string details("The Cppcheck binary was compiled without FILESDIR set. Either the "
281-
"std.cfg should be available in " + cfgfolder + " or the FILESDIR "
282-
"should be configured.");
283-
#endif
284-
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg+" "+details, "failedToLoadCfg", Certainty::normal);
285-
reportErr(errmsg);
286-
return EXIT_FAILURE;
287-
}
288261

289262
if (settings.reportProgress)
290263
mLatestProgressOutputTime = std::time(nullptr);
@@ -341,6 +314,42 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck)
341314
return 0;
342315
}
343316

317+
bool CppCheckExecutor::loadLibraries(Settings& settings)
318+
{
319+
const bool std = tryLoadLibrary(settings.library, settings.exename, "std.cfg");
320+
321+
const auto failed_lib = std::find_if(settings.libraries.begin(), settings.libraries.end(), [&](const std::string& lib) {
322+
return !tryLoadLibrary(settings.library, settings.exename, lib.c_str());
323+
});
324+
if (failed_lib != settings.libraries.end()) {
325+
const std::string msg("Failed to load the library " + *failed_lib);
326+
const std::list<ErrorMessage::FileLocation> callstack;
327+
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg, "failedToLoadCfg", Certainty::normal);
328+
reportErr(errmsg);
329+
return false;
330+
}
331+
332+
if (!std) {
333+
const std::list<ErrorMessage::FileLocation> callstack;
334+
const std::string msg("Failed to load std.cfg. Your Cppcheck installation is broken, please re-install.");
335+
#ifdef FILESDIR
336+
const std::string details("The Cppcheck binary was compiled with FILESDIR set to \""
337+
FILESDIR "\" and will therefore search for "
338+
"std.cfg in " FILESDIR "/cfg.");
339+
#else
340+
const std::string cfgfolder(Path::fromNativeSeparators(Path::getPathFromFilename(settings.exename)) + "cfg");
341+
const std::string details("The Cppcheck binary was compiled without FILESDIR set. Either the "
342+
"std.cfg should be available in " + cfgfolder + " or the FILESDIR "
343+
"should be configured.");
344+
#endif
345+
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg+" "+details, "failedToLoadCfg", Certainty::normal);
346+
reportErr(errmsg);
347+
return false;
348+
}
349+
350+
return true;
351+
}
352+
344353
#ifdef _WIN32
345354
// fix trac ticket #439 'Cppcheck reports wrong filename for filenames containing 8-bit ASCII'
346355
static inline std::string ansiToOEM(const std::string &msg, bool doConvert)

cli/cppcheckexecutor.h

+7
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ class CppCheckExecutor : public ErrorLogger {
144144
*/
145145
int check_internal(CppCheck& cppcheck);
146146

147+
/**
148+
* @brief Load libraries
149+
* @param settings Settings
150+
* @return Returns true if successful
151+
*/
152+
bool loadLibraries(Settings& settings);
153+
147154
/**
148155
* Pointer to current settings; set while check() is running for reportError().
149156
*/

0 commit comments

Comments
 (0)