Record backtrace in cmCustomCommand

This will be used to report custom command errors to the user with a
backtrace pointing at the add_custom_command or add_custom_target call.
This commit is contained in:
Brad King 2010-12-06 14:33:59 -05:00
parent 53ea8b3204
commit bfb7288f81
6 changed files with 40 additions and 9 deletions

View File

@ -11,6 +11,8 @@
============================================================================*/
#include "cmCustomCommand.h"
#include "cmMakefile.h"
//----------------------------------------------------------------------------
cmCustomCommand::cmCustomCommand()
{
@ -28,12 +30,14 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
Comment(r.Comment),
WorkingDirectory(r.WorkingDirectory),
EscapeAllowMakeVars(r.EscapeAllowMakeVars),
EscapeOldStyle(r.EscapeOldStyle)
EscapeOldStyle(r.EscapeOldStyle),
Backtrace(new cmListFileBacktrace(*r.Backtrace))
{
}
//----------------------------------------------------------------------------
cmCustomCommand::cmCustomCommand(const std::vector<std::string>& outputs,
cmCustomCommand::cmCustomCommand(cmMakefile* mf,
const std::vector<std::string>& outputs,
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines,
const char* comment,
@ -45,10 +49,21 @@ cmCustomCommand::cmCustomCommand(const std::vector<std::string>& outputs,
Comment(comment?comment:""),
WorkingDirectory(workingDirectory?workingDirectory:""),
EscapeAllowMakeVars(false),
EscapeOldStyle(true)
EscapeOldStyle(true),
Backtrace(new cmListFileBacktrace)
{
this->EscapeOldStyle = true;
this->EscapeAllowMakeVars = false;
if(mf)
{
mf->GetBacktrace(*this->Backtrace);
}
}
//----------------------------------------------------------------------------
cmCustomCommand::~cmCustomCommand()
{
delete this->Backtrace;
}
//----------------------------------------------------------------------------
@ -130,6 +145,12 @@ void cmCustomCommand::SetEscapeAllowMakeVars(bool b)
this->EscapeAllowMakeVars = b;
}
//----------------------------------------------------------------------------
cmListFileBacktrace const& cmCustomCommand::GetBacktrace() const
{
return *this->Backtrace;
}
//----------------------------------------------------------------------------
cmCustomCommand::ImplicitDependsList const&
cmCustomCommand::GetImplicitDepends() const

View File

@ -13,6 +13,8 @@
#define cmCustomCommand_h
#include "cmStandardIncludes.h"
class cmMakefile;
class cmListFileBacktrace;
/** \class cmCustomCommand
* \brief A class to encapsulate a custom command
@ -27,12 +29,15 @@ public:
cmCustomCommand(const cmCustomCommand& r);
/** Main constructor specifies all information for the command. */
cmCustomCommand(const std::vector<std::string>& outputs,
cmCustomCommand(cmMakefile* mf,
const std::vector<std::string>& outputs,
const std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines,
const char* comment,
const char* workingDirectory);
~cmCustomCommand();
/** Get the output file produced by the command. */
const std::vector<std::string>& GetOutputs() const;
@ -63,6 +68,9 @@ public:
bool GetEscapeAllowMakeVars() const;
void SetEscapeAllowMakeVars(bool b);
/** Backtrace of the command that created this custom command. */
cmListFileBacktrace const& GetBacktrace() const;
typedef std::pair<cmStdString, cmStdString> ImplicitDependsPair;
class ImplicitDependsList: public std::vector<ImplicitDependsPair> {};
void SetImplicitDepends(ImplicitDependsList const&);
@ -78,6 +86,7 @@ private:
std::string WorkingDirectory;
bool EscapeAllowMakeVars;
bool EscapeOldStyle;
cmListFileBacktrace* Backtrace;
ImplicitDependsList ImplicitDepends;
};

View File

@ -1893,7 +1893,7 @@ cmTarget cmGlobalGenerator::CreateGlobalTarget(
std::vector<std::string> no_outputs;
std::vector<std::string> no_depends;
// Store the custom command in the target.
cmCustomCommand cc(no_outputs, no_depends, *commandLines, 0,
cmCustomCommand cc(0, no_outputs, no_depends, *commandLines, 0,
workingDirectory);
target.GetPostBuildCommands().push_back(cc);
target.SetProperty("EchoString", message);

View File

@ -838,7 +838,7 @@ cmLocalVisualStudio6Generator::MaybeCreateOutputDir(cmTarget& target,
std::vector<std::string> no_depends;
cmCustomCommandLines commands;
commands.push_back(command);
pcc.reset(new cmCustomCommand(no_output, no_depends, commands, 0, 0));
pcc.reset(new cmCustomCommand(0, no_output, no_depends, commands, 0, 0));
pcc->SetEscapeOldStyle(false);
pcc->SetEscapeAllowMakeVars(true);
return pcc;

View File

@ -53,7 +53,7 @@ cmLocalVisualStudioGenerator::MaybeCreateImplibDir(cmTarget& target,
std::vector<std::string> no_depends;
cmCustomCommandLines commands;
commands.push_back(command);
pcc.reset(new cmCustomCommand(no_output, no_depends, commands, 0, 0));
pcc.reset(new cmCustomCommand(0, no_output, no_depends, commands, 0, 0));
pcc->SetEscapeOldStyle(false);
pcc->SetEscapeAllowMakeVars(true);
return pcc;

View File

@ -827,7 +827,8 @@ cmMakefile::AddCustomCommandToTarget(const char* target,
{
// Add the command to the appropriate build step for the target.
std::vector<std::string> no_output;
cmCustomCommand cc(no_output, depends, commandLines, comment, workingDir);
cmCustomCommand cc(this, no_output, depends,
commandLines, comment, workingDir);
cc.SetEscapeOldStyle(escapeOldStyle);
cc.SetEscapeAllowMakeVars(true);
switch(type)
@ -947,7 +948,7 @@ cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs,
if(file)
{
cmCustomCommand* cc =
new cmCustomCommand(outputs, depends2, commandLines,
new cmCustomCommand(this, outputs, depends2, commandLines,
comment, workingDir);
cc->SetEscapeOldStyle(escapeOldStyle);
cc->SetEscapeAllowMakeVars(true);