2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2006-02-03 21:51:46 +00:00
|
|
|
#include "cmExecuteProcessCommand.h"
|
2016-04-29 13:40:20 +00:00
|
|
|
|
2006-02-03 21:51:46 +00:00
|
|
|
#include <cmsys/Process.h>
|
2006-10-16 15:32:28 +00:00
|
|
|
#include <ctype.h> /* isspace */
|
2016-10-25 18:35:04 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "cmMakefile.h"
|
2016-11-01 18:29:17 +00:00
|
|
|
#include "cmProcessOutput.h"
|
2016-10-25 18:35:04 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
|
|
|
|
class cmExecutionStatus;
|
2006-10-16 15:32:28 +00:00
|
|
|
|
|
|
|
static bool cmExecuteProcessCommandIsWhitespace(char c)
|
|
|
|
{
|
|
|
|
return (isspace((int)c) || c == '\n' || c == '\r');
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExecuteProcessCommandFixText(std::vector<char>& output,
|
|
|
|
bool strip_trailing_whitespace);
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmExecuteProcessCommandAppend(std::vector<char>& output, const char* data,
|
|
|
|
int length);
|
2006-02-10 16:46:34 +00:00
|
|
|
|
2006-02-03 21:51:46 +00:00
|
|
|
// cmExecuteProcessCommand
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmExecuteProcessCommand::InitialPass(std::vector<std::string> const& args,
|
|
|
|
cmExecutionStatus&)
|
2006-02-03 21:51:46 +00:00
|
|
|
{
|
2016-09-15 21:59:29 +00:00
|
|
|
if (args.empty()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError("called with incorrect number of arguments");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
std::vector<std::vector<const char*> > cmds;
|
2006-02-03 21:51:46 +00:00
|
|
|
std::string arguments;
|
|
|
|
bool doing_command = false;
|
2006-03-30 18:49:56 +00:00
|
|
|
size_t command_index = 0;
|
2006-02-03 21:51:46 +00:00
|
|
|
bool output_quiet = false;
|
|
|
|
bool error_quiet = false;
|
2006-10-16 15:32:28 +00:00
|
|
|
bool output_strip_trailing_whitespace = false;
|
|
|
|
bool error_strip_trailing_whitespace = false;
|
2006-02-03 21:51:46 +00:00
|
|
|
std::string timeout_string;
|
|
|
|
std::string input_file;
|
|
|
|
std::string output_file;
|
|
|
|
std::string error_file;
|
|
|
|
std::string output_variable;
|
|
|
|
std::string error_variable;
|
|
|
|
std::string result_variable;
|
|
|
|
std::string working_directory;
|
2016-11-23 12:11:40 +00:00
|
|
|
cmProcessOutput::Encoding encoding = cmProcessOutput::Auto;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (size_t i = 0; i < args.size(); ++i) {
|
|
|
|
if (args[i] == "COMMAND") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = true;
|
|
|
|
command_index = cmds.size();
|
|
|
|
cmds.push_back(std::vector<const char*>());
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "OUTPUT_VARIABLE") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (++i < args.size()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
output_variable = args[i];
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with no value for OUTPUT_VARIABLE.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "ERROR_VARIABLE") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (++i < args.size()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
error_variable = args[i];
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with no value for ERROR_VARIABLE.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "RESULT_VARIABLE") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (++i < args.size()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
result_variable = args[i];
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with no value for RESULT_VARIABLE.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "WORKING_DIRECTORY") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (++i < args.size()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
working_directory = args[i];
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with no value for WORKING_DIRECTORY.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "INPUT_FILE") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (++i < args.size()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
input_file = args[i];
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with no value for INPUT_FILE.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "OUTPUT_FILE") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (++i < args.size()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
output_file = args[i];
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with no value for OUTPUT_FILE.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "ERROR_FILE") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (++i < args.size()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
error_file = args[i];
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with no value for ERROR_FILE.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "TIMEOUT") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (++i < args.size()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
timeout_string = args[i];
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with no value for TIMEOUT.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "OUTPUT_QUIET") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
|
|
|
output_quiet = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "ERROR_QUIET") {
|
2006-02-03 21:51:46 +00:00
|
|
|
doing_command = false;
|
|
|
|
error_quiet = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "OUTPUT_STRIP_TRAILING_WHITESPACE") {
|
2006-10-16 15:32:28 +00:00
|
|
|
doing_command = false;
|
|
|
|
output_strip_trailing_whitespace = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (args[i] == "ERROR_STRIP_TRAILING_WHITESPACE") {
|
2006-10-16 15:32:28 +00:00
|
|
|
doing_command = false;
|
|
|
|
error_strip_trailing_whitespace = true;
|
2016-11-23 12:11:40 +00:00
|
|
|
} else if (args[i] == "ENCODING") {
|
|
|
|
doing_command = false;
|
|
|
|
if (++i < args.size()) {
|
|
|
|
encoding = cmProcessOutput::FindEncoding(args[i]);
|
|
|
|
} else {
|
|
|
|
this->SetError(" called with no value for ENCODING.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (doing_command) {
|
2006-02-03 21:51:46 +00:00
|
|
|
cmds[command_index].push_back(args[i].c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-01-05 19:31:31 +00:00
|
|
|
std::ostringstream e;
|
2006-10-16 15:32:28 +00:00
|
|
|
e << " given unknown argument \"" << args[i] << "\".";
|
2014-03-10 23:04:11 +00:00
|
|
|
this->SetError(e.str());
|
2006-10-16 15:32:28 +00:00
|
|
|
return false;
|
2006-02-03 21:51:46 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!this->Makefile->CanIWriteThisFile(output_file.c_str())) {
|
|
|
|
std::string e = "attempted to output into a file: " + output_file +
|
|
|
|
" into a source directory.";
|
2014-03-10 23:04:11 +00:00
|
|
|
this->SetError(e);
|
2006-03-22 19:40:36 +00:00
|
|
|
cmSystemTools::SetFatalErrorOccured();
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-03-22 19:40:36 +00:00
|
|
|
|
2006-02-03 21:51:46 +00:00
|
|
|
// Check for commands given.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (cmds.empty()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with no COMMAND argument.");
|
|
|
|
return false;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
for (unsigned int i = 0; i < cmds.size(); ++i) {
|
|
|
|
if (cmds[i].empty()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" given COMMAND argument with no value.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-16 20:45:24 +00:00
|
|
|
// Add the null terminating pointer to the command argument list.
|
|
|
|
cmds[i].push_back(CM_NULLPTR);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
|
|
|
// Parse the timeout string.
|
|
|
|
double timeout = -1;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!timeout_string.empty()) {
|
|
|
|
if (sscanf(timeout_string.c_str(), "%lg", &timeout) != 1) {
|
2006-02-03 21:51:46 +00:00
|
|
|
this->SetError(" called with TIMEOUT value that could not be parsed.");
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
|
|
|
// Create a process instance.
|
|
|
|
cmsysProcess* cp = cmsysProcess_New();
|
|
|
|
|
|
|
|
// Set the command sequence.
|
2016-05-16 14:34:04 +00:00
|
|
|
for (unsigned int i = 0; i < cmds.size(); ++i) {
|
2006-02-03 21:51:46 +00:00
|
|
|
cmsysProcess_AddCommand(cp, &*cmds[i].begin());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
|
|
|
// Set the process working directory.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!working_directory.empty()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
cmsysProcess_SetWorkingDirectory(cp, working_directory.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
|
|
|
// Always hide the process window.
|
|
|
|
cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1);
|
|
|
|
|
|
|
|
// Check the output variables.
|
2015-05-07 18:40:38 +00:00
|
|
|
bool merge_output = false;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!input_file.empty()) {
|
2006-02-03 21:51:46 +00:00
|
|
|
cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDIN, input_file.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!output_file.empty()) {
|
2012-08-13 17:42:58 +00:00
|
|
|
cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDOUT,
|
2006-05-10 19:08:38 +00:00
|
|
|
output_file.c_str());
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!error_file.empty()) {
|
|
|
|
if (error_file == output_file) {
|
2015-05-07 18:40:38 +00:00
|
|
|
merge_output = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-05-07 18:40:38 +00:00
|
|
|
cmsysProcess_SetPipeFile(cp, cmsysProcess_Pipe_STDERR,
|
|
|
|
error_file.c_str());
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (!output_variable.empty() && output_variable == error_variable) {
|
2015-05-07 18:40:38 +00:00
|
|
|
merge_output = true;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
|
|
|
if (merge_output) {
|
2015-05-07 18:40:38 +00:00
|
|
|
cmsysProcess_SetOption(cp, cmsysProcess_Option_MergeOutput, 1);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
|
|
|
// Set the timeout if any.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (timeout >= 0) {
|
2006-02-03 21:51:46 +00:00
|
|
|
cmsysProcess_SetTimeout(cp, timeout);
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
|
|
|
// Start the process.
|
|
|
|
cmsysProcess_Execute(cp);
|
|
|
|
|
|
|
|
// Read the process output.
|
|
|
|
std::vector<char> tempOutput;
|
|
|
|
std::vector<char> tempError;
|
|
|
|
int length;
|
|
|
|
char* data;
|
|
|
|
int p;
|
2016-11-23 12:11:40 +00:00
|
|
|
cmProcessOutput processOutput(encoding);
|
2016-11-01 18:29:17 +00:00
|
|
|
std::string strdata;
|
2016-06-27 20:44:16 +00:00
|
|
|
while ((p = cmsysProcess_WaitForData(cp, &data, &length, CM_NULLPTR), p)) {
|
2006-02-03 21:51:46 +00:00
|
|
|
// Put the output in the right place.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (p == cmsysProcess_Pipe_STDOUT && !output_quiet) {
|
|
|
|
if (output_variable.empty()) {
|
2016-11-01 18:29:17 +00:00
|
|
|
processOutput.DecodeText(data, length, strdata, 1);
|
|
|
|
cmSystemTools::Stdout(strdata.c_str(), strdata.size());
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2007-10-15 21:38:10 +00:00
|
|
|
cmExecuteProcessCommandAppend(tempOutput, data, length);
|
2006-02-03 21:51:46 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
} else if (p == cmsysProcess_Pipe_STDERR && !error_quiet) {
|
|
|
|
if (error_variable.empty()) {
|
2016-11-01 18:29:17 +00:00
|
|
|
processOutput.DecodeText(data, length, strdata, 2);
|
|
|
|
cmSystemTools::Stderr(strdata.c_str(), strdata.size());
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2007-10-15 21:38:10 +00:00
|
|
|
cmExecuteProcessCommandAppend(tempError, data, length);
|
2006-02-03 21:51:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2016-11-01 18:29:17 +00:00
|
|
|
if (!output_quiet && output_variable.empty()) {
|
|
|
|
processOutput.DecodeText(std::string(), strdata, 1);
|
|
|
|
if (!strdata.empty()) {
|
|
|
|
cmSystemTools::Stdout(strdata.c_str(), strdata.size());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!error_quiet && error_variable.empty()) {
|
|
|
|
processOutput.DecodeText(std::string(), strdata, 2);
|
|
|
|
if (!strdata.empty()) {
|
|
|
|
cmSystemTools::Stderr(strdata.c_str(), strdata.size());
|
|
|
|
}
|
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
|
|
|
// All output has been read. Wait for the process to exit.
|
2016-06-27 20:44:16 +00:00
|
|
|
cmsysProcess_WaitForExit(cp, CM_NULLPTR);
|
2016-11-01 18:29:17 +00:00
|
|
|
processOutput.DecodeText(tempOutput, tempOutput);
|
|
|
|
processOutput.DecodeText(tempError, tempError);
|
2006-02-03 21:51:46 +00:00
|
|
|
|
2006-02-10 16:46:34 +00:00
|
|
|
// Fix the text in the output strings.
|
2016-05-16 14:34:04 +00:00
|
|
|
cmExecuteProcessCommandFixText(tempOutput, output_strip_trailing_whitespace);
|
|
|
|
cmExecuteProcessCommandFixText(tempError, error_strip_trailing_whitespace);
|
2006-02-10 16:46:34 +00:00
|
|
|
|
2006-02-03 21:51:46 +00:00
|
|
|
// Store the output obtained.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!output_variable.empty() && !tempOutput.empty()) {
|
|
|
|
this->Makefile->AddDefinition(output_variable, &*tempOutput.begin());
|
|
|
|
}
|
|
|
|
if (!merge_output && !error_variable.empty() && !tempError.empty()) {
|
|
|
|
this->Makefile->AddDefinition(error_variable, &*tempError.begin());
|
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
|
|
|
// Store the result of running the process.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!result_variable.empty()) {
|
|
|
|
switch (cmsysProcess_GetState(cp)) {
|
|
|
|
case cmsysProcess_State_Exited: {
|
2006-02-03 21:51:46 +00:00
|
|
|
int v = cmsysProcess_GetExitValue(cp);
|
|
|
|
char buf[100];
|
|
|
|
sprintf(buf, "%d", v);
|
2014-03-10 23:04:11 +00:00
|
|
|
this->Makefile->AddDefinition(result_variable, buf);
|
2016-05-16 14:34:04 +00:00
|
|
|
} break;
|
2006-02-03 21:51:46 +00:00
|
|
|
case cmsysProcess_State_Exception:
|
2014-03-10 23:04:11 +00:00
|
|
|
this->Makefile->AddDefinition(result_variable,
|
2016-05-16 14:34:04 +00:00
|
|
|
cmsysProcess_GetExceptionString(cp));
|
2006-02-03 21:51:46 +00:00
|
|
|
break;
|
|
|
|
case cmsysProcess_State_Error:
|
2014-03-10 23:04:11 +00:00
|
|
|
this->Makefile->AddDefinition(result_variable,
|
2016-05-16 14:34:04 +00:00
|
|
|
cmsysProcess_GetErrorString(cp));
|
2006-02-03 21:51:46 +00:00
|
|
|
break;
|
|
|
|
case cmsysProcess_State_Expired:
|
2014-03-10 23:04:11 +00:00
|
|
|
this->Makefile->AddDefinition(result_variable,
|
2016-05-16 14:34:04 +00:00
|
|
|
"Process terminated due to timeout");
|
2006-02-03 21:51:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-02-03 21:51:46 +00:00
|
|
|
|
|
|
|
// Delete the process instance.
|
|
|
|
cmsysProcess_Delete(cp);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2006-02-10 16:46:34 +00:00
|
|
|
|
2006-10-16 15:32:28 +00:00
|
|
|
void cmExecuteProcessCommandFixText(std::vector<char>& output,
|
|
|
|
bool strip_trailing_whitespace)
|
2006-02-10 16:46:34 +00:00
|
|
|
{
|
|
|
|
// Remove \0 characters and the \r part of \r\n pairs.
|
|
|
|
unsigned int in_index = 0;
|
|
|
|
unsigned int out_index = 0;
|
2016-05-16 14:34:04 +00:00
|
|
|
while (in_index < output.size()) {
|
2006-02-10 16:46:34 +00:00
|
|
|
char c = output[in_index++];
|
2016-05-16 14:34:04 +00:00
|
|
|
if ((c != '\r' ||
|
|
|
|
!(in_index < output.size() && output[in_index] == '\n')) &&
|
|
|
|
c != '\0') {
|
2006-02-10 16:46:34 +00:00
|
|
|
output[out_index++] = c;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-10-16 15:32:28 +00:00
|
|
|
|
|
|
|
// Remove trailing whitespace if requested.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (strip_trailing_whitespace) {
|
|
|
|
while (out_index > 0 &&
|
|
|
|
cmExecuteProcessCommandIsWhitespace(output[out_index - 1])) {
|
2006-10-16 15:32:28 +00:00
|
|
|
--out_index;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2006-10-16 15:32:28 +00:00
|
|
|
|
|
|
|
// Shrink the vector to the size needed.
|
2006-02-10 16:46:34 +00:00
|
|
|
output.resize(out_index);
|
|
|
|
|
|
|
|
// Put a terminator on the text string.
|
|
|
|
output.push_back('\0');
|
|
|
|
}
|
2007-10-15 21:38:10 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmExecuteProcessCommandAppend(std::vector<char>& output, const char* data,
|
|
|
|
int length)
|
2007-10-15 21:38:10 +00:00
|
|
|
{
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
// HACK on Apple to work around bug with inserting at the
|
|
|
|
// end of an empty vector. This resulted in random failures
|
|
|
|
// that were hard to reproduce.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (output.empty() && length > 0) {
|
2007-10-15 21:38:10 +00:00
|
|
|
output.push_back(data[0]);
|
|
|
|
++data;
|
|
|
|
--length;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2007-10-15 21:38:10 +00:00
|
|
|
#endif
|
2016-05-16 14:34:04 +00:00
|
|
|
output.insert(output.end(), data, data + length);
|
2007-10-15 21:38:10 +00:00
|
|
|
}
|