diff options
author | Brad King <brad.king@kitware.com> | 2024-01-25 15:39:50 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2024-01-25 15:40:02 (GMT) |
commit | b11c8c45f977a4d69bc5a056341b57e17a602694 (patch) | |
tree | 42f545e8385bb1da68b7799a1fc35e0ebd48377c /Source | |
parent | 4c4cd1246e5b66f731c6e145332ed75bf24fd045 (diff) | |
parent | adb3e13d323aeb19c3824112cfa712cc122db3b4 (diff) | |
download | CMake-b11c8c45f977a4d69bc5a056341b57e17a602694.zip CMake-b11c8c45f977a4d69bc5a056341b57e17a602694.tar.gz CMake-b11c8c45f977a4d69bc5a056341b57e17a602694.tar.bz2 |
Merge topic 'cmuvprocesschain'
adb3e13d32 cmUVProcessChain: Tolerate fileno() of invalid FILE stream
b6e4e4babc cmUVProcessChain: Simplify SetExternalStream usage
116bb2b70f cmUVProcessChain: Simplify builder initialization
d32c30906a Tests: Add missing include in testUVProcessChainHelper on Windows
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9181
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CTest/cmCTestCoverageHandler.cxx | 6 | ||||
-rw-r--r-- | Source/CTest/cmCTestLaunch.cxx | 9 | ||||
-rw-r--r-- | Source/cmExecuteProcessCommand.cxx | 13 | ||||
-rw-r--r-- | Source/cmSystemTools.cxx | 12 | ||||
-rw-r--r-- | Source/cmUVProcessChain.cxx | 19 | ||||
-rw-r--r-- | Source/cmUVProcessChain.h | 6 | ||||
-rw-r--r-- | Source/cmake.cxx | 7 | ||||
-rw-r--r-- | Source/cmcmd.cxx | 9 |
8 files changed, 33 insertions, 48 deletions
diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index 1aa49cf..f9f9add 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -21,8 +21,6 @@ #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" -#include "cm_fileno.hxx" - #include "cmCTest.h" #include "cmDuration.h" #include "cmGeneratedFileStream.h" @@ -1887,9 +1885,9 @@ int cmCTestCoverageHandler::RunBullseyeCommand( cmsys::SystemTools::Fopen(stderrFile, "w"), fclose); builder.AddCommand(args) .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, - cm_fileno(stdoutHandle.get())) + stdoutHandle.get()) .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, - cm_fileno(stderrHandle.get())); + stderrHandle.get()); // since we set the output file names wait for it to end auto chain = builder.Start(); chain.Wait(); diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 6b13ad1..9669d76 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -13,8 +13,6 @@ #include "cmsys/FStream.hxx" #include "cmsys/RegularExpression.hxx" -#include "cm_fileno.hxx" - #include "cmCTestLaunchReporter.h" #include "cmGlobalGenerator.h" #include "cmMakefile.h" @@ -158,11 +156,8 @@ void cmCTestLaunch::RunChild() cmsys::ofstream ferr; if (this->Reporter.Passthru) { // In passthru mode we just share the output pipes. - builder - .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, - cm_fileno(stdout)) - .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, - cm_fileno(stderr)); + builder.SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, stdout) + .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, stderr); } else { // In full mode we record the child output pipes to log files. builder.SetBuiltinStream(cmUVProcessChainBuilder::Stream_OUTPUT) diff --git a/Source/cmExecuteProcessCommand.cxx b/Source/cmExecuteProcessCommand.cxx index da6def9..2b923df 100644 --- a/Source/cmExecuteProcessCommand.cxx +++ b/Source/cmExecuteProcessCommand.cxx @@ -17,8 +17,6 @@ #include <cm3p/uv.h> -#include "cm_fileno.hxx" - #include "cmArgumentParser.h" #include "cmExecutionStatus.h" #include "cmList.h" @@ -183,11 +181,10 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args, inputFile.reset(cmsys::SystemTools::Fopen(inputFilename, "rb")); if (inputFile) { builder.SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT, - cm_fileno(inputFile.get())); + inputFile.get()); } } else { - builder.SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT, - cm_fileno(stdin)); + builder.SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT, stdin); } std::unique_ptr<FILE, int (*)(FILE*)> outputFile(nullptr, fclose); @@ -195,7 +192,7 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args, outputFile.reset(cmsys::SystemTools::Fopen(outputFilename, "wb")); if (outputFile) { builder.SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, - cm_fileno(outputFile.get())); + outputFile.get()); } } else { if (arguments.OutputVariable == arguments.ErrorVariable && @@ -211,13 +208,13 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args, if (errorFilename == outputFilename) { if (outputFile) { builder.SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, - cm_fileno(outputFile.get())); + outputFile.get()); } } else { errorFile.reset(cmsys::SystemTools::Fopen(errorFilename, "wb")); if (errorFile) { builder.SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, - cm_fileno(errorFile.get())); + errorFile.get()); } } } else if (arguments.ErrorVariable.empty() || diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index fca8186..bd914e5 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -25,8 +25,6 @@ #include <cm3p/uv.h> -#include "cm_fileno.hxx" - #include "cmDuration.h" #include "cmELF.h" #include "cmMessageMetadata.h" @@ -576,8 +574,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command, cmDuration timeout, Encoding encoding) { cmUVProcessChainBuilder builder; - builder - .SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT, cm_fileno(stdin)) + builder.SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT, stdin) .AddCommand(command); if (dir) { builder.SetWorkingDirectory(dir); @@ -586,11 +583,8 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command, if (outputflag == OUTPUT_PASSTHROUGH) { captureStdOut = nullptr; captureStdErr = nullptr; - builder - .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, - cm_fileno(stdout)) - .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, - cm_fileno(stderr)); + builder.SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, stdout) + .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, stderr); } else if (outputflag == OUTPUT_MERGE || (captureStdErr && captureStdErr == captureStdOut)) { builder.SetMergedBuiltinStreams(); diff --git a/Source/cmUVProcessChain.cxx b/Source/cmUVProcessChain.cxx index 4c72261..0412f45 100644 --- a/Source/cmUVProcessChain.cxx +++ b/Source/cmUVProcessChain.cxx @@ -12,6 +12,8 @@ #include <cm3p/uv.h> +#include "cm_fileno.hxx" + #include "cmGetPipes.h" #include "cmUVHandlePtr.h" @@ -58,12 +60,7 @@ struct cmUVProcessChain::InternalData void Finish(); }; -cmUVProcessChainBuilder::cmUVProcessChainBuilder() -{ - this->SetNoStream(Stream_INPUT) - .SetNoStream(Stream_OUTPUT) - .SetNoStream(Stream_ERROR); -} +cmUVProcessChainBuilder::cmUVProcessChainBuilder() = default; cmUVProcessChainBuilder& cmUVProcessChainBuilder::AddCommand( const std::vector<std::string>& arguments) @@ -136,6 +133,16 @@ cmUVProcessChainBuilder& cmUVProcessChainBuilder::SetExternalStream( return *this; } +cmUVProcessChainBuilder& cmUVProcessChainBuilder::SetExternalStream( + Stream stdio, FILE* stream) +{ + int fd = cm_fileno(stream); + if (fd >= 0) { + return this->SetExternalStream(stdio, fd); + } + return this->SetNoStream(stdio); +} + cmUVProcessChainBuilder& cmUVProcessChainBuilder::SetMergedBuiltinStreams() { this->MergedBuiltinStreams = true; diff --git a/Source/cmUVProcessChain.h b/Source/cmUVProcessChain.h index 139588b..65816e2 100644 --- a/Source/cmUVProcessChain.h +++ b/Source/cmUVProcessChain.h @@ -7,6 +7,7 @@ #include <array> #include <cstddef> // IWYU pragma: keep #include <cstdint> +#include <cstdio> #include <memory> #include <string> #include <utility> @@ -36,6 +37,7 @@ public: cmUVProcessChainBuilder& SetBuiltinStream(Stream stdio); cmUVProcessChainBuilder& SetMergedBuiltinStreams(); cmUVProcessChainBuilder& SetExternalStream(Stream stdio, int fd); + cmUVProcessChainBuilder& SetExternalStream(Stream stdio, FILE* stream); cmUVProcessChainBuilder& SetWorkingDirectory(std::string dir); uv_loop_t* GetLoop() const; @@ -54,8 +56,8 @@ private: struct StdioConfiguration { - StdioType Type; - int FileDescriptor; + StdioType Type = None; + int FileDescriptor = -1; }; struct ProcessConfiguration diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 7ab7600..88fac8d 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -27,7 +27,6 @@ #include "cmsys/Glob.hxx" #include "cmsys/RegularExpression.hxx" -#include "cm_fileno.hxx" #include "cm_sys_stat.h" #include "cmBuildOptions.h" @@ -3934,10 +3933,8 @@ std::function<int()> cmake::BuildWorkflowStep( { cmUVProcessChainBuilder builder; builder.AddCommand(args) - .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, - cm_fileno(stdout)) - .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, - cm_fileno(stderr)); + .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, stdout) + .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, stderr); return [builder]() -> int { auto chain = builder.Start(); chain.Wait(); diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index bcf7462..25b2ced 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -11,8 +11,6 @@ #include <cm3p/uv.h> #include <fcntl.h> -#include "cm_fileno.hxx" - #include "cmCommandLineArgument.h" #include "cmConsoleBuf.h" #include "cmCryptoHash.h" @@ -1917,11 +1915,8 @@ int cmcmd::ExecuteLinkScript(std::vector<std::string> const& args) cmUVProcessChainBuilder builder; // Children should share stdout and stderr with this process. - builder - .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, - cm_fileno(stdout)) - .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, - cm_fileno(stderr)); + builder.SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, stdout) + .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, stderr); // Setup this command line. std::vector<std::string> args2; |