Add comment support, so that you can see in build process what the custom command does

This commit is contained in:
Andy Cedilnik 2002-12-10 16:47:37 -05:00
parent ab64db6ee8
commit 3893ee72d2
9 changed files with 41 additions and 16 deletions

View File

@ -32,7 +32,7 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
std::vector<std::string> args; std::vector<std::string> args;
cmSystemTools::ExpandListArguments(argsIn, args); cmSystemTools::ExpandListArguments(argsIn, args);
std::string source, command, target; std::string source, command, target, comment;
std::vector<std::string> command_args, depends, outputs; std::vector<std::string> command_args, depends, outputs;
enum tdoing { enum tdoing {
@ -42,6 +42,7 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
doing_args, doing_args,
doing_depends, doing_depends,
doing_outputs, doing_outputs,
doing_comment,
doing_nothing doing_nothing
}; };
@ -75,6 +76,10 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
{ {
doing = doing_outputs; doing = doing_outputs;
} }
else if (copy == "COMMENT")
{
doing = doing_comment;
}
else else
{ {
switch (doing) switch (doing)
@ -97,6 +102,9 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
case doing_outputs: case doing_outputs:
outputs.push_back(copy); outputs.push_back(copy);
break; break;
case doing_comment:
comment = copy;
break;
default: default:
this->SetError("Wrong syntax. Unknow type of argument."); this->SetError("Wrong syntax. Unknow type of argument.");
return false; return false;
@ -108,12 +116,7 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
For the moment, let's say that COMMAND, TARGET are always For the moment, let's say that COMMAND, TARGET are always
required. required.
*/ */
if(command.empty())
{
this->SetError("Wrong syntax. Empty COMMAND.");
return false;
}
if(target.empty()) if(target.empty())
{ {
this->SetError("Wrong syntax. Empty TARGET."); this->SetError("Wrong syntax. Empty TARGET.");
@ -133,7 +136,8 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args
command_args, command_args,
depends, depends,
outputs, outputs,
target.c_str()); target.c_str(),
comment.c_str());
return true; return true;
} }

View File

@ -86,8 +86,8 @@ public:
virtual const char* GetFullDocumentation() virtual const char* GetFullDocumentation()
{ {
return return
"ADD_CUSTOM_COMMAND([SOURCE source] COMMAND command TARGET target " "ADD_CUSTOM_COMMAND([SOURCE source] [COMMAND command] TARGET target "
"[ARGS [args...]] [DEPENDS [depends...]] [OUTPUTS [outputs...]])\n" "[ARGS [args...]] [DEPENDS [depends...]] [OUTPUTS [outputs...]] [COMMENT comment])\n"
"Add a custom command."; "Add a custom command.";
} }

View File

@ -40,6 +40,7 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r):
m_Source(r.m_Source), m_Source(r.m_Source),
m_Command(r.m_Command), m_Command(r.m_Command),
m_Arguments(r.m_Arguments), m_Arguments(r.m_Arguments),
m_Comment(r.m_Comment),
m_Depends(r.m_Depends), m_Depends(r.m_Depends),
m_Outputs(r.m_Outputs) m_Outputs(r.m_Outputs)
{ {

View File

@ -54,6 +54,10 @@ public:
std::string GetCommand() const {return m_Command;} std::string GetCommand() const {return m_Command;}
void SetCommand(const char *cmd) {m_Command = cmd;} void SetCommand(const char *cmd) {m_Command = cmd;}
///! Return the command to execute
std::string GetComment() const {return m_Comment;}
void SetComment(const char *cm) {m_Comment = cm;}
///! Return the commands arguments ///! Return the commands arguments
std::string GetArguments() const {return m_Arguments;} std::string GetArguments() const {return m_Arguments;}
void SetArguments(const char *arg) {m_Arguments = arg;} void SetArguments(const char *arg) {m_Arguments = arg;}
@ -74,6 +78,7 @@ private:
std::string m_Source; std::string m_Source;
std::string m_Command; std::string m_Command;
std::string m_Arguments; std::string m_Arguments;
std::string m_Comment;
std::vector<std::string> m_Depends; std::vector<std::string> m_Depends;
std::vector<std::string> m_Outputs; std::vector<std::string> m_Outputs;
}; };

View File

@ -1785,6 +1785,7 @@ void cmLocalUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
{ {
// escape spaces and convert to native slashes path for // escape spaces and convert to native slashes path for
// the command // the command
const char* comment = c->second.m_Comment.c_str();
std::string command = c->second.m_Command; std::string command = c->second.m_Command;
cmSystemTools::ReplaceString(command, "/./", "/"); cmSystemTools::ReplaceString(command, "/./", "/");
command = cmSystemTools::ConvertToOutputPath(command.c_str()); command = cmSystemTools::ConvertToOutputPath(command.c_str());
@ -1811,7 +1812,7 @@ void cmLocalUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
} }
// output rule // output rule
this->OutputMakeRule(fout, this->OutputMakeRule(fout,
"Custom command", (*comment?comment:"Custom command"),
source.c_str(), source.c_str(),
depends.c_str(), depends.c_str(),
command.c_str()); command.c_str());
@ -1838,7 +1839,7 @@ void cmLocalUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
} }
// output rule // output rule
this->OutputMakeRule(fout, this->OutputMakeRule(fout,
"Custom command", (*comment?comment:"Custom command"),
output->c_str(), output->c_str(),
depends.c_str(), depends.c_str(),
command.c_str()); command.c_str());
@ -2511,7 +2512,8 @@ void cmLocalUnixMakefileGenerator::OutputMakeRule(std::ostream& fout,
{ {
replace = *i; replace = *i;
m_Makefile->ExpandVariablesInString(replace); m_Makefile->ExpandVariablesInString(replace);
if(count == 0 && replace[0] != '-' && replace.find("echo") != 0 if(count == 0 && replace.find_first_not_of(" \t\n\r") != std::string::npos &&
replace[0] != '-' && replace.find("echo") != 0
&& replace.find("$(MAKE)") != 0) && replace.find("$(MAKE)") != 0)
{ {
std::string echostring = "Building "; std::string echostring = "Building ";

View File

@ -415,7 +415,8 @@ void cmMakefile::AddCustomCommand(const char* source,
const std::vector<std::string>& commandArgs, const std::vector<std::string>& commandArgs,
const std::vector<std::string>& depends, const std::vector<std::string>& depends,
const std::vector<std::string>& outputs, const std::vector<std::string>& outputs,
const char *target) const char *target,
const char *comment)
{ {
// find the target, // find the target,
if (m_Targets.find(target) != m_Targets.end()) if (m_Targets.find(target) != m_Targets.end())
@ -434,6 +435,10 @@ void cmMakefile::AddCustomCommand(const char* source,
} }
cmCustomCommand cc(source,c.c_str(),combinedArgs.c_str(),depends,outputs); cmCustomCommand cc(source,c.c_str(),combinedArgs.c_str(),depends,outputs);
if ( comment && comment[0] )
{
cc.SetComment(comment);
}
m_Targets[target].GetCustomCommands().push_back(cc); m_Targets[target].GetCustomCommands().push_back(cc);
std::string cacheCommand = command; std::string cacheCommand = command;
this->ExpandVariablesInString(cacheCommand); this->ExpandVariablesInString(cacheCommand);

View File

@ -123,7 +123,8 @@ public:
const std::vector<std::string>& commandArgs, const std::vector<std::string>& commandArgs,
const std::vector<std::string>& depends, const std::vector<std::string>& depends,
const std::vector<std::string>& outputs, const std::vector<std::string>& outputs,
const char *target); const char *target,
const char *comment = 0);
void AddCustomCommand(const char* source, void AddCustomCommand(const char* source,
const char* command, const char* command,
@ -260,6 +261,8 @@ public:
{ {
m_cmCurrentDirectory = m_cmStartDirectory; m_cmCurrentDirectory = m_cmStartDirectory;
m_CurrentOutputDirectory = m_StartOutputDirectory; m_CurrentOutputDirectory = m_StartOutputDirectory;
this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", m_cmCurrentDirectory.c_str());
this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", m_CurrentOutputDirectory.c_str());
} }
//@{ //@{
@ -323,6 +326,7 @@ public:
{ {
m_cmCurrentDirectory = dir; m_cmCurrentDirectory = dir;
cmSystemTools::ConvertToUnixSlashes(m_cmCurrentDirectory); cmSystemTools::ConvertToUnixSlashes(m_cmCurrentDirectory);
this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR", m_cmCurrentDirectory.c_str());
} }
const char* GetCurrentDirectory() const const char* GetCurrentDirectory() const
{ {
@ -332,6 +336,7 @@ public:
{ {
m_CurrentOutputDirectory = lib; m_CurrentOutputDirectory = lib;
cmSystemTools::ConvertToUnixSlashes(m_CurrentOutputDirectory); cmSystemTools::ConvertToUnixSlashes(m_CurrentOutputDirectory);
this->AddDefinition("CMAKE_CURRENT_BINARY_DIR", m_CurrentOutputDirectory.c_str());
} }
const char* GetCurrentOutputDirectory() const const char* GetCurrentOutputDirectory() const
{ {

View File

@ -80,6 +80,7 @@ void cmSourceGroup::AddCustomCommand(const cmCustomCommand &cmd)
CommandFiles& cmdFiles = CommandFiles& cmdFiles =
m_BuildRules[cmd.GetSourceName()].m_Commands[commandAndArgs]; m_BuildRules[cmd.GetSourceName()].m_Commands[commandAndArgs];
cmdFiles.m_Command = cmd.GetCommand(); cmdFiles.m_Command = cmd.GetCommand();
cmdFiles.m_Comment = cmd.GetComment();
cmdFiles.m_Arguments = cmd.GetArguments(); cmdFiles.m_Arguments = cmd.GetArguments();
cmdFiles.m_Depends.insert(cmd.GetDepends().begin(),cmd.GetDepends().end()); cmdFiles.m_Depends.insert(cmd.GetDepends().begin(),cmd.GetDepends().end());
cmdFiles.m_Outputs.insert(cmd.GetOutputs().begin(),cmd.GetOutputs().end()); cmdFiles.m_Outputs.insert(cmd.GetOutputs().begin(),cmd.GetOutputs().end());
@ -93,6 +94,7 @@ void cmSourceGroup::AddCustomCommand(const cmCustomCommand &cmd)
{ {
// The command did not exist. Add it. // The command did not exist. Add it.
commands[commandAndArgs].m_Command = cmd.GetCommand(); commands[commandAndArgs].m_Command = cmd.GetCommand();
commands[commandAndArgs].m_Comment = cmd.GetComment();
commands[commandAndArgs].m_Arguments = cmd.GetArguments(); commands[commandAndArgs].m_Arguments = cmd.GetArguments();
commands[commandAndArgs].m_Depends.insert(cmd.GetDepends().begin(), commands[commandAndArgs].m_Depends.insert(cmd.GetDepends().begin(),
cmd.GetDepends().end()); cmd.GetDepends().end());

View File

@ -39,12 +39,13 @@ public:
{ {
CommandFiles() {} CommandFiles() {}
CommandFiles(const CommandFiles& r): CommandFiles(const CommandFiles& r):
m_Outputs(r.m_Outputs), m_Depends(r.m_Depends) {} m_Comment(r.m_Comment), m_Outputs(r.m_Outputs), m_Depends(r.m_Depends) {}
void Merge(const CommandFiles &r); void Merge(const CommandFiles &r);
std::string m_Command; std::string m_Command;
std::string m_Arguments; std::string m_Arguments;
std::string m_Comment;
std::set<std::string> m_Outputs; std::set<std::string> m_Outputs;
std::set<std::string> m_Depends; std::set<std::string> m_Depends;
}; };