mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-01-26 19:09:06 +00:00
Merge branch 'backport-sarif-path-encoding' into sarif-path-encoding
This commit is contained in:
commit
b79331556d
@ -5,8 +5,6 @@
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <cm/filesystem>
|
||||
|
||||
#include <cm3p/json/value.h>
|
||||
#include <cm3p/json/writer.h>
|
||||
|
||||
@ -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<std::string> sarifFilePath = cm.GetSarifFilePath();
|
||||
if (sarifFilePath) {
|
||||
this->SetPath(cm::filesystem::path(*sarifFilePath));
|
||||
if (cm::optional<std::string> sarifFilePath = cm.GetSarifFilePath()) {
|
||||
this->SetPath(*sarifFilePath);
|
||||
if (!this->EnsureFileValid()) {
|
||||
cmSystemTools::Error(
|
||||
cmStrCat("Invalid SARIF output file path: ", *sarifFilePath));
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/filesystem>
|
||||
#include <cm/optional>
|
||||
|
||||
#include <cm3p/json/value.h>
|
||||
@ -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<bool()> WriteCondition;
|
||||
cm::filesystem::path FilePath;
|
||||
std::string FilePath;
|
||||
bool CreateDirectories = false;
|
||||
bool FileWritten = false;
|
||||
};
|
||||
|
||||
@ -3005,10 +3005,9 @@ int cmake::Run(std::vector<std::string> 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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user