exename: Set proper exename when cppcheck is executed from PATH and argv[0] does not contain path information
This commit is contained in:
parent
18d24e2420
commit
1fe7cd348a
|
@ -937,7 +937,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
|||
}
|
||||
}
|
||||
|
||||
mSettings->loadCppcheckCfg(argv[0]);
|
||||
mSettings->loadCppcheckCfg();
|
||||
|
||||
// Default template format..
|
||||
if (mSettings->templateFormat.empty()) {
|
||||
|
|
|
@ -243,9 +243,9 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
|
|||
int ret;
|
||||
|
||||
if (cppCheck.settings().exceptionHandling)
|
||||
ret = check_wrapper(cppCheck, argc, argv);
|
||||
ret = check_wrapper(cppCheck);
|
||||
else
|
||||
ret = check_internal(cppCheck, argc, argv);
|
||||
ret = check_internal(cppCheck);
|
||||
|
||||
mSettings = nullptr;
|
||||
return ret;
|
||||
|
@ -821,12 +821,12 @@ namespace {
|
|||
* TODO Check for multi-threading issues!
|
||||
*
|
||||
*/
|
||||
int CppCheckExecutor::check_wrapper(CppCheck& cppcheck, int argc, const char* const argv[])
|
||||
int CppCheckExecutor::check_wrapper(CppCheck& cppcheck)
|
||||
{
|
||||
#ifdef USE_WINDOWS_SEH
|
||||
FILE *outputFile = stdout;
|
||||
__try {
|
||||
return check_internal(cppcheck, argc, argv);
|
||||
return check_internal(cppcheck);
|
||||
} __except (filterException(GetExceptionCode(), GetExceptionInformation())) {
|
||||
// reporting to stdout may not be helpful within a GUI application...
|
||||
fputs("Please report this to the cppcheck developers!\n", outputFile);
|
||||
|
@ -854,23 +854,23 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck, int argc, const char* co
|
|||
for (std::map<int, std::string>::const_iterator sig=listofsignals.begin(); sig!=listofsignals.end(); ++sig) {
|
||||
sigaction(sig->first, &act, nullptr);
|
||||
}
|
||||
return check_internal(cppcheck, argc, argv);
|
||||
return check_internal(cppcheck);
|
||||
#else
|
||||
return check_internal(cppcheck, argc, argv);
|
||||
return check_internal(cppcheck);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* That is a method which gets called from check_wrapper
|
||||
* */
|
||||
int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const char* const argv[])
|
||||
int CppCheckExecutor::check_internal(CppCheck& cppcheck)
|
||||
{
|
||||
Settings& settings = cppcheck.settings();
|
||||
mSettings = &settings;
|
||||
const bool std = tryLoadLibrary(settings.library, argv[0], "std.cfg");
|
||||
const bool std = tryLoadLibrary(settings.library, settings.exename, "std.cfg");
|
||||
|
||||
for (const std::string &lib : settings.libraries) {
|
||||
if (!tryLoadLibrary(settings.library, argv[0], lib.c_str())) {
|
||||
if (!tryLoadLibrary(settings.library, settings.exename, lib.c_str())) {
|
||||
const std::string msg("Failed to load the library " + lib);
|
||||
const std::list<ErrorMessage::FileLocation> callstack;
|
||||
ErrorMessage errmsg(callstack, emptyString, Severity::information, msg, "failedToLoadCfg", Certainty::normal);
|
||||
|
@ -879,22 +879,15 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
|
|||
}
|
||||
}
|
||||
|
||||
bool posix = true;
|
||||
if (settings.posix())
|
||||
posix = tryLoadLibrary(settings.library, argv[0], "posix.cfg");
|
||||
bool windows = true;
|
||||
if (settings.isWindowsPlatform())
|
||||
windows = tryLoadLibrary(settings.library, argv[0], "windows.cfg");
|
||||
|
||||
if (!std || !posix || !windows) {
|
||||
if (!std) {
|
||||
const std::list<ErrorMessage::FileLocation> callstack;
|
||||
const std::string msg("Failed to load " + std::string(!std ? "std.cfg" : !posix ? "posix.cfg" : "windows.cfg") + ". Your Cppcheck installation is broken, please re-install.");
|
||||
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 \""
|
||||
FILESDIR "\" and will therefore search for "
|
||||
"std.cfg in " FILESDIR "/cfg.");
|
||||
#else
|
||||
const std::string cfgfolder(Path::fromNativeSeparators(Path::getPathFromFilename(argv[0])) + "cfg");
|
||||
const std::string cfgfolder(Path::fromNativeSeparators(Path::getPathFromFilename(settings.exename)) + "cfg");
|
||||
const std::string details("The Cppcheck binary was compiled without FILESDIR set. Either the "
|
||||
"std.cfg should be available in " + cfgfolder + " or the FILESDIR "
|
||||
"should be configured.");
|
||||
|
@ -1143,9 +1136,9 @@ FILE* CppCheckExecutor::getExceptionOutput()
|
|||
return mExceptionOutput;
|
||||
}
|
||||
|
||||
bool CppCheckExecutor::tryLoadLibrary(Library& destination, const char* basepath, const char* filename)
|
||||
bool CppCheckExecutor::tryLoadLibrary(Library& destination, const std::string& basepath, const char* filename)
|
||||
{
|
||||
const Library::Error err = destination.load(basepath, filename);
|
||||
const Library::Error err = destination.load(basepath.c_str(), filename);
|
||||
|
||||
if (err.errorcode == Library::ErrorCode::UNKNOWN_ELEMENT)
|
||||
std::cout << "cppcheck: Found unknown elements in configuration file '" << filename << "': " << err.reason << std::endl;
|
||||
|
|
|
@ -111,7 +111,7 @@ public:
|
|||
* Tries to load a library and prints warning/error messages
|
||||
* @return false, if an error occurred (except unknown XML elements)
|
||||
*/
|
||||
static bool tryLoadLibrary(Library& destination, const char* basepath, const char* filename);
|
||||
static bool tryLoadLibrary(Library& destination, const std::string& basepath, const char* filename);
|
||||
|
||||
/**
|
||||
* Execute a shell command and read the output from it. Returns true if command terminated successfully.
|
||||
|
@ -150,24 +150,20 @@ private:
|
|||
* - installs optional platform dependent signal handling
|
||||
*
|
||||
* @param cppcheck cppcheck instance
|
||||
* @param argc from main()
|
||||
* @param argv from main()
|
||||
**/
|
||||
int check_wrapper(CppCheck& cppcheck, int argc, const char* const argv[]);
|
||||
int check_wrapper(CppCheck& cppcheck);
|
||||
|
||||
/**
|
||||
* Starts the checking.
|
||||
*
|
||||
* @param cppcheck cppcheck instance
|
||||
* @param argc from main()
|
||||
* @param argv from main()
|
||||
* @return EXIT_FAILURE if arguments are invalid or no input files
|
||||
* were found.
|
||||
* If errors are found and --error-exitcode is used,
|
||||
* given value is returned instead of default 0.
|
||||
* If no errors are found, 0 is returned.
|
||||
*/
|
||||
int check_internal(CppCheck& cppcheck, int argc, const char* const argv[]);
|
||||
int check_internal(CppCheck& cppcheck);
|
||||
|
||||
/**
|
||||
* Pointer to current settings; set while check() is running.
|
||||
|
|
|
@ -511,8 +511,6 @@ void MainWindow::doAnalyzeFiles(const QStringList &files, const bool checkLibrar
|
|||
checkSettings.checkLibrary = checkLibrary;
|
||||
checkSettings.checkConfiguration = checkConfiguration;
|
||||
|
||||
checkSettings.loadCppcheckCfg(QCoreApplication::applicationFilePath().toStdString());
|
||||
|
||||
if (mProjectFile)
|
||||
qDebug() << "Checking project file" << mProjectFile->getFilename();
|
||||
|
||||
|
@ -857,15 +855,10 @@ Settings MainWindow::getCppcheckSettings()
|
|||
result.exename = QCoreApplication::applicationFilePath().toStdString();
|
||||
|
||||
const bool std = tryLoadLibrary(&result.library, "std.cfg");
|
||||
bool posix = true;
|
||||
if (result.posix())
|
||||
posix = tryLoadLibrary(&result.library, "posix.cfg");
|
||||
bool windows = true;
|
||||
if (result.isWindowsPlatform())
|
||||
windows = tryLoadLibrary(&result.library, "windows.cfg");
|
||||
if (!std)
|
||||
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.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"));
|
||||
result.loadCppcheckCfg();
|
||||
|
||||
// If project file loaded, read settings from it
|
||||
if (mProjectFile) {
|
||||
|
|
|
@ -78,9 +78,9 @@ Settings::Settings()
|
|||
certainty.setEnabled(Certainty::normal, true);
|
||||
}
|
||||
|
||||
void Settings::loadCppcheckCfg(const std::string &executable)
|
||||
void Settings::loadCppcheckCfg()
|
||||
{
|
||||
std::string fileName = Path::getPathFromFilename(executable) + "cppcheck.cfg";
|
||||
std::string fileName = Path::getPathFromFilename(exename) + "cppcheck.cfg";
|
||||
#ifdef FILESDIR
|
||||
if (Path::fileExists(FILESDIR "/cppcheck.cfg"))
|
||||
fileName = FILESDIR "/cppcheck.cfg";
|
||||
|
|
|
@ -97,7 +97,7 @@ private:
|
|||
public:
|
||||
Settings();
|
||||
|
||||
void loadCppcheckCfg(const std::string &executable);
|
||||
void loadCppcheckCfg();
|
||||
|
||||
/** @brief addons, either filename of python/json file or json data */
|
||||
std::list<std::string> addons;
|
||||
|
|
|
@ -70,9 +70,9 @@ ${CPPCHECK} ${CPPCHECK_OPT} --inconclusive ${DIR}std.cpp
|
|||
# windows.cpp
|
||||
# Syntax check via g++ does not work because it can not find a valid windows.h
|
||||
#${CXX} ${CXX_OPT} ${DIR}windows.cpp
|
||||
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32A ${DIR}windows.cpp
|
||||
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32W ${DIR}windows.cpp
|
||||
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win64 ${DIR}windows.cpp
|
||||
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32A --library=windows ${DIR}windows.cpp
|
||||
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win32W --library=windows ${DIR}windows.cpp
|
||||
${CPPCHECK} ${CPPCHECK_OPT} --inconclusive --platform=win64 --library=windows ${DIR}windows.cpp
|
||||
|
||||
# wxwidgets.cpp
|
||||
set +e
|
||||
|
|
Loading…
Reference in New Issue