From 2eef2baf93306857acc68f993686e3f7510e58a0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 19 Dec 2025 14:26:57 -0500 Subject: cmake: Fix SARIF diagnostics output path encoding on Windows Avoid using `filesystem::path` to hold the output path. It performs encoding conversions that violate our internal UTF-8 encoding. Fixes: #27471 Issue: #27472 --- Source/cmSarifLog.cxx | 20 ++++++++------------ Source/cmSarifLog.h | 6 ++---- Source/cmake.cxx | 8 +++----- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/Source/cmSarifLog.cxx b/Source/cmSarifLog.cxx index 35b67f7..e5953db 100644 --- a/Source/cmSarifLog.cxx +++ b/Source/cmSarifLog.cxx @@ -5,8 +5,6 @@ #include #include -#include - #include #include @@ -299,8 +297,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); } } } @@ -308,16 +305,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; } @@ -335,7 +332,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 @@ -357,9 +354,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 efdaf14..d267d00 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 0d405a3..7d0b1ad 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -14,7 +14,6 @@ #include #include -#include #include #include #include @@ -2929,10 +2928,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 { -- cgit v0.12