Do not error out on missing optional repository dependencies

Read the 'required' value from dependencies.yaml and store all required
dependencies of repository 'qtfoo' in a global property
QT_REQUIRED_DEPS_FOR_qtfoo.

Check this property in the top-level CMakeLists.txt and only print
informational messages instead of errors for optional dependencies.

Fixes: QTBUG-91144
Change-Id: I0e1b84a70221857cebba1b9a27456ad3667bfe3a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann
2021-03-12 14:53:23 +01:00
parent 174a511460
commit 81096b44bb
2 changed files with 52 additions and 21 deletions

View File

@@ -49,20 +49,35 @@ qt_internal_sort_module_dependencies("${BUILD_SUBMODULES}" BUILD_SUBMODULES
foreach(module IN LISTS BUILD_SUBMODULES) foreach(module IN LISTS BUILD_SUBMODULES)
# Check for unmet dependencies # Check for unmet dependencies
if(NOT DEFINED BUILD_${module} OR BUILD_${module}) if(NOT DEFINED BUILD_${module} OR BUILD_${module})
message(NOTICE "Check dependencies of '${module}'") message(NOTICE "Checking dependencies of '${module}'")
get_property(required_deps GLOBAL PROPERTY QT_REQUIRED_DEPS_FOR_${module})
foreach(dep IN LISTS "${qt_module_dependency_map_prefix}${module}") foreach(dep IN LISTS "${qt_module_dependency_map_prefix}${module}")
if (dep STREQUAL "qtbase") if (dep STREQUAL "qtbase")
# Always available skip # Always available skip
continue() continue()
endif() endif()
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dep}/CMakeLists.txt")
message(FATAL_ERROR "Module '${module}' depends on '${dep}', but ${dep}'s \ set(required FALSE)
CMakeLists.txt couldn't be found.\nNote: Use '-skip ${module}' to exclude it \ if(dep IN_LIST required_deps)
from build.\n") set(required TRUE)
endif() endif()
if(DEFINED BUILD_${dep} AND NOT BUILD_${dep})
message(FATAL_ERROR "Module '${module}' depends on '${dep}', but '${dep}' \ set(error_reason "")
will not be built.\nNote: Use '-skip ${module}' to exclude it from build.\n") if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${dep}/CMakeLists.txt")
set(error_reason "${dep}'s CMakeLists.txt couldn't be found")
elseif(DEFINED BUILD_${dep} AND NOT BUILD_${dep})
set(error_reason "building '${dep}' was explicitly disabled")
endif()
if(NOT error_reason STREQUAL "")
if(required)
message(FATAL_ERROR "Module '${module}' depends on '${dep}', "
"but ${error_reason}.\n"
"Note: Use '-skip ${module}' to exclude it from the build.")
else()
message(NOTICE "Skipping optional dependency '${dep}' of '${module}', "
"because ${error_reason}.")
endif()
endif() endif()
endforeach() endforeach()
endif() endif()

View File

@@ -17,24 +17,34 @@ endfunction()
# Each entry will be in the format dependency/sha1 # Each entry will be in the format dependency/sha1
function(qt_internal_parse_dependencies depends_file out_dependencies) function(qt_internal_parse_dependencies depends_file out_dependencies)
file(STRINGS "${depends_file}" lines) file(STRINGS "${depends_file}" lines)
set(eof_marker "---EOF---")
list(APPEND lines "${eof_marker}")
set(required_default TRUE)
set(dependencies "") set(dependencies "")
set(dependency "") set(dependency "")
set(revision "")
set(required "${required_default}")
foreach(line IN LISTS lines) foreach(line IN LISTS lines)
if(line STREQUAL "dependencies:") if(line MATCHES "^ (.+):$" OR line STREQUAL "${eof_marker}")
set(found_dependencies 1) # Found a repo entry or end of file. Add the last seen dependency.
elseif(found_dependencies) if(NOT dependency STREQUAL "")
if(line MATCHES "^ ref: (.*)$") if(revision STREQUAL "")
set(revision "${CMAKE_MATCH_1}")
list(APPEND dependencies ${dependency}/${revision})
set(dependency "")
elseif (line MATCHES "^ (.*):$")
if(dependency)
message(FATAL_ERROR "Format error in ${depends_file} - ${dependency} does not specify revision!") message(FATAL_ERROR "Format error in ${depends_file} - ${dependency} does not specify revision!")
endif() endif()
list(APPEND dependencies "${dependency}/${revision}/${required}")
endif()
# Remember the current dependency
if(NOT line STREQUAL "${eof_marker}")
set(dependency "${CMAKE_MATCH_1}") set(dependency "${CMAKE_MATCH_1}")
set(revision "")
set(required "${required_default}")
# dependencies are specified with relative path to this module # dependencies are specified with relative path to this module
string(REPLACE "../" "" dependency ${dependency}) string(REPLACE "../" "" dependency ${dependency})
endif() endif()
elseif(line MATCHES "^ ref: (.+)$")
set(revision "${CMAKE_MATCH_1}")
elseif(line MATCHES "^ required: (.+)$")
string(TOUPPER "${CMAKE_MATCH_1}" required)
endif() endif()
endforeach() endforeach()
message(DEBUG "qt_internal_parse_dependencies for ${depends_file}: ${dependencies} ${revisions}") message(DEBUG "qt_internal_parse_dependencies for ${depends_file}: ${dependencies} ${revisions}")
@@ -66,10 +76,16 @@ function(qt_internal_add_module_dependencies module ordered out_ordered out_has_
endif() endif()
set(modules_dependencies "") set(modules_dependencies "")
foreach(dependency IN LISTS dependencies) foreach(dependency IN LISTS dependencies)
string(FIND "${dependency}" "/" splitindex REVERSE) if(dependency MATCHES "(.*)/([^/]+)/([^/]+)")
string(SUBSTRING "${dependency}" ${splitindex} -1 revision) set(dependency "${CMAKE_MATCH_1}")
string(SUBSTRING "${revision}" 1 -1 revision) set(revision "${CMAKE_MATCH_2}")
string(SUBSTRING "${dependency}" 0 ${splitindex} dependency) set(required "${CMAKE_MATCH_3}")
if(required)
set_property(GLOBAL APPEND PROPERTY QT_REQUIRED_DEPS_FOR_${module} ${dependency})
endif()
else()
message(FATAL_ERROR "Internal Error: wrong dependency format ${dependency}")
endif()
list(APPEND modules_dependencies "${dependency}") list(APPEND modules_dependencies "${dependency}")
list(FIND ordered "${dependency}" dindex) list(FIND ordered "${dependency}" dindex)
if (dindex EQUAL -1) if (dindex EQUAL -1)