diff --git a/Source/cmSarifLog.cxx b/Source/cmSarifLog.cxx index f251b9cb90..72949492fe 100644 --- a/Source/cmSarifLog.cxx +++ b/Source/cmSarifLog.cxx @@ -5,8 +5,6 @@ #include #include -#include - #include #include @@ -300,8 +298,7 @@ cmSarif::LogFileWriter::~LogFileWriter() if (this->TryWrite() == WriteResult::FAILURE) { // If the result is `FAILURE`, it means the write condition is true but // the file still wasn't written. This is an error. - cmSystemTools::Error("Failed to write SARIF log to " + - this->FilePath.generic_string()); + cmSystemTools::Error("Failed to write SARIF log to " + this->FilePath); } } } @@ -309,16 +306,16 @@ cmSarif::LogFileWriter::~LogFileWriter() bool cmSarif::LogFileWriter::EnsureFileValid() { // First, ensure directory exists - cm::filesystem::path dir = this->FilePath.parent_path(); - if (!cmSystemTools::FileIsDirectory(dir.generic_string())) { + std::string const dir = cmSystemTools::GetFilenamePath(this->FilePath); + if (!cmSystemTools::FileIsDirectory(dir)) { if (!this->CreateDirectories || - !cmSystemTools::MakeDirectory(dir.generic_string()).IsSuccess()) { + !cmSystemTools::MakeDirectory(dir).IsSuccess()) { return false; } } // Open the file for writing - cmsys::ofstream outputFile(this->FilePath.generic_string().c_str()); + cmsys::ofstream outputFile(this->FilePath.c_str()); if (!outputFile.good()) { return false; } @@ -336,7 +333,7 @@ cmSarif::LogFileWriter::WriteResult cmSarif::LogFileWriter::TryWrite() if (!this->EnsureFileValid()) { return WriteResult::FAILURE; } - cmsys::ofstream outputFile(this->FilePath.generic_string().c_str()); + cmsys::ofstream outputFile(this->FilePath.c_str()); // The file is available, so proceed to write the log @@ -358,9 +355,8 @@ cmSarif::LogFileWriter::WriteResult cmSarif::LogFileWriter::TryWrite() bool cmSarif::LogFileWriter::ConfigureForCMakeRun(cmake& cm) { // If an explicit SARIF output path has been provided, set and check it - cm::optional sarifFilePath = cm.GetSarifFilePath(); - if (sarifFilePath) { - this->SetPath(cm::filesystem::path(*sarifFilePath)); + if (cm::optional sarifFilePath = cm.GetSarifFilePath()) { + this->SetPath(*sarifFilePath); if (!this->EnsureFileValid()) { cmSystemTools::Error( cmStrCat("Invalid SARIF output file path: ", *sarifFilePath)); diff --git a/Source/cmSarifLog.h b/Source/cmSarifLog.h index efdaf14f16..d267d0001b 100644 --- a/Source/cmSarifLog.h +++ b/Source/cmSarifLog.h @@ -9,7 +9,6 @@ #include #include -#include #include #include @@ -269,8 +268,7 @@ public: /// /// The settings will apply when the log file is written. If the output /// file should be checked earlier, use `CheckFileValidity`. - void SetPath(cm::filesystem::path const& path, - bool createParentDirectories = false) + void SetPath(std::string const& path, bool createParentDirectories = false) { this->FilePath = path; this->CreateDirectories = createParentDirectories; @@ -279,7 +277,7 @@ public: private: ResultsLog const& Log; std::function WriteCondition; - cm::filesystem::path FilePath; + std::string FilePath; bool CreateDirectories = false; bool FileWritten = false; }; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index fc4d6a5961..f635a2a1b2 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -3005,10 +3005,9 @@ int cmake::Run(std::vector const& args, bool noconfigure) if (!this->SarifFileOutput) { // If no output file is specified, use the default path // Enable parent directory creation for the default path - sarifLogFileWriter.SetPath( - cm::filesystem::path(this->GetHomeOutputDirectory()) / - std::string(cmSarif::PROJECT_DEFAULT_SARIF_FILE), - true); + sarifLogFileWriter.SetPath(cmStrCat(this->GetHomeOutputDirectory(), '/', + cmSarif::PROJECT_DEFAULT_SARIF_FILE), + true); } #endif } else {