mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-16 20:21:41 -06:00
cmCustomCommandGenerator: refactor GetComment to return std::string
Refactoring was done because EvaluateComment leaked memory.
This commit is contained in:
@@ -463,9 +463,12 @@ std::string cmCustomCommandGenerator::GetInternalDepfile() const
|
||||
return this->ComputeInternalDepfile(this->OutputConfig, depfile);
|
||||
}
|
||||
|
||||
const char* cmCustomCommandGenerator::GetComment() const
|
||||
cm::optional<std::string> cmCustomCommandGenerator::GetComment() const
|
||||
{
|
||||
return this->CC->GetComment();
|
||||
if (const char* comment = this->CC->GetComment()) {
|
||||
return comment;
|
||||
}
|
||||
return cm::nullopt;
|
||||
}
|
||||
|
||||
std::string cmCustomCommandGenerator::GetWorkingDirectory() const
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
unsigned int GetNumberOfCommands() const;
|
||||
std::string GetCommand(unsigned int c) const;
|
||||
void AppendArguments(unsigned int c, std::string& cmd) const;
|
||||
const char* GetComment() const;
|
||||
cm::optional<std::string> GetComment() const;
|
||||
std::string GetWorkingDirectory() const;
|
||||
std::vector<std::string> const& GetOutputs() const;
|
||||
std::vector<std::string> const& GetByproducts() const;
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/optional>
|
||||
|
||||
#include "cmCustomCommand.h"
|
||||
#include "cmCustomCommandGenerator.h"
|
||||
#include "cmGeneratedFileStream.h"
|
||||
@@ -411,9 +413,8 @@ void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
|
||||
cmdLines.push_back("@echo off");
|
||||
#endif
|
||||
// Echo the custom command's comment text.
|
||||
const char* comment = ccg.GetComment();
|
||||
if (comment && *comment) {
|
||||
std::string echocmd = cmStrCat("echo ", comment);
|
||||
if (cm::optional<std::string> comment = ccg.GetComment()) {
|
||||
std::string echocmd = cmStrCat("echo ", *comment);
|
||||
cmdLines.push_back(std::move(echocmd));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cm/optional>
|
||||
#include <cmext/algorithm>
|
||||
#include <cmext/string_view>
|
||||
|
||||
@@ -2280,11 +2281,11 @@ void cmGlobalXCodeGenerator::CreateCustomRulesMakefile(
|
||||
}
|
||||
makefileStream << "\n";
|
||||
|
||||
if (const char* comment = ccg.GetComment()) {
|
||||
if (cm::optional<std::string> comment = ccg.GetComment()) {
|
||||
std::string echo_cmd =
|
||||
cmStrCat("echo ",
|
||||
(this->CurrentLocalGenerator->EscapeForShell(
|
||||
comment, ccg.GetCC().GetEscapeAllowMakeVars())));
|
||||
*comment, ccg.GetCC().GetEscapeAllowMakeVars())));
|
||||
makefileStream << "\t" << echo_cmd << "\n";
|
||||
}
|
||||
|
||||
|
||||
@@ -3484,8 +3484,8 @@ std::string cmLocalGenerator::ConstructComment(
|
||||
cmCustomCommandGenerator const& ccg, const char* default_comment) const
|
||||
{
|
||||
// Check for a comment provided with the command.
|
||||
if (ccg.GetComment()) {
|
||||
return ccg.GetComment();
|
||||
if (cm::optional<std::string> comment = ccg.GetComment()) {
|
||||
return *comment;
|
||||
}
|
||||
|
||||
// Construct a reasonable default comment if possible.
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cm/optional>
|
||||
#include <cm/string_view>
|
||||
#include <cm/vector>
|
||||
#include <cmext/algorithm>
|
||||
@@ -945,9 +946,8 @@ void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
|
||||
// post-build command comments. Custom build step commands have
|
||||
// their comments generated elsewhere.
|
||||
if (echo_comment) {
|
||||
const char* comment = ccg.GetComment();
|
||||
if (comment && *comment) {
|
||||
this->AppendEcho(commands, comment,
|
||||
if (cm::optional<std::string> comment = ccg.GetComment()) {
|
||||
this->AppendEcho(commands, *comment,
|
||||
cmLocalUnixMakefileGenerator3::EchoGenerate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cm/optional>
|
||||
#include <cmext/algorithm>
|
||||
|
||||
#include <windows.h>
|
||||
@@ -592,9 +593,8 @@ public:
|
||||
{
|
||||
cmCustomCommandGenerator ccg(cc, this->Config, this->LG);
|
||||
if (this->First) {
|
||||
const char* comment = ccg.GetComment();
|
||||
if (comment && *comment) {
|
||||
this->Stream << "\nDescription=\"" << this->LG->EscapeForXML(comment)
|
||||
if (cm::optional<std::string> comment = ccg.GetComment()) {
|
||||
this->Stream << "\nDescription=\"" << this->LG->EscapeForXML(*comment)
|
||||
<< "\"";
|
||||
}
|
||||
this->Stream << "\nCommandLine=\"";
|
||||
|
||||
Reference in New Issue
Block a user