|
@@ -8,20 +8,21 @@
|
|
|
#include <algorithm>
|
|
|
#include <ctype.h> /* isspace */
|
|
|
#include <iostream>
|
|
|
+#include <memory>
|
|
|
#include <stdio.h>
|
|
|
#include <vector>
|
|
|
|
|
|
#include "cmAlgorithms.h"
|
|
|
#include "cmArgumentParser.h"
|
|
|
+#include "cmExecutionStatus.h"
|
|
|
#include "cmMakefile.h"
|
|
|
#include "cmMessageType.h"
|
|
|
#include "cmProcessOutput.h"
|
|
|
#include "cmStringAlgorithms.h"
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
-class cmExecutionStatus;
|
|
|
-
|
|
|
-static bool cmExecuteProcessCommandIsWhitespace(char c)
|
|
|
+namespace {
|
|
|
+bool cmExecuteProcessCommandIsWhitespace(char c)
|
|
|
{
|
|
|
return (isspace(static_cast<int>(c)) || c == '\n' || c == '\r');
|
|
|
}
|
|
@@ -30,13 +31,14 @@ void cmExecuteProcessCommandFixText(std::vector<char>& output,
|
|
|
bool strip_trailing_whitespace);
|
|
|
void cmExecuteProcessCommandAppend(std::vector<char>& output, const char* data,
|
|
|
int length);
|
|
|
+}
|
|
|
|
|
|
// cmExecuteProcessCommand
|
|
|
-bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
- cmExecutionStatus&)
|
|
|
+bool cmExecuteProcessCommand(std::vector<std::string> const& args,
|
|
|
+ cmExecutionStatus& status)
|
|
|
{
|
|
|
if (args.empty()) {
|
|
|
- this->SetError("called with incorrect number of arguments");
|
|
|
+ status.SetError("called with incorrect number of arguments");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -87,31 +89,31 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
parser.Parse(args, &unparsedArguments, &keywordsMissingValue);
|
|
|
|
|
|
if (!keywordsMissingValue.empty()) {
|
|
|
- this->SetError(" called with no value for " +
|
|
|
- keywordsMissingValue.front() + ".");
|
|
|
+ status.SetError(" called with no value for " +
|
|
|
+ keywordsMissingValue.front() + ".");
|
|
|
return false;
|
|
|
}
|
|
|
if (!unparsedArguments.empty()) {
|
|
|
- this->SetError(" given unknown argument \"" + unparsedArguments.front() +
|
|
|
- "\".");
|
|
|
+ status.SetError(" given unknown argument \"" + unparsedArguments.front() +
|
|
|
+ "\".");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- if (!this->Makefile->CanIWriteThisFile(arguments.OutputFile)) {
|
|
|
- this->SetError("attempted to output into a file: " + arguments.OutputFile +
|
|
|
- " into a source directory.");
|
|
|
+ if (!status.GetMakefile().CanIWriteThisFile(arguments.OutputFile)) {
|
|
|
+ status.SetError("attempted to output into a file: " +
|
|
|
+ arguments.OutputFile + " into a source directory.");
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// Check for commands given.
|
|
|
if (arguments.Commands.empty()) {
|
|
|
- this->SetError(" called with no COMMAND argument.");
|
|
|
+ status.SetError(" called with no COMMAND argument.");
|
|
|
return false;
|
|
|
}
|
|
|
for (std::vector<std::string> const& cmd : arguments.Commands) {
|
|
|
if (cmd.empty()) {
|
|
|
- this->SetError(" given COMMAND argument with no value.");
|
|
|
+ status.SetError(" given COMMAND argument with no value.");
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -120,7 +122,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
double timeout = -1;
|
|
|
if (!arguments.Timeout.empty()) {
|
|
|
if (sscanf(arguments.Timeout.c_str(), "%lg", &timeout) != 1) {
|
|
|
- this->SetError(" called with TIMEOUT value that could not be parsed.");
|
|
|
+ status.SetError(" called with TIMEOUT value that could not be parsed.");
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -180,8 +182,8 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
bool echo_stdout = false;
|
|
|
bool echo_stderr = false;
|
|
|
bool echo_output_from_variable = true;
|
|
|
- std::string echo_output =
|
|
|
- this->Makefile->GetSafeDefinition("CMAKE_EXECUTE_PROCESS_COMMAND_ECHO");
|
|
|
+ std::string echo_output = status.GetMakefile().GetSafeDefinition(
|
|
|
+ "CMAKE_EXECUTE_PROCESS_COMMAND_ECHO");
|
|
|
if (!arguments.CommandEcho.empty()) {
|
|
|
echo_output_from_variable = false;
|
|
|
echo_output = arguments.CommandEcho;
|
|
@@ -204,7 +206,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
if (!echo_output_from_variable) {
|
|
|
error += " for COMMAND_ECHO.";
|
|
|
}
|
|
|
- this->Makefile->IssueMessage(MessageType::FATAL_ERROR, error);
|
|
|
+ status.GetMakefile().IssueMessage(MessageType::FATAL_ERROR, error);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
@@ -278,11 +280,13 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
|
|
// Store the output obtained.
|
|
|
if (!arguments.OutputVariable.empty() && !tempOutput.empty()) {
|
|
|
- this->Makefile->AddDefinition(arguments.OutputVariable, tempOutput.data());
|
|
|
+ status.GetMakefile().AddDefinition(arguments.OutputVariable,
|
|
|
+ tempOutput.data());
|
|
|
}
|
|
|
if (!merge_output && !arguments.ErrorVariable.empty() &&
|
|
|
!tempError.empty()) {
|
|
|
- this->Makefile->AddDefinition(arguments.ErrorVariable, tempError.data());
|
|
|
+ status.GetMakefile().AddDefinition(arguments.ErrorVariable,
|
|
|
+ tempError.data());
|
|
|
}
|
|
|
|
|
|
// Store the result of running the process.
|
|
@@ -292,19 +296,19 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
int v = cmsysProcess_GetExitValue(cp);
|
|
|
char buf[16];
|
|
|
sprintf(buf, "%d", v);
|
|
|
- this->Makefile->AddDefinition(arguments.ResultVariable, buf);
|
|
|
+ status.GetMakefile().AddDefinition(arguments.ResultVariable, buf);
|
|
|
} break;
|
|
|
case cmsysProcess_State_Exception:
|
|
|
- this->Makefile->AddDefinition(arguments.ResultVariable,
|
|
|
- cmsysProcess_GetExceptionString(cp));
|
|
|
+ status.GetMakefile().AddDefinition(
|
|
|
+ arguments.ResultVariable, cmsysProcess_GetExceptionString(cp));
|
|
|
break;
|
|
|
case cmsysProcess_State_Error:
|
|
|
- this->Makefile->AddDefinition(arguments.ResultVariable,
|
|
|
- cmsysProcess_GetErrorString(cp));
|
|
|
+ status.GetMakefile().AddDefinition(arguments.ResultVariable,
|
|
|
+ cmsysProcess_GetErrorString(cp));
|
|
|
break;
|
|
|
case cmsysProcess_State_Expired:
|
|
|
- this->Makefile->AddDefinition(arguments.ResultVariable,
|
|
|
- "Process terminated due to timeout");
|
|
|
+ status.GetMakefile().AddDefinition(
|
|
|
+ arguments.ResultVariable, "Process terminated due to timeout");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -332,20 +336,20 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- this->Makefile->AddDefinition(arguments.ResultsVariable,
|
|
|
- cmJoin(res, ";"));
|
|
|
+ status.GetMakefile().AddDefinition(arguments.ResultsVariable,
|
|
|
+ cmJoin(res, ";"));
|
|
|
} break;
|
|
|
case cmsysProcess_State_Exception:
|
|
|
- this->Makefile->AddDefinition(arguments.ResultsVariable,
|
|
|
- cmsysProcess_GetExceptionString(cp));
|
|
|
+ status.GetMakefile().AddDefinition(
|
|
|
+ arguments.ResultsVariable, cmsysProcess_GetExceptionString(cp));
|
|
|
break;
|
|
|
case cmsysProcess_State_Error:
|
|
|
- this->Makefile->AddDefinition(arguments.ResultsVariable,
|
|
|
- cmsysProcess_GetErrorString(cp));
|
|
|
+ status.GetMakefile().AddDefinition(arguments.ResultsVariable,
|
|
|
+ cmsysProcess_GetErrorString(cp));
|
|
|
break;
|
|
|
case cmsysProcess_State_Expired:
|
|
|
- this->Makefile->AddDefinition(arguments.ResultsVariable,
|
|
|
- "Process terminated due to timeout");
|
|
|
+ status.GetMakefile().AddDefinition(
|
|
|
+ arguments.ResultsVariable, "Process terminated due to timeout");
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -353,6 +357,7 @@ bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+namespace {
|
|
|
void cmExecuteProcessCommandFixText(std::vector<char>& output,
|
|
|
bool strip_trailing_whitespace)
|
|
|
{
|
|
@@ -398,3 +403,4 @@ void cmExecuteProcessCommandAppend(std::vector<char>& output, const char* data,
|
|
|
#endif
|
|
|
cmAppend(output, data, data + length);
|
|
|
}
|
|
|
+}
|