| 16 | #include "cmVersion.h" |
| 17 | |
| 18 | bool cmGlobVerificationManager::SaveVerificationScript(std::string const& path, |
| 19 | cmMessenger* messenger) |
| 20 | { |
| 21 | if (this->Cache.empty()) { |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | std::string scriptFile = cmStrCat(path, "/CMakeFiles"); |
| 26 | std::string stampFile = scriptFile; |
| 27 | cmSystemTools::MakeDirectory(scriptFile); |
| 28 | scriptFile += "/VerifyGlobs.cmake"; |
| 29 | stampFile += "/cmake.verify_globs"; |
| 30 | cmGeneratedFileStream verifyScriptFile(scriptFile); |
| 31 | verifyScriptFile.SetCopyIfDifferent(true); |
| 32 | if (!verifyScriptFile) { |
| 33 | cmSystemTools::Error("Unable to open verification script file for save. " + |
| 34 | scriptFile); |
| 35 | cmSystemTools::ReportLastSystemError(""); |
| 36 | return false; |
| 37 | } |
| 38 | |
| 39 | verifyScriptFile << std::boolalpha; |
| 40 | verifyScriptFile << "# CMAKE generated file: DO NOT EDIT!\n" |
| 41 | << "# Generated by CMake Version " |
| 42 | << cmVersion::GetMajorVersion() << "." |
| 43 | << cmVersion::GetMinorVersion() << "\n"; |
| 44 | |
| 45 | for (auto const& i : this->Cache) { |
| 46 | CacheEntryKey k = std::get<0>(i); |
| 47 | CacheEntryValue v = std::get<1>(i); |
| 48 | |
| 49 | if (!v.Initialized) { |
| 50 | continue; |
| 51 | } |
| 52 | |
| 53 | verifyScriptFile << "\n"; |
| 54 | |
| 55 | for (auto const& bt : v.Backtraces) { |
| 56 | verifyScriptFile << "# " << std::get<0>(bt); |
| 57 | messenger->PrintBacktraceTitle(verifyScriptFile, std::get<1>(bt)); |
| 58 | verifyScriptFile << "\n"; |
| 59 | } |
| 60 | |
| 61 | k.PrintGlobCommand(verifyScriptFile, "NEW_GLOB"); |
| 62 | verifyScriptFile << "\n"; |
| 63 | |
| 64 | verifyScriptFile << "set(OLD_GLOB\n"; |
| 65 | for (std::string const& file : v.Files) { |
| 66 | verifyScriptFile << " \"" << file << "\"\n"; |
| 67 | } |
| 68 | verifyScriptFile << " )\n"; |
| 69 | |
| 70 | verifyScriptFile << "if(NOT \"${NEW_GLOB}\" STREQUAL \"${OLD_GLOB}\")\n" |
| 71 | << " message(\"-- GLOB mismatch!\")\n" |
| 72 | << " set(NEW_ONLY ${NEW_GLOB})\n" |
| 73 | << " set(OLD_ONLY ${OLD_GLOB})\n" |
| 74 | << " list(REMOVE_ITEM NEW_ONLY ${OLD_GLOB})\n" |
| 75 | << " list(REMOVE_ITEM OLD_ONLY ${NEW_GLOB})\n" |
nothing calls this directly
no test coverage detected