mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 13:20:47 -06:00
Ninja: In cmGlobalNinjaGenerator use std::unique_ptr to manage output streams
This commit is contained in:
@@ -424,9 +424,6 @@ void cmGlobalNinjaGenerator::WriteDefault(std::ostream& os,
|
||||
|
||||
cmGlobalNinjaGenerator::cmGlobalNinjaGenerator(cmake* cm)
|
||||
: cmGlobalCommonGenerator(cm)
|
||||
, BuildFileStream(nullptr)
|
||||
, RulesFileStream(nullptr)
|
||||
, CompileCommandsStream(nullptr)
|
||||
, UsingGCCOnWindows(false)
|
||||
, ComputingUnknownDependencies(false)
|
||||
, PolicyCMP0058(cmPolicies::WARN)
|
||||
@@ -487,8 +484,12 @@ void cmGlobalNinjaGenerator::Generate()
|
||||
msg.str());
|
||||
return;
|
||||
}
|
||||
this->OpenBuildFileStream();
|
||||
this->OpenRulesFileStream();
|
||||
if (!this->OpenBuildFileStream()) {
|
||||
return;
|
||||
}
|
||||
if (!this->OpenRulesFileStream()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->TargetDependsClosures.clear();
|
||||
|
||||
@@ -737,7 +738,7 @@ void cmGlobalNinjaGenerator::ComputeTargetObjectDirectory(
|
||||
|
||||
// Private methods
|
||||
|
||||
void cmGlobalNinjaGenerator::OpenBuildFileStream()
|
||||
bool cmGlobalNinjaGenerator::OpenBuildFileStream()
|
||||
{
|
||||
// Compute Ninja's build file path.
|
||||
std::string buildFilePath =
|
||||
@@ -747,12 +748,12 @@ void cmGlobalNinjaGenerator::OpenBuildFileStream()
|
||||
|
||||
// Get a stream where to generate things.
|
||||
if (!this->BuildFileStream) {
|
||||
this->BuildFileStream = new cmGeneratedFileStream(
|
||||
this->BuildFileStream = cm::make_unique<cmGeneratedFileStream>(
|
||||
buildFilePath, false, this->GetMakefileEncoding());
|
||||
if (!this->BuildFileStream) {
|
||||
if (!(*this->BuildFileStream)) {
|
||||
// An error message is generated by the constructor if it cannot
|
||||
// open the file.
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -763,19 +764,20 @@ void cmGlobalNinjaGenerator::OpenBuildFileStream()
|
||||
*this->BuildFileStream
|
||||
<< "# This file contains all the build statements describing the\n"
|
||||
<< "# compilation DAG.\n\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void cmGlobalNinjaGenerator::CloseBuildFileStream()
|
||||
{
|
||||
if (this->BuildFileStream) {
|
||||
delete this->BuildFileStream;
|
||||
this->BuildFileStream = nullptr;
|
||||
this->BuildFileStream.reset();
|
||||
} else {
|
||||
cmSystemTools::Error("Build file stream was not open.");
|
||||
}
|
||||
}
|
||||
|
||||
void cmGlobalNinjaGenerator::OpenRulesFileStream()
|
||||
bool cmGlobalNinjaGenerator::OpenRulesFileStream()
|
||||
{
|
||||
// Compute Ninja's build file path.
|
||||
std::string rulesFilePath =
|
||||
@@ -785,12 +787,12 @@ void cmGlobalNinjaGenerator::OpenRulesFileStream()
|
||||
|
||||
// Get a stream where to generate things.
|
||||
if (!this->RulesFileStream) {
|
||||
this->RulesFileStream = new cmGeneratedFileStream(
|
||||
this->RulesFileStream = cm::make_unique<cmGeneratedFileStream>(
|
||||
rulesFilePath, false, this->GetMakefileEncoding());
|
||||
if (!this->RulesFileStream) {
|
||||
if (!(*this->RulesFileStream)) {
|
||||
// An error message is generated by the constructor if it cannot
|
||||
// open the file.
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -805,13 +807,13 @@ void cmGlobalNinjaGenerator::OpenRulesFileStream()
|
||||
<< "# It is included in the main '" << NINJA_BUILD_FILE << "'.\n\n"
|
||||
;
|
||||
/* clang-format on */
|
||||
return true;
|
||||
}
|
||||
|
||||
void cmGlobalNinjaGenerator::CloseRulesFileStream()
|
||||
{
|
||||
if (this->RulesFileStream) {
|
||||
delete this->RulesFileStream;
|
||||
this->RulesFileStream = nullptr;
|
||||
this->RulesFileStream.reset();
|
||||
} else {
|
||||
cmSystemTools::Error("Rules file stream was not open.");
|
||||
}
|
||||
@@ -868,7 +870,8 @@ void cmGlobalNinjaGenerator::AddCXXCompileCommand(
|
||||
}
|
||||
|
||||
// Get a stream where to generate things.
|
||||
this->CompileCommandsStream = new cmGeneratedFileStream(buildFilePath);
|
||||
this->CompileCommandsStream =
|
||||
cm::make_unique<cmGeneratedFileStream>(buildFilePath);
|
||||
*this->CompileCommandsStream << "[";
|
||||
} else {
|
||||
*this->CompileCommandsStream << "," << std::endl;
|
||||
@@ -896,8 +899,7 @@ void cmGlobalNinjaGenerator::CloseCompileCommandsStream()
|
||||
{
|
||||
if (this->CompileCommandsStream) {
|
||||
*this->CompileCommandsStream << "\n]";
|
||||
delete this->CompileCommandsStream;
|
||||
this->CompileCommandsStream = nullptr;
|
||||
this->CompileCommandsStream.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <iosfwd>
|
||||
#include <map>
|
||||
#include <memory> // IWYU pragma: keep
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -14,6 +15,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "cmGeneratedFileStream.h"
|
||||
#include "cmGlobalCommonGenerator.h"
|
||||
#include "cmGlobalGenerator.h"
|
||||
#include "cmGlobalGeneratorFactory.h"
|
||||
@@ -22,7 +24,6 @@
|
||||
#include "cm_codecvt.hxx"
|
||||
|
||||
class cmCustomCommand;
|
||||
class cmGeneratedFileStream;
|
||||
class cmGeneratorTarget;
|
||||
class cmLinkLineComputer;
|
||||
class cmLocalGenerator;
|
||||
@@ -234,12 +235,12 @@ public:
|
||||
|
||||
cmGeneratedFileStream* GetBuildFileStream() const
|
||||
{
|
||||
return this->BuildFileStream;
|
||||
return this->BuildFileStream.get();
|
||||
}
|
||||
|
||||
cmGeneratedFileStream* GetRulesFileStream() const
|
||||
{
|
||||
return this->RulesFileStream;
|
||||
return this->RulesFileStream.get();
|
||||
}
|
||||
|
||||
std::string const& ConvertToNinjaPath(const std::string& path) const;
|
||||
@@ -379,12 +380,12 @@ private:
|
||||
cmMakefile* mf) const override;
|
||||
bool CheckFortran(cmMakefile* mf) const;
|
||||
|
||||
void OpenBuildFileStream();
|
||||
bool OpenBuildFileStream();
|
||||
void CloseBuildFileStream();
|
||||
|
||||
void CloseCompileCommandsStream();
|
||||
|
||||
void OpenRulesFileStream();
|
||||
bool OpenRulesFileStream();
|
||||
void CloseRulesFileStream();
|
||||
|
||||
/// Write the common disclaimer text at the top of each build file.
|
||||
@@ -411,11 +412,11 @@ private:
|
||||
|
||||
/// The file containing the build statement. (the relationship of the
|
||||
/// compilation DAG).
|
||||
cmGeneratedFileStream* BuildFileStream;
|
||||
std::unique_ptr<cmGeneratedFileStream> BuildFileStream;
|
||||
/// The file containing the rule statements. (The action attached to each
|
||||
/// edge of the compilation DAG).
|
||||
cmGeneratedFileStream* RulesFileStream;
|
||||
cmGeneratedFileStream* CompileCommandsStream;
|
||||
std::unique_ptr<cmGeneratedFileStream> RulesFileStream;
|
||||
std::unique_ptr<cmGeneratedFileStream> CompileCommandsStream;
|
||||
|
||||
/// The set of rules added to the generated build system.
|
||||
std::unordered_set<std::string> Rules;
|
||||
|
||||
Reference in New Issue
Block a user