diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 51e583147..485f19e55 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -96,7 +96,7 @@ void ImportProject::FileSettings::setDefines(std::string defs) defines.swap(defs); } -static bool simplifyPathWithVariables(std::string &s, const std::map &variables) +static bool simplifyPathWithVariables(std::string &s, std::map &variables) { std::set expanded; std::string::size_type start = 0; @@ -109,9 +109,17 @@ static bool simplifyPathWithVariables(std::string &s, const std::map::const_iterator it1 = variables.find(var); - if (it1 == variables.end()) - break; - s = s.substr(0,start) + it1->second + s.substr(end+1); + // variable was not found within defined variables + if (it1 == variables.end()) { + 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) return false; @@ -119,7 +127,7 @@ static bool simplifyPathWithVariables(std::string &s, const std::map &in, const std::map &variables) +void ImportProject::FileSettings::setIncludePaths(const std::string &basepath, const std::list &in, std::map &variables) { std::list I; // only parse each includePath once - so remove duplicates @@ -387,7 +395,7 @@ static void importPropertyGroup(const tinyxml2::XMLElement *node, std::map *variables, std::string *includePath, const std::string &additionalIncludeDirectories, std::list &itemDefinitionGroupList) { std::string filename(props); - if (!simplifyPathWithVariables(filename,*variables)) + if (!simplifyPathWithVariables(filename, *variables)) return; tinyxml2::XMLDocument doc; if (doc.LoadFile(filename.c_str()) != tinyxml2::XML_SUCCESS) @@ -414,7 +422,7 @@ static void loadVisualStudioProperties(const std::string &props, std::map variables, const std::string &additionalIncludeDirectories) +void ImportProject::importVcxproj(const std::string &filename, std::map &variables, const std::string &additionalIncludeDirectories) { variables["ProjectDir"] = Path::simplifyPath(Path::getPathFromFilename(filename)); diff --git a/lib/importproject.h b/lib/importproject.h index 5715ef438..5e67b2bff 100644 --- a/lib/importproject.h +++ b/lib/importproject.h @@ -49,7 +49,7 @@ public: cppcheck::Platform::PlatformType platformType; void setDefines(std::string defs); - void setIncludePaths(const std::string &basepath, const std::list &in, const std::map &variables); + void setIncludePaths(const std::string &basepath, const std::list &in, std::map &variables); }; std::list fileSettings; @@ -61,7 +61,7 @@ public: private: void importCompileCommands(std::istream &istr); void importSln(std::istream &istr, const std::string &path); - void importVcxproj(const std::string &filename, std::map variables, const std::string &additionalIncludeDirectories); + void importVcxproj(const std::string &filename, std::map &variables, const std::string &additionalIncludeDirectories); }; /// @}