More flexible loading of platform files, when using --platform it should not be necessary to provide the full path
This commit is contained in:
parent
8e6ac60797
commit
780bd7e63e
|
@ -714,7 +714,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
|||
_settings->platform(Settings::Native);
|
||||
else if (platform == "unspecified")
|
||||
_settings->platform(Settings::Unspecified);
|
||||
else if (!_settings->platformFile(platform)) {
|
||||
else if (!_settings->platformFile(argv[0], platform)) {
|
||||
std::string message("cppcheck: error: unrecognized platform: \"");
|
||||
message += platform;
|
||||
message += "\".";
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
*/
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "path.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
cppcheck::Platform::Platform()
|
||||
{
|
||||
|
@ -154,12 +155,35 @@ bool cppcheck::Platform::platform(cppcheck::Platform::PlatformType type)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool cppcheck::Platform::platformFile(const std::string &filename)
|
||||
bool cppcheck::Platform::platformFile(const char exename[], const std::string &filename)
|
||||
{
|
||||
// open file..
|
||||
tinyxml2::XMLDocument doc;
|
||||
if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_SUCCESS)
|
||||
return false;
|
||||
if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_SUCCESS) {
|
||||
std::vector<std::string> filenames;
|
||||
filenames.push_back(filename + ".xml");
|
||||
if (exename && strchr(exename, '/')) {
|
||||
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename);
|
||||
filenames.push_back(Path::getPathFromFilename(Path::fromNativeSeparators(exename)) + "platforms/" + filename + ".xml");
|
||||
}
|
||||
#ifdef CFGDIR
|
||||
std::string cfgdir = CFGDIR;
|
||||
if (cfgdir[cfgdir.size()-1] != '/')
|
||||
cfgdir += '/';
|
||||
filenames.push_back(CFG_DIR + ("../platforms/" + filename));
|
||||
filenames.push_back(CFG_DIR + ("../platforms/" + filename + ".xml"));
|
||||
#endif
|
||||
bool success = false;
|
||||
for (int i = 0; i < filenames.size(); ++i) {
|
||||
std::cout << "platform:" << filenames[i] << std::endl;
|
||||
if (doc.LoadFile(filenames[i].c_str()) == tinyxml2::XML_SUCCESS) {
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!success)
|
||||
return false;
|
||||
}
|
||||
|
||||
const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement();
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace cppcheck {
|
|||
bool platform(PlatformType type);
|
||||
|
||||
/** set the platform type for user specified platforms */
|
||||
bool platformFile(const std::string &filename);
|
||||
bool platformFile(const char exename[], const std::string &filename);
|
||||
|
||||
/**
|
||||
* @brief Returns true if platform type is Windows
|
||||
|
|
Loading…
Reference in New Issue