From b683d7b2d6855a073760529edd1ba6312b9e9918 Mon Sep 17 00:00:00 2001 From: Manuel Dobusch Date: Thu, 7 Jul 2016 00:14:29 +0200 Subject: [PATCH] logic: VS Solution Macro Handling Added handling of project specific VS macros --- cmake/publicKey.cmake | 4 +- .../solution/SolutionParserUtility.cpp | 22 +++++ .../utility/solution/SolutionParserUtility.h | 1 + .../solution/SolutionParserVisualStudio.cpp | 99 +++++++++++++++++-- .../solution/SolutionParserVisualStudio.h | 2 + 5 files changed, 118 insertions(+), 10 deletions(-) diff --git a/cmake/publicKey.cmake b/cmake/publicKey.cmake index 5b3a59de..f4227c7e 100644 --- a/cmake/publicKey.cmake +++ b/cmake/publicKey.cmake @@ -4,6 +4,8 @@ string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_VERSION_NUMBER}") message(STATUS "Get Public Key for Coati version: ${VERSION_MAJOR}") +message(STATUS "${CMAKE_SOURCE_DIR}/setup/RSA_keys/public-${VERSION_MAJOR}.pem") + set(pubKeyFile "${CMAKE_SOURCE_DIR}/setup/RSA_keys/public-${VERSION_MAJOR}.pem") # message(STATUS "file: ${pubKeyFile}") @@ -13,7 +15,7 @@ if(EXISTS ${pubKeyFile}) STRING(REGEX REPLACE "\n" "\\\\n\"\n\t\"" KEY "${KEY}") # message(STATUS "key: ${KEY}") else() - message(WARNING "public keyfile for this version of Coati") + message(WARNING "public keyfile for this version of Coati not found") endif() configure_file( diff --git a/src/lib/utility/solution/SolutionParserUtility.cpp b/src/lib/utility/solution/SolutionParserUtility.cpp index 051438a8..9fa5ecf5 100644 --- a/src/lib/utility/solution/SolutionParserUtility.cpp +++ b/src/lib/utility/solution/SolutionParserUtility.cpp @@ -345,6 +345,28 @@ std::vector SolutionParserUtility::makePathsCanonical(const std::ve return canonicalPaths; } +std::string SolutionParserUtility::makePathCanonical(const std::string& path) +{ + std::string result = ""; + + try + { + boost::filesystem::path canonicalPath = boost::filesystem::canonical(boost::filesystem::path(path)); + result = canonicalPath.string(); + } + catch (std::exception& e) + { + std::string what = e.what(); + LOG_WARNING_STREAM(<< e.what()); + + std::stringstream errorMessage; + errorMessage << "Could not make path \"" << path << "\" canonical. Check if it really exists."; + MessageStatus(errorMessage.str(), true).dispatch(); + } + + return result; +} + std::string SolutionParserUtility::checkIsIdeMacro(const std::string& text) { for (unsigned int i = 0; i < m_ideMacros.size(); i++) diff --git a/src/lib/utility/solution/SolutionParserUtility.h b/src/lib/utility/solution/SolutionParserUtility.h index 91ffd492..33598c22 100644 --- a/src/lib/utility/solution/SolutionParserUtility.h +++ b/src/lib/utility/solution/SolutionParserUtility.h @@ -21,6 +21,7 @@ public: static std::vector resolveEnvironmentVariables(const std::vector& paths); static std::string findAndResolveEnvironmentVariable(const std::string& path); static std::vector makePathsCanonical(const std::vector& paths); + static std::string makePathCanonical(const std::string& path); static std::string checkIsIdeMacro(const std::string& text); // returns matching macro or empty string if no match was found diff --git a/src/lib/utility/solution/SolutionParserVisualStudio.cpp b/src/lib/utility/solution/SolutionParserVisualStudio.cpp index 63d76ddd..d6621e71 100644 --- a/src/lib/utility/solution/SolutionParserVisualStudio.cpp +++ b/src/lib/utility/solution/SolutionParserVisualStudio.cpp @@ -340,6 +340,8 @@ std::vector SolutionParserVisualStudio::findProjectItems() continue; } + setProjectMacros(projectFilesNames[i]); + TiXmlElement* root = SolutionParserUtility::getFirstTagByNameWithAttribute(doc.RootElement(), "ClCompile", "Include"); TiXmlElement* headerRoot = SolutionParserUtility::getFirstTagByNameWithAttribute(doc.RootElement(), "ClInclude", "Include"); if (root != NULL) @@ -394,7 +396,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() } }*/ - + std::vector filePaths; if (root != NULL) { @@ -404,7 +406,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() if (boost::filesystem::exists(filePath) && SolutionParserUtility::checkValidFileExtension(filePath, validFileExtensions)) { - projectItems.push_back(filePath); + filePaths.push_back(filePath); continue; } @@ -415,7 +417,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() if (SolutionParserUtility::checkValidFileExtension(filePath, validFileExtensions)) { - projectItems.push_back(filePath); + filePaths.push_back(filePath); } } } @@ -428,7 +430,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() if (boost::filesystem::exists(filePath) && SolutionParserUtility::checkValidFileExtension(filePath, validFileExtensions)) { - projectItems.push_back(filePath); + filePaths.push_back(filePath); continue; } @@ -439,10 +441,20 @@ std::vector SolutionParserVisualStudio::findProjectItems() if (SolutionParserUtility::checkValidFileExtension(filePath, validFileExtensions)) { - projectItems.push_back(filePath); + filePaths.push_back(filePath); } } } + + std::set s(filePaths.begin(), filePaths.end()); + filePaths.assign(s.begin(), s.end()); + + filePaths = SolutionParserUtility::resolveEnvironmentVariables(filePaths); + + for (unsigned int j = 0; j < filePaths.size(); j++) + { + projectItems.push_back(filePaths[j]); + } } std::set s(projectItems.begin(), projectItems.end()); @@ -450,7 +462,7 @@ std::vector SolutionParserVisualStudio::findProjectItems() LOG_INFO_STREAM(<< "Found " << projectItems.size() << " code files"); - projectItems = SolutionParserUtility::resolveEnvironmentVariables(projectItems); + // projectItems = SolutionParserUtility::resolveEnvironmentVariables(projectItems); projectItems = makePathsAbsolute(projectItems); return projectItems; @@ -461,6 +473,7 @@ std::vector SolutionParserVisualStudio::findIncludePaths() std::vector includePaths; std::vector projectFiles = getProjectFiles(); + std::vector projectFilesNames = getProjects(); std::vector validExtensions; validExtensions.push_back(".c"); @@ -475,6 +488,8 @@ std::vector SolutionParserVisualStudio::findIncludePaths() TiXmlDocument doc; doc.Parse(projectFiles[i].c_str(), 0, TIXML_ENCODING_UTF8); + setProjectMacros(projectFilesNames[i]); + std::string error = doc.ErrorDesc(); if (error.length() > 0) @@ -485,22 +500,36 @@ std::vector SolutionParserVisualStudio::findIncludePaths() std::vector nodes = SolutionParserUtility::getAllTagsByName(doc.RootElement(), "AdditionalIncludeDirectories"); + std::vector paths; + for (unsigned int j = 0; j < nodes.size(); j++) { std::string path = nodes[j]->GetText(); - includePaths.push_back(path); + paths.push_back(path); + } + + paths = seperateIncludePaths(paths); + + std::set s(paths.begin(), paths.end()); + paths.assign(s.begin(), s.end()); + + paths = SolutionParserUtility::resolveEnvironmentVariables(paths); + + for (unsigned int j = 0; j < paths.size(); j++) + { + includePaths.push_back(paths[j]); } } - includePaths = seperateIncludePaths(includePaths); + // includePaths = seperateIncludePaths(includePaths); std::set s(includePaths.begin(), includePaths.end()); includePaths.assign(s.begin(), s.end()); LOG_INFO_STREAM(<< "Found " << includePaths.size() << " additional include paths"); - includePaths = SolutionParserUtility::resolveEnvironmentVariables(includePaths); + // includePaths = SolutionParserUtility::resolveEnvironmentVariables(includePaths); includePaths = makePathsAbsolute(includePaths); return includePaths; @@ -638,3 +667,55 @@ std::vector SolutionParserVisualStudio::seperateCompilerFlags(const return seperatedFlags; } + +void SolutionParserVisualStudio::setProjectMacros(const std::string& projectName) +{ + std::string solutionPath = getSolutionPath(); + + std::string projectNameBase = projectName; + + std::replace(solutionPath.begin(), solutionPath.end(), '/', '\\'); + std::replace(projectNameBase.begin(), projectNameBase.end(), '/', '\\'); + + std::string projectPath = solutionPath + projectNameBase; + + std::string projectDirectory = ""; + std::string projectNameOnly = ""; + + size_t pos = projectNameBase.find_last_of('\\'); + if (pos != std::string::npos) + { + projectDirectory = projectNameBase.substr(0, pos); + projectNameOnly = projectNameBase.substr(pos + 1); + } + else + { + projectNameOnly = projectNameBase; + } + + std::string projectExtension = ""; + + pos = projectNameOnly.find_last_of('.'); + if (pos != std::string::npos) + { + projectExtension = projectNameOnly.substr(pos + 1); + projectNameOnly = projectNameOnly.substr(0, pos); + } + + projectPath = SolutionParserUtility::findAndResolveEnvironmentVariable(projectPath); + projectPath = SolutionParserUtility::makePathCanonical(projectPath); + + std::string projectDir = ""; + + pos = projectPath.find_last_of('\\'); + if (pos != std::string::npos) + { + projectDir = projectPath.substr(0, pos+1); + } + + SolutionParserUtility::m_ideMacroValues["ProjectDir"] = projectDir; + SolutionParserUtility::m_ideMacroValues["ProjectPath"] = projectPath; + SolutionParserUtility::m_ideMacroValues["ProjectName"] = projectNameOnly; + SolutionParserUtility::m_ideMacroValues["ProjectFileName"] = projectNameOnly + "." + projectExtension; + SolutionParserUtility::m_ideMacroValues["ProjectExt"] = projectExtension; +} diff --git a/src/lib/utility/solution/SolutionParserVisualStudio.h b/src/lib/utility/solution/SolutionParserVisualStudio.h index c08942d1..b65bfb66 100644 --- a/src/lib/utility/solution/SolutionParserVisualStudio.h +++ b/src/lib/utility/solution/SolutionParserVisualStudio.h @@ -45,6 +45,8 @@ private: std::vector seperateCompilerFlags(const std::vector& compilerFlags) const; std::vector seperateCompilerFlags(const std::string& compilerFlags) const; + void setProjectMacros(const std::string& projectName); + std::vector m_compatibilityFlags; };