Skip to content

Commit

Permalink
added verbose logging of library loading
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed May 26, 2024
1 parent 5b025c8 commit eaf4b46
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
# TODO: disable all warnings
- name: CMake
run: |
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_ADDRESS=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
env:
CC: clang-18
CXX: clang++-18
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: CMake
run: |
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_THREAD=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=Off -DWITH_QCHART=Off -DUSE_MATCHCOMPILER=Verify -DANALYZE_THREAD=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=Off -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
env:
CC: clang-18
CXX: clang++-18
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
# TODO: disable warnings
- name: CMake
run: |
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake -S . -B cmake.output -DCMAKE_BUILD_TYPE=RelWithDebInfo -DHAVE_RULES=On -DBUILD_TESTS=On -DBUILD_GUI=ON -DWITH_QCHART=ON -DUSE_MATCHCOMPILER=Verify -DANALYZE_UNDEFINED=On -DENABLE_CHECK_INTERNAL=On -DUSE_BOOST=On -DCPPCHK_GLIBCXX_DEBUG=Off -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On -DCMAKE_GLOBAL_AUTOGEN_TARGET=On -DDISABLE_DMAKE=On -DFILESDIR= -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
env:
CC: clang-18
CXX: clang++-18
Expand Down
8 changes: 4 additions & 4 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1810,9 +1810,9 @@ bool CmdLineParser::isCppcheckPremium() const {
return startsWith(mSettings.cppcheckCfgProductName, "Cppcheck Premium");
}

bool CmdLineParser::tryLoadLibrary(Library& destination, const std::string& basepath, const char* filename)
bool CmdLineParser::tryLoadLibrary(Library& destination, const std::string& basepath, const char* filename, bool verbose)
{
const Library::Error err = destination.load(basepath.c_str(), filename);
const Library::Error err = destination.load(basepath.c_str(), filename, verbose);

if (err.errorcode == Library::ErrorCode::UNKNOWN_ELEMENT)
mLogger.printMessage("Found unknown elements in configuration file '" + std::string(filename) + "': " + err.reason); // TODO: print as errors
Expand Down Expand Up @@ -1859,7 +1859,7 @@ bool CmdLineParser::tryLoadLibrary(Library& destination, const std::string& base

bool CmdLineParser::loadLibraries(Settings& settings)
{
if (!tryLoadLibrary(settings.library, settings.exename, "std.cfg")) {
if (!tryLoadLibrary(settings.library, settings.exename, "std.cfg", settings.verbose)) {
const std::string msg("Failed to load std.cfg. Your Cppcheck installation is broken, please re-install.");
#ifdef FILESDIR
const std::string details("The Cppcheck binary was compiled with FILESDIR set to \""
Expand All @@ -1877,7 +1877,7 @@ bool CmdLineParser::loadLibraries(Settings& settings)

bool result = true;
for (const auto& lib : settings.libraries) {
if (!tryLoadLibrary(settings.library, settings.exename, lib.c_str())) {
if (!tryLoadLibrary(settings.library, settings.exename, lib.c_str(), settings.verbose)) {
result = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class CmdLineParser {
* Tries to load a library and prints warning/error messages
* @return false, if an error occurred (except unknown XML elements)
*/
bool tryLoadLibrary(Library& destination, const std::string& basepath, const char* filename);
bool tryLoadLibrary(Library& destination, const std::string& basepath, const char* filename, bool verbose);

/**
* @brief Load libraries
Expand Down
40 changes: 32 additions & 8 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -836,35 +836,50 @@ void MainWindow::addIncludeDirs(const QStringList &includeDirs, Settings &result
}
}

Library::Error MainWindow::loadLibrary(Library &library, const QString &filename)
Library::Error MainWindow::loadLibrary(Library &library, const QString &filename, bool verbose)
{
Library::Error ret;

// Try to load the library from the project folder..
if (mProjectFile) {
QString path = QFileInfo(mProjectFile->getFilename()).canonicalPath();
ret = library.load(nullptr, (path+"/"+filename).toLatin1());
QString libpath = path+"/"+filename;
if (verbose)
std::cout << "looking for library '" + libpath.toStdString() + "'" << std::endl;
ret = library.load(nullptr, libpath.toLatin1());
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;
}

// Try to load the library from the application folder..
const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath();
ret = library.load(nullptr, (appPath+"/"+filename).toLatin1());
QString libpath = appPath+"/"+filename;
if (verbose)
std::cout << "looking for library '" + libpath.toStdString() + "'" << std::endl;
ret = library.load(nullptr, libpath.toLatin1());
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;
ret = library.load(nullptr, (appPath+"/cfg/"+filename).toLatin1());
libpath = appPath+"/cfg/"+filename;
if (verbose)
std::cout << "looking for library '" + libpath.toStdString() + "'" << std::endl;
ret = library.load(nullptr, libpath.toLatin1());
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;

#ifdef FILESDIR
// Try to load the library from FILESDIR/cfg..
const QString filesdir = FILESDIR;
if (!filesdir.isEmpty()) {
ret = library.load(nullptr, (filesdir+"/cfg/"+filename).toLatin1());
libpath = filesdir+"/cfg/"+filename;
if (verbose)
std::cout << "looking for library '" + libpath.toStdString() + "'" << std::endl;
ret = library.load(nullptr, libpath.toLatin1());
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;
ret = library.load(nullptr, (filesdir+filename).toLatin1());
libpath = filesdir+filename;
if (verbose)
std::cout << "looking for library '" + libpath.toStdString() + "'" << std::endl;
ret = library.load(nullptr, libpath.toLatin1());
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;
}
Expand All @@ -873,14 +888,23 @@ Library::Error MainWindow::loadLibrary(Library &library, const QString &filename
// Try to load the library from the cfg subfolder..
const QString datadir = getDataDir();
if (!datadir.isEmpty()) {
ret = library.load(nullptr, (datadir+"/"+filename).toLatin1());
libpath = datadir+"/"+filename;
if (verbose)
std::cout << "looking for library '" + libpath.toStdString() + "'" << std::endl;
ret = library.load(nullptr, libpath.toLatin1());
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;
ret = library.load(nullptr, (datadir+"/cfg/"+filename).toLatin1());
libpath = datadir+"/cfg/"+filename;
if (verbose)
std::cout << "looking for library '" + libpath.toStdString() + "'" << std::endl;
ret = library.load(nullptr, libpath.toLatin1());
if (ret.errorcode != Library::ErrorCode::FILE_NOT_FOUND)
return ret;
}

if (verbose)
std::cout << "library not found: '" + filename.toStdString() + "'" << std::endl;

return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private slots:
* @param filename filename (no path)
* @return error code
*/
Library::Error loadLibrary(Library &library, const QString &filename);
Library::Error loadLibrary(Library &library, const QString &filename, bool verbose = false);

/**
* @brief Tries to load library file, prints message on error
Expand Down
19 changes: 17 additions & 2 deletions lib/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <cctype>
#include <climits>
#include <cstring>
#include <iostream>
#include <list>
#include <memory>
#include <sstream>
Expand Down Expand Up @@ -65,9 +66,12 @@ static void gettokenlistfromvalid(const std::string& valid, bool cpp, TokenList&
}
}

Library::Error Library::load(const char exename[], const char path[])
Library::Error Library::load(const char exename[], const char path[], bool verbose)
{
// TODO: remove handling of multiple libraries at once?
if (std::strchr(path,',') != nullptr) {
if (verbose)
std::cout << "handling multiple libraries '" + std::string(path) + "'" << std::endl;
std::string p(path);
for (;;) {
const std::string::size_type pos = p.find(',');
Expand All @@ -86,15 +90,21 @@ Library::Error Library::load(const char exename[], const char path[])
std::string absolute_path;
// open file..
tinyxml2::XMLDocument doc;
if (verbose)
std::cout << "looking for library '" + std::string(path) + "'" << std::endl;
tinyxml2::XMLError error = doc.LoadFile(path);
if (error == tinyxml2::XML_ERROR_FILE_READ_ERROR && Path::getFilenameExtension(path).empty())
{
// Reading file failed, try again...
error = tinyxml2::XML_ERROR_FILE_NOT_FOUND;
}
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) {
// failed to open file.. is there no extension?
std::string fullfilename(path);
if (Path::getFilenameExtension(fullfilename).empty()) {
fullfilename += ".cfg";
if (verbose)
std::cout << "looking for library '" + std::string(fullfilename) + "'" << std::endl;
error = doc.LoadFile(fullfilename.c_str());
if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)
absolute_path = Path::getAbsoluteFilePath(fullfilename);
Expand All @@ -116,6 +126,8 @@ Library::Error Library::load(const char exename[], const char path[])
cfgfolders.pop_back();
const char *sep = (!cfgfolder.empty() && endsWith(cfgfolder,'/') ? "" : "/");
const std::string filename(cfgfolder + sep + fullfilename);
if (verbose)
std::cout << "looking for library '" + std::string(filename) + "'" << std::endl;
error = doc.LoadFile(filename.c_str());
if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)
absolute_path = Path::getAbsoluteFilePath(filename);
Expand All @@ -134,10 +146,13 @@ Library::Error Library::load(const char exename[], const char path[])
return Error(ErrorCode::OK); // ignore duplicates
}

if (verbose)
std::cout << "library not found: '" + std::string(path) + "'" << std::endl;

if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
return Error(ErrorCode::FILE_NOT_FOUND);

doc.PrintError();
doc.PrintError(); // TODO: do not print stray messages
return Error(ErrorCode::BAD_XML);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CPPCHECKLIB Library {
std::string reason;
};

Error load(const char exename[], const char path[]);
Error load(const char exename[], const char path[], bool verbose = false);

struct AllocFunc {
int groupId;
Expand Down
Loading

0 comments on commit eaf4b46

Please sign in to comment.