cmCustomCommand: Return std::string from GetWorkingDirectory

This commit is contained in:
Brad King 2014-03-10 13:53:57 -04:00
parent cb8f87f622
commit d45e7f3461
7 changed files with 22 additions and 29 deletions

View File

@ -100,16 +100,6 @@ const std::vector<std::string>& cmCustomCommand::GetOutputs() const
return this->Outputs; return this->Outputs;
} }
//----------------------------------------------------------------------------
const char* cmCustomCommand::GetWorkingDirectory() const
{
if(this->WorkingDirectory.size() == 0)
{
return 0;
}
return this->WorkingDirectory.c_str();
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const std::vector<std::string>& cmCustomCommand::GetDepends() const const std::vector<std::string>& cmCustomCommand::GetDepends() const
{ {

View File

@ -42,12 +42,13 @@ public:
/** Get the output file produced by the command. */ /** Get the output file produced by the command. */
const std::vector<std::string>& GetOutputs() const; const std::vector<std::string>& GetOutputs() const;
/** Get the working directory. */
const char* GetWorkingDirectory() const;
/** Get the vector that holds the list of dependencies. */ /** Get the vector that holds the list of dependencies. */
const std::vector<std::string>& GetDepends() const; const std::vector<std::string>& GetDepends() const;
/** Get the working directory. */
std::string const& GetWorkingDirectory() const
{ return this->WorkingDirectory; }
/** Get the list of command lines. */ /** Get the list of command lines. */
const cmCustomCommandLines& GetCommandLines() const; const cmCustomCommandLines& GetCommandLines() const;

View File

@ -1646,10 +1646,11 @@ void cmGlobalXCodeGenerator
cmSystemTools::ReplaceString(cmd2, "/./", "/"); cmSystemTools::ReplaceString(cmd2, "/./", "/");
cmd2 = this->ConvertToRelativeForMake(cmd2.c_str()); cmd2 = this->ConvertToRelativeForMake(cmd2.c_str());
std::string cmd; std::string cmd;
if(cc.GetWorkingDirectory()) std::string wd = cc.GetWorkingDirectory();
if(!wd.empty())
{ {
cmd += "cd "; cmd += "cd ";
cmd += this->ConvertToRelativeForMake(cc.GetWorkingDirectory()); cmd += this->ConvertToRelativeForMake(wd.c_str());
cmd += " && "; cmd += " && ";
} }
cmd += cmd2; cmd += cmd2;

View File

@ -364,8 +364,8 @@ void cmLocalNinjaGenerator::AppendCustomCommandLines(const cmCustomCommand *cc,
{ {
cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->Makefile); cmCustomCommandGenerator ccg(*cc, this->GetConfigName(), this->Makefile);
if (ccg.GetNumberOfCommands() > 0) { if (ccg.GetNumberOfCommands() > 0) {
const char* wd = cc->GetWorkingDirectory(); std::string wd = cc->GetWorkingDirectory();
if (!wd) if (wd.empty())
wd = this->GetMakefile()->GetStartOutputDirectory(); wd = this->GetMakefile()->GetStartOutputDirectory();
cmOStringStream cdCmd; cmOStringStream cdCmd;
@ -491,7 +491,7 @@ std::string cmLocalNinjaGenerator::MakeCustomLauncher(
if(!outputs.empty()) if(!outputs.empty())
{ {
RelativeRoot relative_root = RelativeRoot relative_root =
cc.GetWorkingDirectory() ? NONE : START_OUTPUT; cc.GetWorkingDirectory().empty() ? START_OUTPUT : NONE;
output = this->Convert(outputs[0], relative_root, SHELL); output = this->Convert(outputs[0], relative_root, SHELL);
} }

View File

@ -1023,9 +1023,9 @@ cmLocalUnixMakefileGenerator3
} }
// if the command specified a working directory use it. // if the command specified a working directory use it.
const char* dir = this->Makefile->GetStartOutputDirectory(); std::string dir = this->Makefile->GetStartOutputDirectory();
const char* workingDir = cc.GetWorkingDirectory(); std::string workingDir = cc.GetWorkingDirectory();
if(workingDir) if(!workingDir.empty())
{ {
dir = workingDir; dir = workingDir;
} }
@ -1066,7 +1066,7 @@ cmLocalUnixMakefileGenerator3
// Convert the command to a relative path only if the current // Convert the command to a relative path only if the current
// working directory will be the start-output directory. // working directory will be the start-output directory.
bool had_slash = cmd.find("/") != cmd.npos; bool had_slash = cmd.find("/") != cmd.npos;
if(!workingDir) if(workingDir.empty())
{ {
cmd = this->Convert(cmd,START_OUTPUT); cmd = this->Convert(cmd,START_OUTPUT);
} }
@ -1079,7 +1079,8 @@ cmLocalUnixMakefileGenerator3
cmd = "./" + cmd; cmd = "./" + cmd;
} }
std::string launcher = std::string launcher =
this->MakeLauncher(cc, target, workingDir? NONE : START_OUTPUT); this->MakeLauncher(cc, target,
workingDir.empty()? START_OUTPUT : NONE);
cmd = launcher + this->ConvertShellCommand(cmd, NONE); cmd = launcher + this->ConvertShellCommand(cmd, NONE);
ccg.AppendArguments(c, cmd); ccg.AppendArguments(c, cmd);
@ -1125,7 +1126,7 @@ cmLocalUnixMakefileGenerator3
} }
// Setup the proper working directory for the commands. // Setup the proper working directory for the commands.
this->CreateCDCommand(commands1, dir, relative); this->CreateCDCommand(commands1, dir.c_str(), relative);
// push back the custom commands // push back the custom commands
commands.insert(commands.end(), commands1.begin(), commands1.end()); commands.insert(commands.end(), commands1.begin(), commands1.end());

View File

@ -583,7 +583,7 @@ cmLocalVisualStudio6Generator
this->Makefile->AddCustomCommandToOutput( this->Makefile->AddCustomCommandToOutput(
output, depends, no_main_dependency, output, depends, no_main_dependency,
origCommand.GetCommandLines(), comment.c_str(), origCommand.GetCommandLines(), comment.c_str(),
origCommand.GetWorkingDirectory())) origCommand.GetWorkingDirectory().c_str()))
{ {
target.AddSourceFile(outsf); target.AddSourceFile(outsf);
} }

View File

@ -84,9 +84,9 @@ cmLocalVisualStudioGenerator
const std::string& newline_text) const std::string& newline_text)
{ {
bool useLocal = this->CustomCommandUseLocal(); bool useLocal = this->CustomCommandUseLocal();
const char* workingDirectory = cc.GetWorkingDirectory(); std::string workingDirectory = cc.GetWorkingDirectory();
cmCustomCommandGenerator ccg(cc, configName, this->Makefile); cmCustomCommandGenerator ccg(cc, configName, this->Makefile);
RelativeRoot relativeRoot = workingDirectory? NONE : START_OUTPUT; RelativeRoot relativeRoot = workingDirectory.empty()? START_OUTPUT : NONE;
// Avoid leading or trailing newlines. // Avoid leading or trailing newlines.
std::string newline = ""; std::string newline = "";
@ -114,7 +114,7 @@ cmLocalVisualStudioGenerator
script += "setlocal"; script += "setlocal";
} }
if(workingDirectory) if(!workingDirectory.empty())
{ {
// Change the working directory. // Change the working directory.
script += newline; script += newline;
@ -124,7 +124,7 @@ cmLocalVisualStudioGenerator
script += check_error; script += check_error;
// Change the working drive. // Change the working drive.
if(workingDirectory[0] && workingDirectory[1] == ':') if(workingDirectory.size() > 1 && workingDirectory[1] == ':')
{ {
script += newline; script += newline;
newline = newline_text; newline = newline_text;