diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2023-11-02 14:02:41 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2023-11-02 14:04:00 (GMT) |
commit | c4be9c914b045ceb91a7ac7120fc6c6422944ae5 (patch) | |
tree | 60e05ef7b295f5deea800ce05acf4e6af0c1af43 | |
parent | ae84de5a0c204bbb6ad808f9bae36ef71dcc4ca1 (diff) | |
download | CMake-c4be9c914b045ceb91a7ac7120fc6c6422944ae5.zip CMake-c4be9c914b045ceb91a7ac7120fc6c6422944ae5.tar.gz CMake-c4be9c914b045ceb91a7ac7120fc6c6422944ae5.tar.bz2 |
cmSystemTools::RunSingleCommand(): Pass stdin to child process
Fixes: #25383
-rw-r--r-- | Source/cmSystemTools.cxx | 4 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLine/E_env-stdin-stdout.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLine/E_env-stdin.cmake | 4 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLine/RunCMakeTest.cmake | 1 |
5 files changed, 11 insertions, 2 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index fe421ba..f606c22 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -576,7 +576,9 @@ bool cmSystemTools::RunSingleCommand(std::vector<std::string> const& command, cmDuration timeout, Encoding encoding) { cmUVProcessChainBuilder builder; - builder.AddCommand(command); + builder + .SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT, cm_fileno(stdin)) + .AddCommand(command); if (dir) { builder.SetWorkingDirectory(dir); } diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 4387c5b..2b61fd1 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -827,7 +827,8 @@ endif() add_executable(pseudo_llvm-rc pseudo_llvm-rc.c) add_RunCMake_test(CommandLine -DLLVM_RC=$<TARGET_FILE:pseudo_llvm-rc> -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME} -DCYGWIN=${CYGWIN} -DMSYS=${MSYS} -DPython_EXECUTABLE=${Python_EXECUTABLE} - -DEXIT_CODE_EXE=$<TARGET_FILE:exit_code>) + -DEXIT_CODE_EXE=$<TARGET_FILE:exit_code> + -DPRINT_STDIN_EXE=$<TARGET_FILE:print_stdin>) add_RunCMake_test(CommandLineTar) if(CMAKE_PLATFORM_NO_VERSIONED_SONAME OR (NOT CMAKE_SHARED_LIBRARY_SONAME_FLAG AND NOT CMAKE_SHARED_LIBRARY_SONAME_C_FLAG)) diff --git a/Tests/RunCMake/CommandLine/E_env-stdin-stdout.txt b/Tests/RunCMake/CommandLine/E_env-stdin-stdout.txt new file mode 100644 index 0000000..8210d59 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_env-stdin-stdout.txt @@ -0,0 +1 @@ +^Hello world$ diff --git a/Tests/RunCMake/CommandLine/E_env-stdin.cmake b/Tests/RunCMake/CommandLine/E_env-stdin.cmake new file mode 100644 index 0000000..4ff0ad2 --- /dev/null +++ b/Tests/RunCMake/CommandLine/E_env-stdin.cmake @@ -0,0 +1,4 @@ +execute_process( + COMMAND ${CMAKE_COMMAND} -E echo "Hello world" + COMMAND ${CMAKE_COMMAND} -E env ${PRINT_STDIN_EXE} + ) diff --git a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake index 52be1bb..b29e50a 100644 --- a/Tests/RunCMake/CommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CommandLine/RunCMakeTest.cmake @@ -791,6 +791,7 @@ run_cmake_command(E_env-no-command1 ${CMAKE_COMMAND} -E env TEST_ENV=1) run_cmake_command(E_env-bad-arg1 ${CMAKE_COMMAND} -E env -bad-arg1) run_cmake_command(E_env-set ${CMAKE_COMMAND} -E env TEST_ENV=1 ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_env-set.cmake) run_cmake_command(E_env-unset ${CMAKE_COMMAND} -E env TEST_ENV=1 ${CMAKE_COMMAND} -E env --unset=TEST_ENV ${CMAKE_COMMAND} -P ${RunCMake_SOURCE_DIR}/E_env-unset.cmake) +run_cmake_command(E_env-stdin ${CMAKE_COMMAND} -DPRINT_STDIN_EXE=${PRINT_STDIN_EXE} -P ${RunCMake_SOURCE_DIR}/E_env-stdin.cmake) # To test whether the double dash (--) works for the env command, we need a command that e.g. contains an equals sign (=) # and would normally be interpreted as an NAME=VALUE environment variable. |