diff options
author | Gabor Bencze <b.gabor98@gmail.com> | 2019-07-25 15:31:39 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-08-20 18:42:19 (GMT) |
commit | 3e5eb45ec1fd977b709da6e36966b0b13d185214 (patch) | |
tree | ea0dbaf79cf4b964ba1cda005850fe16e269853c /Source | |
parent | 0d87f5d83e52ceb72f754331a9fd3d7189680297 (diff) | |
download | CMake-3e5eb45ec1fd977b709da6e36966b0b13d185214.zip CMake-3e5eb45ec1fd977b709da6e36966b0b13d185214.tar.gz CMake-3e5eb45ec1fd977b709da6e36966b0b13d185214.tar.bz2 |
cmCommand refactor: cmExecuteProcessCommand
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCommands.cxx | 3 | ||||
-rw-r--r-- | Source/cmExecuteProcessCommand.cxx | 78 | ||||
-rw-r--r-- | Source/cmExecuteProcessCommand.h | 26 |
3 files changed, 46 insertions, 61 deletions
diff --git a/Source/cmCommands.cxx b/Source/cmCommands.cxx index 0f73293..ea9bddb 100644 --- a/Source/cmCommands.cxx +++ b/Source/cmCommands.cxx @@ -123,8 +123,7 @@ void GetScriptingCommands(cmState* state) state->AddBuiltinCommand("configure_file", cmConfigureFileCommand); state->AddBuiltinCommand("continue", cmContinueCommand); state->AddBuiltinCommand("exec_program", cmExecProgramCommand); - state->AddBuiltinCommand("execute_process", - cm::make_unique<cmExecuteProcessCommand>()); + state->AddBuiltinCommand("execute_process", cmExecuteProcessCommand); state->AddBuiltinCommand("file", cmFileCommand); state->AddBuiltinCommand("find_file", cm::make_unique<cmFindFileCommand>()); state->AddBuiltinCommand("find_library", diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index 465f4b3..acf2a83 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -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); } +} diff --git a/Source/cmExecuteProcessCommand.h b/Source/cmExecuteProcessCommand.h index 1d5445f..9c4b600 100644 --- a/Source/cmExecuteProcessCommand.h +++ b/Source/cmExecuteProcessCommand.h @@ -8,35 +8,15 @@ #include <string> #include <vector> -#include "cm_memory.hxx" - -#include "cmCommand.h" - class cmExecutionStatus; -/** \class cmExecuteProcessCommand +/** * \brief Command that adds a target to the build system. * * cmExecuteProcessCommand is a CMake language interface to the KWSys * Process Execution implementation. */ -class cmExecuteProcessCommand : public cmCommand -{ -public: - /** - * This is a virtual constructor for the command. - */ - std::unique_ptr<cmCommand> Clone() override - { - return cm::make_unique<cmExecuteProcessCommand>(); - } - - /** - * This is called when the command is first encountered in - * the CMakeLists.txt file. - */ - bool InitialPass(std::vector<std::string> const& args, - cmExecutionStatus& status) override; -}; +bool cmExecuteProcessCommand(std::vector<std::string> const& args, + cmExecutionStatus& status); #endif |