From 2119c33b7e7b5fc348c0b4b24e402bcacb18d5db Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Mon, 14 Jan 2019 22:56:19 +1100 Subject: FetchContent: Give access to the terminal for download and update A main scenario where this is needed is when a git operation needs the password to a private key and asks for it on the console. Without this change, such operations can appear to hang indefinitely with no prompt if QUIET is in effect (which it is by default). Another scenario this addresses is when progress of a download or update should be shown. Without this change, all such progress is buffered with some generators and will only be shown at the end, which defeats the purpose of logging any progress to begin with. Relates: #18238 --- Modules/FetchContent.cmake | 7 +++++++ Modules/FetchContent/CMakeLists.cmake.in | 2 ++ Tests/RunCMake/FetchContent/CMakeLists.txt | 4 ++++ Tests/RunCMake/FetchContent/RunCMakeTest.cmake | 1 + .../FetchContent/UsesTerminalOverride-stdout.txt | 2 ++ Tests/RunCMake/FetchContent/UsesTerminalOverride.cmake | 17 +++++++++++++++++ 6 files changed, 33 insertions(+) create mode 100644 Tests/RunCMake/FetchContent/UsesTerminalOverride-stdout.txt create mode 100644 Tests/RunCMake/FetchContent/UsesTerminalOverride.cmake diff --git a/Modules/FetchContent.cmake b/Modules/FetchContent.cmake index 98cdf6c..c65ae9e 100644 --- a/Modules/FetchContent.cmake +++ b/Modules/FetchContent.cmake @@ -691,6 +691,13 @@ function(__FetchContent_directPopulate contentName) BUILD_COMMAND INSTALL_COMMAND TEST_COMMAND + # We force both of these to be ON since we are always executing serially + # and we want all steps to have access to the terminal in case they + # need input from the command line (e.g. ask for a private key password) + # or they want to provide timely progress. We silently absorb and + # discard these if they are set by the caller. + USES_TERMINAL_DOWNLOAD + USES_TERMINAL_UPDATE ) set(multiValueArgs "") diff --git a/Modules/FetchContent/CMakeLists.cmake.in b/Modules/FetchContent/CMakeLists.cmake.in index 9a7a771..0095b11 100644 --- a/Modules/FetchContent/CMakeLists.cmake.in +++ b/Modules/FetchContent/CMakeLists.cmake.in @@ -18,4 +18,6 @@ ExternalProject_Add(${contentName}-populate BUILD_COMMAND "" INSTALL_COMMAND "" TEST_COMMAND "" + USES_TERMINAL_DOWNLOAD YES + USES_TERMINAL_UPDATE YES ) diff --git a/Tests/RunCMake/FetchContent/CMakeLists.txt b/Tests/RunCMake/FetchContent/CMakeLists.txt index d3137f6..3cc2e43 100644 --- a/Tests/RunCMake/FetchContent/CMakeLists.txt +++ b/Tests/RunCMake/FetchContent/CMakeLists.txt @@ -1,3 +1,7 @@ cmake_minimum_required(VERSION 3.9) project(${RunCMake_TEST} NONE) + +# Tests assume no previous downloads in the output directory +file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/_deps) + include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake index 621fb8b..9c1ab66 100644 --- a/Tests/RunCMake/FetchContent/RunCMakeTest.cmake +++ b/Tests/RunCMake/FetchContent/RunCMakeTest.cmake @@ -10,6 +10,7 @@ run_cmake(SameGenerator) run_cmake(VarDefinitions) run_cmake(GetProperties) run_cmake(DirOverrides) +run_cmake(UsesTerminalOverride) # We need to pass through CMAKE_GENERATOR and CMAKE_MAKE_PROGRAM # to ensure the test can run on machines where the build tool diff --git a/Tests/RunCMake/FetchContent/UsesTerminalOverride-stdout.txt b/Tests/RunCMake/FetchContent/UsesTerminalOverride-stdout.txt new file mode 100644 index 0000000..3718d64 --- /dev/null +++ b/Tests/RunCMake/FetchContent/UsesTerminalOverride-stdout.txt @@ -0,0 +1,2 @@ +Logged from t1 download step ++.*Logged from t2 download step diff --git a/Tests/RunCMake/FetchContent/UsesTerminalOverride.cmake b/Tests/RunCMake/FetchContent/UsesTerminalOverride.cmake new file mode 100644 index 0000000..99d9719 --- /dev/null +++ b/Tests/RunCMake/FetchContent/UsesTerminalOverride.cmake @@ -0,0 +1,17 @@ +include(FetchContent) + +set(FETCHCONTENT_QUIET NO) + +FetchContent_Declare( + t1 + DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E echo "Logged from t1 download step" + USES_TERMINAL_DOWNLOAD NO + +) +FetchContent_Populate(t1) + +FetchContent_Populate( + t2 + DOWNLOAD_COMMAND ${CMAKE_COMMAND} -E echo "Logged from t2 download step" + USES_TERMINAL_DOWNLOAD NO +) -- cgit v0.12