diff options
author | Sebastian Holtermann <sebholt@xwmw.org> | 2019-05-10 09:54:58 (GMT) |
---|---|---|
committer | Sebastian Holtermann <sebholt@xwmw.org> | 2019-05-11 13:51:30 (GMT) |
commit | 47da9859e8b5e938fa40b69d117aecef82e090a9 (patch) | |
tree | 0648f0bc72f1b2471cbed1e363be2057afeb1e4d /Source/cmGlobalNinjaGenerator.cxx | |
parent | 990270213408bb4d11fa620ba9c96b25da313945 (diff) | |
download | CMake-47da9859e8b5e938fa40b69d117aecef82e090a9.zip CMake-47da9859e8b5e938fa40b69d117aecef82e090a9.tar.gz CMake-47da9859e8b5e938fa40b69d117aecef82e090a9.tar.bz2 |
Ninja: In cmGlobalNinjaGenerator use std::unique_ptr to manage output streams
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx index 90d0f61..71516a2 100644 --- a/Source/cmGlobalNinjaGenerator.cxx +++ b/Source/cmGlobalNinjaGenerator.cxx @@ -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(); } } |