CMake Nightly Date Stamp
[kiteware-cmake.git] / Source / cmUVProcessChain.h
blob65816e20846e35bda685ee387abf8096e1d8a994
1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
3 #pragma once
5 #include "cmConfigure.h" // IWYU pragma: keep
7 #include <array>
8 #include <cstddef> // IWYU pragma: keep
9 #include <cstdint>
10 #include <cstdio>
11 #include <memory>
12 #include <string>
13 #include <utility>
14 #include <vector>
16 #include <cm3p/uv.h>
18 class cmUVProcessChain;
20 class cmUVProcessChainBuilder
22 public:
23 enum Stream
25 Stream_INPUT = 0,
26 Stream_OUTPUT = 1,
27 Stream_ERROR = 2,
30 cmUVProcessChainBuilder();
32 cmUVProcessChainBuilder& AddCommand(
33 const std::vector<std::string>& arguments);
34 cmUVProcessChainBuilder& SetBuiltinLoop();
35 cmUVProcessChainBuilder& SetExternalLoop(uv_loop_t& loop);
36 cmUVProcessChainBuilder& SetNoStream(Stream stdio);
37 cmUVProcessChainBuilder& SetBuiltinStream(Stream stdio);
38 cmUVProcessChainBuilder& SetMergedBuiltinStreams();
39 cmUVProcessChainBuilder& SetExternalStream(Stream stdio, int fd);
40 cmUVProcessChainBuilder& SetExternalStream(Stream stdio, FILE* stream);
41 cmUVProcessChainBuilder& SetWorkingDirectory(std::string dir);
43 uv_loop_t* GetLoop() const;
45 cmUVProcessChain Start() const;
47 private:
48 enum StdioType
50 None,
51 Builtin,
52 External,
55 friend class cmUVProcessChain;
57 struct StdioConfiguration
59 StdioType Type = None;
60 int FileDescriptor = -1;
63 struct ProcessConfiguration
65 std::vector<std::string> Arguments;
68 std::array<StdioConfiguration, 3> Stdio;
69 std::vector<ProcessConfiguration> Processes;
70 std::string WorkingDirectory;
71 bool MergedBuiltinStreams = false;
72 uv_loop_t* Loop = nullptr;
75 class cmUVProcessChain
77 public:
78 enum class ExceptionCode
80 None,
81 Fault,
82 Illegal,
83 Interrupt,
84 Numerical,
85 Spawn,
86 Other,
89 struct Status
91 int SpawnResult;
92 bool Finished;
93 int64_t ExitStatus;
94 int TermSignal;
96 std::pair<ExceptionCode, std::string> GetException() const;
99 cmUVProcessChain(const cmUVProcessChain& other) = delete;
100 cmUVProcessChain(cmUVProcessChain&& other) noexcept;
102 ~cmUVProcessChain();
104 cmUVProcessChain& operator=(const cmUVProcessChain& other) = delete;
105 cmUVProcessChain& operator=(cmUVProcessChain&& other) noexcept;
107 uv_loop_t& GetLoop();
109 // FIXME: Add stdin support
110 int OutputStream();
111 int ErrorStream();
113 bool Valid() const;
114 bool Wait(uint64_t milliseconds = 0);
115 std::vector<const Status*> GetStatus() const;
116 const Status& GetStatus(std::size_t index) const;
117 bool Finished() const;
119 private:
120 friend class cmUVProcessChainBuilder;
122 cmUVProcessChain();
124 struct InternalData;
125 std::unique_ptr<InternalData> Data;