/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying file Copyright.txt or https://cmake.org/licensing for details. */ #pragma once #include "cmConfigure.h" // IWYU pragma: keep #include #include // IWYU pragma: keep #include #include #include #include #include #include class cmUVProcessChain; class cmUVProcessChainBuilder { public: enum Stream { Stream_INPUT = 0, Stream_OUTPUT = 1, Stream_ERROR = 2, }; cmUVProcessChainBuilder(); cmUVProcessChainBuilder& AddCommand( const std::vector& arguments); cmUVProcessChainBuilder& SetBuiltinLoop(); cmUVProcessChainBuilder& SetExternalLoop(uv_loop_t& loop); cmUVProcessChainBuilder& SetNoStream(Stream stdio); cmUVProcessChainBuilder& SetBuiltinStream(Stream stdio); cmUVProcessChainBuilder& SetMergedBuiltinStreams(); cmUVProcessChainBuilder& SetExternalStream(Stream stdio, int fd); cmUVProcessChainBuilder& SetWorkingDirectory(std::string dir); uv_loop_t* GetLoop() const; cmUVProcessChain Start() const; private: enum StdioType { None, Builtin, External, }; friend class cmUVProcessChain; struct StdioConfiguration { StdioType Type; int FileDescriptor; }; struct ProcessConfiguration { std::vector Arguments; }; std::array Stdio; std::vector Processes; std::string WorkingDirectory; bool MergedBuiltinStreams = false; uv_loop_t* Loop = nullptr; }; class cmUVProcessChain { public: enum class ExceptionCode { None, Fault, Illegal, Interrupt, Numerical, Spawn, Other, }; struct Status { int SpawnResult; bool Finished; int64_t ExitStatus; int TermSignal; std::pair GetException() const; }; cmUVProcessChain(const cmUVProcessChain& other) = delete; cmUVProcessChain(cmUVProcessChain&& other) noexcept; ~cmUVProcessChain(); cmUVProcessChain& operator=(const cmUVProcessChain& other) = delete; cmUVProcessChain& operator=(cmUVProcessChain&& other) noexcept; uv_loop_t& GetLoop(); // FIXME: Add stdin support int OutputStream(); int ErrorStream(); bool Valid() const; bool Wait(uint64_t milliseconds = 0); std::vector GetStatus() const; const Status& GetStatus(std::size_t index) const; bool Finished() const; private: friend class cmUVProcessChainBuilder; cmUVProcessChain(); struct InternalData; std::unique_ptr Data; };