| 323 | } |
| 324 | |
| 325 | cmSarif::LogFileWriter::WriteResult cmSarif::LogFileWriter::TryWrite() |
| 326 | { |
| 327 | // Check that SARIF logging is enabled |
| 328 | if (!this->WriteCondition || !this->WriteCondition()) { |
| 329 | return WriteResult::SKIPPED; |
| 330 | } |
| 331 | |
| 332 | // Open the file |
| 333 | if (!this->EnsureFileValid()) { |
| 334 | return WriteResult::FAILURE; |
| 335 | } |
| 336 | cmsys::ofstream outputFile(this->FilePath.c_str()); |
| 337 | |
| 338 | // The file is available, so proceed to write the log |
| 339 | |
| 340 | // Assemble the SARIF JSON from the results in the log |
| 341 | Json::Value root(Json::objectValue); |
| 342 | this->Log.WriteJson(root); |
| 343 | |
| 344 | // Serialize the JSON to the file |
| 345 | Json::StreamWriterBuilder builder; |
| 346 | std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter()); |
| 347 | |
| 348 | writer->write(root, &outputFile); |
| 349 | outputFile.close(); |
| 350 | |
| 351 | this->FileWritten = true; |
| 352 | return WriteResult::SUCCESS; |
| 353 | } |
| 354 | |
| 355 | bool cmSarif::LogFileWriter::ConfigureForCMakeRun(cmake& cm) |
| 356 | { |
no test coverage detected