mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
ExternalData: add support for suppressing progress during the build
During CI builds (at least), download progress is just noise. Allow it to be suppressed. Default to `OFF` for Ninja due to the tool's behavior of not showing output until a command is complete (which makes any progress reporting of little use) and `ON` otherwise.
This commit is contained in:
6
Help/release/dev/ExternalData-suppress-progress.rst
Normal file
6
Help/release/dev/ExternalData-suppress-progress.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
ExternalData-suppress-progress
|
||||
------------------------------
|
||||
|
||||
* The :module:`ExternalData` module ``ExternalData_add_target`` now supports a
|
||||
``SHOW_PROGRESS <bool>`` argument to suppress progress output during the
|
||||
build.
|
@@ -78,7 +78,8 @@ Module Functions
|
||||
manage local instances of data files stored externally::
|
||||
|
||||
ExternalData_Add_Target(
|
||||
<target> # Name of data management target
|
||||
<target> # Name of data management target
|
||||
[SHOW_PROGRESS <ON|OFF>] # Show progress during the download
|
||||
)
|
||||
|
||||
It creates custom commands in the target as necessary to make data
|
||||
@@ -89,6 +90,11 @@ Module Functions
|
||||
in one of the paths specified in the ``ExternalData_OBJECT_STORES``
|
||||
variable.
|
||||
|
||||
The ``SHOW_PROGRESS`` argument may be passed to suppress progress information
|
||||
during the download of objects. If not provided, it defaults to ``OFF`` for
|
||||
:generator:`Ninja` and :generator:`Ninja Multi-Config` generators and ``ON``
|
||||
otherwise.
|
||||
|
||||
Typically only one target is needed to manage all external data within
|
||||
a project. Call this function once at the end of configuration after
|
||||
all data references have been processed.
|
||||
@@ -344,6 +350,30 @@ function(ExternalData_add_target target)
|
||||
endif()
|
||||
set(_ExternalData_CONFIG_CODE "")
|
||||
|
||||
cmake_parse_arguments(PARSE_ARGV 1 _ExternalData_add_target
|
||||
""
|
||||
"SHOW_PROGRESS"
|
||||
"")
|
||||
if (_ExternalData_add_target_UNPARSED_ARGUMENTS)
|
||||
message(AUTHOR_WARNING
|
||||
"Ignoring unrecognized arguments passed to ExternalData_add_target: "
|
||||
"`${_ExternalData_add_target_UNPARSED_ARGUMENTS}`")
|
||||
endif ()
|
||||
|
||||
# Turn `SHOW_PROGRESS` into a boolean
|
||||
if (NOT DEFINED _ExternalData_add_target_SHOW_PROGRESS)
|
||||
# The default setting
|
||||
if (CMAKE_GENERATOR MATCHES "Ninja")
|
||||
set(_ExternalData_add_target_SHOW_PROGRESS OFF)
|
||||
else ()
|
||||
set(_ExternalData_add_target_SHOW_PROGRESS ON)
|
||||
endif ()
|
||||
elseif (_ExternalData_add_target_SHOW_PROGRESS)
|
||||
set(_ExternalData_add_target_SHOW_PROGRESS ON)
|
||||
else ()
|
||||
set(_ExternalData_add_target_SHOW_PROGRESS OFF)
|
||||
endif ()
|
||||
|
||||
# Store custom script configuration.
|
||||
foreach(url_template IN LISTS ExternalData_URL_TEMPLATES)
|
||||
if("${url_template}" MATCHES "^ExternalDataCustomScript://([^/]*)/(.*)$")
|
||||
@@ -423,6 +453,7 @@ function(ExternalData_add_target target)
|
||||
COMMAND ${CMAKE_COMMAND} -Drelative_top=${CMAKE_BINARY_DIR}
|
||||
-Dfile=${file} -Dname=${name}
|
||||
-DExternalData_ACTION=local
|
||||
-DExternalData_SHOW_PROGRESS=${_ExternalData_add_target_SHOW_PROGRESS}
|
||||
-DExternalData_CONFIG=${config}
|
||||
-P ${_ExternalData_SELF}
|
||||
MAIN_DEPENDENCY "${name}"
|
||||
@@ -459,6 +490,7 @@ function(ExternalData_add_target target)
|
||||
COMMAND ${CMAKE_COMMAND} -Drelative_top=${CMAKE_BINARY_DIR}
|
||||
-Dfile=${file} -Dname=${name} -Dexts=${exts}
|
||||
-DExternalData_ACTION=fetch
|
||||
-DExternalData_SHOW_PROGRESS=${_ExternalData_add_target_SHOW_PROGRESS}
|
||||
-DExternalData_CONFIG=${config}
|
||||
-P ${_ExternalData_SELF}
|
||||
# Update whenever the object hash changes.
|
||||
@@ -925,7 +957,11 @@ function(_ExternalData_download_file url file err_var msg_var)
|
||||
else()
|
||||
set(absolute_timeout "")
|
||||
endif()
|
||||
file(DOWNLOAD "${url}" "${file}" STATUS status LOG log ${inactivity_timeout} ${absolute_timeout} SHOW_PROGRESS)
|
||||
set(show_progress_args)
|
||||
if (ExternalData_SHOW_PROGRESS)
|
||||
list(APPEND show_progress_args SHOW_PROGRESS)
|
||||
endif ()
|
||||
file(DOWNLOAD "${url}" "${file}" STATUS status LOG log ${inactivity_timeout} ${absolute_timeout} ${show_progress_args})
|
||||
list(GET status 0 err)
|
||||
list(GET status 1 msg)
|
||||
if(err)
|
||||
|
7
Tests/RunCMake/ExternalData/BadArguments-stderr.txt
Normal file
7
Tests/RunCMake/ExternalData/BadArguments-stderr.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
CMake Warning \(dev\) at .*/Modules/ExternalData.cmake:[0-9]+ \(message\):
|
||||
Ignoring unrecognized arguments passed to ExternalData_add_target:
|
||||
`UNKNOWN_ARGUMENT`
|
||||
Call Stack \(most recent call first\):
|
||||
BadArguments.cmake:[0-9]+ \(ExternalData_Add_Target\)
|
||||
CMakeLists.txt:[0-9]+ \(include\)
|
||||
This warning is for project developers. Use -Wno-dev to suppress it.
|
5
Tests/RunCMake/ExternalData/BadArguments.cmake
Normal file
5
Tests/RunCMake/ExternalData/BadArguments.cmake
Normal file
@@ -0,0 +1,5 @@
|
||||
include(ExternalData)
|
||||
set(ExternalData_URL_TEMPLATES
|
||||
"file:///path/to/%(algo)/%(hash)"
|
||||
)
|
||||
ExternalData_Add_Target(Data UNKNOWN_ARGUMENT)
|
@@ -2,6 +2,7 @@ include(RunCMake)
|
||||
|
||||
run_cmake(BadAlgoMap1)
|
||||
run_cmake(BadAlgoMap2)
|
||||
run_cmake(BadArguments)
|
||||
run_cmake(BadCustom1)
|
||||
run_cmake(BadCustom2)
|
||||
run_cmake(BadCustom3)
|
||||
|
Reference in New Issue
Block a user