import solution: Support system environment variables
This commit is contained in:
parent
80367095db
commit
15b0eb42bd
|
@ -96,7 +96,7 @@ void ImportProject::FileSettings::setDefines(std::string defs)
|
||||||
defines.swap(defs);
|
defines.swap(defs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool simplifyPathWithVariables(std::string &s, const std::map<std::string, std::string> &variables)
|
static bool simplifyPathWithVariables(std::string &s, std::map<std::string, std::string> &variables)
|
||||||
{
|
{
|
||||||
std::set<std::string> expanded;
|
std::set<std::string> expanded;
|
||||||
std::string::size_type start = 0;
|
std::string::size_type start = 0;
|
||||||
|
@ -109,9 +109,17 @@ static bool simplifyPathWithVariables(std::string &s, const std::map<std::string
|
||||||
break;
|
break;
|
||||||
expanded.insert(var);
|
expanded.insert(var);
|
||||||
std::map<std::string, std::string>::const_iterator it1 = variables.find(var);
|
std::map<std::string, std::string>::const_iterator it1 = variables.find(var);
|
||||||
if (it1 == variables.end())
|
// variable was not found within defined variables
|
||||||
break;
|
if (it1 == variables.end()) {
|
||||||
s = s.substr(0,start) + it1->second + s.substr(end+1);
|
const char *envValue = std::getenv(var.c_str());
|
||||||
|
if (!envValue) {
|
||||||
|
//! @TODO generate a debug/info message about undefined variable
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
variables[var] = std::string(envValue);
|
||||||
|
it1 = variables.find(var);
|
||||||
|
}
|
||||||
|
s = s.substr(0, start) + it1->second + s.substr(end + 1);
|
||||||
}
|
}
|
||||||
if (s.find("$(") != std::string::npos)
|
if (s.find("$(") != std::string::npos)
|
||||||
return false;
|
return false;
|
||||||
|
@ -119,7 +127,7 @@ static bool simplifyPathWithVariables(std::string &s, const std::map<std::string
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportProject::FileSettings::setIncludePaths(const std::string &basepath, const std::list<std::string> &in, const std::map<std::string, std::string> &variables)
|
void ImportProject::FileSettings::setIncludePaths(const std::string &basepath, const std::list<std::string> &in, std::map<std::string, std::string> &variables)
|
||||||
{
|
{
|
||||||
std::list<std::string> I;
|
std::list<std::string> I;
|
||||||
// only parse each includePath once - so remove duplicates
|
// only parse each includePath once - so remove duplicates
|
||||||
|
@ -387,7 +395,7 @@ static void importPropertyGroup(const tinyxml2::XMLElement *node, std::map<std::
|
||||||
static void loadVisualStudioProperties(const std::string &props, std::map<std::string,std::string> *variables, std::string *includePath, const std::string &additionalIncludeDirectories, std::list<ItemDefinitionGroup> &itemDefinitionGroupList)
|
static void loadVisualStudioProperties(const std::string &props, std::map<std::string,std::string> *variables, std::string *includePath, const std::string &additionalIncludeDirectories, std::list<ItemDefinitionGroup> &itemDefinitionGroupList)
|
||||||
{
|
{
|
||||||
std::string filename(props);
|
std::string filename(props);
|
||||||
if (!simplifyPathWithVariables(filename,*variables))
|
if (!simplifyPathWithVariables(filename, *variables))
|
||||||
return;
|
return;
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_SUCCESS)
|
if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_SUCCESS)
|
||||||
|
@ -414,7 +422,7 @@ static void loadVisualStudioProperties(const std::string &props, std::map<std::s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImportProject::importVcxproj(const std::string &filename, std::map<std::string, std::string> variables, const std::string &additionalIncludeDirectories)
|
void ImportProject::importVcxproj(const std::string &filename, std::map<std::string, std::string> &variables, const std::string &additionalIncludeDirectories)
|
||||||
{
|
{
|
||||||
variables["ProjectDir"] = Path::simplifyPath(Path::getPathFromFilename(filename));
|
variables["ProjectDir"] = Path::simplifyPath(Path::getPathFromFilename(filename));
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
cppcheck::Platform::PlatformType platformType;
|
cppcheck::Platform::PlatformType platformType;
|
||||||
|
|
||||||
void setDefines(std::string defs);
|
void setDefines(std::string defs);
|
||||||
void setIncludePaths(const std::string &basepath, const std::list<std::string> &in, const std::map<std::string, std::string> &variables);
|
void setIncludePaths(const std::string &basepath, const std::list<std::string> &in, std::map<std::string, std::string> &variables);
|
||||||
};
|
};
|
||||||
std::list<FileSettings> fileSettings;
|
std::list<FileSettings> fileSettings;
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void importCompileCommands(std::istream &istr);
|
void importCompileCommands(std::istream &istr);
|
||||||
void importSln(std::istream &istr, const std::string &path);
|
void importSln(std::istream &istr, const std::string &path);
|
||||||
void importVcxproj(const std::string &filename, std::map<std::string, std::string> variables, const std::string &additionalIncludeDirectories);
|
void importVcxproj(const std::string &filename, std::map<std::string, std::string> &variables, const std::string &additionalIncludeDirectories);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
Loading…
Reference in New Issue