MCPcopy Create free account
hub / github.com/Kitware/CMake / ExecuteScript

Method ExecuteScript

Source/CTest/cmCTestScriptHandler.cxx:75–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg)
76{
77 // execute the script passing in the arguments to the script as well as the
78 // arguments from this invocation of cmake
79 std::vector<std::string> argv;
80 argv.push_back(cmSystemTools::GetCTestCommand());
81 argv.push_back("-SR");
82 argv.push_back(total_script_arg);
83
84 cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
85 "Executable for CTest is: " << cmSystemTools::GetCTestCommand()
86 << "\n");
87
88 // now pass through all the other arguments
89 std::vector<std::string>& initArgs =
90 this->CTest->GetInitialCommandLineArguments();
91 //*** need to make sure this does not have the current script ***
92 for (size_t i = 1; i < initArgs.size(); ++i) {
93 // in a nested subprocess, skip the parent's `-SR <path>` arguments.
94 if (initArgs[i] == "-SR") {
95 i++; // <path>
96 } else {
97 argv.push_back(initArgs[i]);
98 }
99 }
100
101 // Now create process object
102 cmUVProcessChainBuilder builder;
103 builder.AddCommand(argv)
104 .SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT)
105 .SetBuiltinStream(cmUVProcessChainBuilder::Stream_ERROR);
106 auto process = builder.Start();
107
108 std::vector<char> out;
109 std::vector<char> err;
110 std::string line;
111 cmSystemTools::WaitForLineResult pipe;
112 while ((pipe = cmSystemTools::WaitForLine(
113 &process.GetLoop(), process.OutputStream(), process.ErrorStream(),
114 line, out, err)) != cmSystemTools::WaitForLineResult::None) {
115 cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
116 "Output: " << line << "\n");
117 if (pipe == cmSystemTools::WaitForLineResult::STDERR) {
118 cmCTestLog(this->CTest, ERROR_MESSAGE, line << "\n");
119 } else if (pipe == cmSystemTools::WaitForLineResult::STDOUT) {
120 cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, line << "\n");
121 }
122 }
123
124 // Properly handle output of the build command
125 process.Wait();
126 auto const& status = process.GetStatus(0);
127 auto result = status.GetException();
128 int retVal = 0;
129 bool failed = false;
130 switch (result.first) {
131 case cmUVProcessChain::ExceptionCode::None:
132 retVal = static_cast<int>(status.ExitStatus);

Callers 1

Calls 11

push_backMethod · 0.80
GetLoopMethod · 0.80
OutputStreamMethod · 0.80
ErrorStreamMethod · 0.80
GetStatusMethod · 0.80
GetExceptionMethod · 0.80
strMethod · 0.80
sizeMethod · 0.45
AddCommandMethod · 0.45
StartMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected