Reimplement code. Since a custom command is very flexible and might be extended in the future, make all arguments prefixed with arg type, make ordering irrelevant and potentially all args optional.

This commit is contained in:
Sebastien Barre 2001-11-09 10:33:22 -05:00
parent 438676de38
commit 6b5e54744c
2 changed files with 101 additions and 49 deletions

View File

@ -17,71 +17,122 @@
// cmAddCustomCommandCommand // cmAddCustomCommandCommand
bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& argsIn) bool cmAddCustomCommandCommand::InitialPass(std::vector<std::string> const& args)
{ {
if (argsIn.size() < 6) /* No control on the number of arguments for now since everything can
be optional in that implementation. Should be fixed but this command
is so flexible that too much constraint could prevent user to achieve
a particular task.
Let's complain at the end of this function about the lack of a particular
arg. For the moment, let's say that SOURCE, COMMAND, TARGET are always
required
*/
if (args.size() < 6)
{ {
this->SetError("called with wrong number of arguments."); this->SetError("called with wrong number of arguments.");
return false; return false;
} }
std::vector<std::string> args = argsIn; std::string source, command, target;
std::vector<std::string> command_args, depends, outputs;
if(args[2] != "ARGS") enum tdoing {
doing_source,
doing_command,
doing_target,
doing_args,
doing_depends,
doing_outputs,
doing_nothing
};
tdoing doing = doing_nothing;
for (unsigned int j = 0; j < args.size(); ++j)
{ {
this->SetError("Wrong syntax. The third argument should be ARGS"); std::string copy = args[j];
m_Makefile->ExpandVariablesInString(copy);
if(copy == "SOURCE")
{
doing = doing_source;
}
else if(copy == "COMMAND")
{
doing = doing_command;
}
else if(copy == "TARGET")
{
doing = doing_target;
}
else if(copy == "ARGS")
{
doing = doing_args;
}
else if (copy == "DEPENDS")
{
doing = doing_depends;
}
else if (copy == "OUTPUTS")
{
doing = doing_outputs;
}
else
{
switch (doing)
{
case doing_source:
source = copy;
break;
case doing_command:
command = copy;
break;
case doing_target:
target = copy;
break;
case doing_args:
command_args.push_back(copy);
break;
case doing_depends:
depends.push_back(copy);
break;
case doing_outputs:
outputs.push_back(copy);
break;
default:
this->SetError("Wrong syntax. Unknow type of argument.");
return false; return false;
} }
int cc=3; }
std::vector<std::string> commandArgs;
while(args[cc] != "DEPENDS" && cc < argsIn.size())
{
m_Makefile->ExpandVariablesInString(args[cc]);
commandArgs.push_back(args[cc]);
cc++;
} }
if(cc == argsIn.size()-1) /* At this point we could complain about the lack of arguments.
For the moment, let's say that SOURCE, COMMAND, TARGET are always
required.
*/
if(source.empty())
{ {
this->SetError("Wrong syntax. Missing DEPENDS."); this->SetError("Wrong syntax. Empty SOURCE.");
return false; return false;
} }
cc++ ; // Skip DEPENDS if(command.empty())
std::vector<std::string> depends;
while(args[cc] != "OUTPUTS" && cc < argsIn.size())
{ {
m_Makefile->ExpandVariablesInString(args[cc]); this->SetError("Wrong syntax. Empty COMMAND.");
depends.push_back(args[cc]);
cc++;
}
if(cc == argsIn.size()-1)
{
this->SetError("Wrong syntax. Missing OUTPUTS.");
return false; return false;
} }
cc ++; // Skip OUTPUTS if(target.empty())
std::vector<std::string> outputs;
while(cc < argsIn.size()-1)
{ {
m_Makefile->ExpandVariablesInString(args[cc]); this->SetError("Wrong syntax. Empty TARGET.");
outputs.push_back(args[cc]); return false;
cc++;
} }
m_Makefile->ExpandVariablesInString(args[0]); m_Makefile->AddCustomCommand(source.c_str(),
m_Makefile->ExpandVariablesInString(args[1]); command.c_str(),
m_Makefile->ExpandVariablesInString(args[argsIn.size()-1]); command_args,
m_Makefile->AddCustomCommand(args[0].c_str(),
args[1].c_str(),
commandArgs,
depends, depends,
outputs, outputs,
args[argsIn.size()-1].c_str()); target.c_str());
return true; return true;
} }

View File

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