1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
6 #include "cmConfigure.h" // IWYU pragma: keep
17 #include "cmDuration.h"
18 #include "cmProcessOutput.h"
19 #include "cmUVHandlePtr.h"
24 * \brief run a process with c++
26 * cmProcess wraps the kwsys process stuff in a c++ class.
31 explicit cmProcess(cmCTestRunTest& runner);
33 void SetCommand(std::string const& command);
34 void SetCommandArguments(std::vector<std::string> const& arg);
35 void SetWorkingDirectory(std::string const& dir);
36 void SetTimeout(cmDuration t) { this->Timeout = t; }
37 void ChangeTimeout(cmDuration t);
38 void ResetStartTime();
39 // Return true if the process starts
40 bool StartProcess(uv_loop_t& loop, std::vector<size_t>* affinity);
54 State GetProcessStatus();
55 int GetId() { return this->Id; }
56 void SetId(int id) { this->Id = id; }
57 int64_t GetExitValue() { return this->ExitValue; }
58 cmDuration GetTotalTime() { return this->TotalTime; }
70 Exception GetExitException();
71 std::string GetExitExceptionString();
75 std::chrono::steady_clock::time_point StartTime;
77 bool ReadHandleClosed = false;
78 bool ProcessHandleClosed = false;
80 cm::uv_process_ptr Process;
81 cm::uv_pipe_ptr PipeReader;
82 cm::uv_timer_ptr Timer;
83 std::vector<char> Buf;
85 cmCTestRunTest& Runner;
88 cmProcess::State ProcessState = cmProcess::State::Starting;
90 static void OnExitCB(uv_process_t* process, int64_t exit_status,
92 static void OnTimeoutCB(uv_timer_t* timer);
93 static void OnReadCB(uv_stream_t* stream, ssize_t nread,
95 static void OnAllocateCB(uv_handle_t* handle, size_t suggested_size,
98 void OnExit(int64_t exit_status, int term_signal);
100 void OnRead(ssize_t nread, const uv_buf_t* buf);
101 void OnAllocate(size_t suggested_size, uv_buf_t* buf);
106 class Buffer : public std::vector<char>
108 // Half-open index range of partial line already scanned.
118 bool GetLine(std::string& line);
119 bool GetLast(std::string& line);
123 std::string WorkingDirectory;
124 std::vector<std::string> Arguments;
125 std::vector<const char*> ProcessArgs;