From 1307736c7db1ff24e3b8282f4a7b14d24866feba Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 26 Jul 2019 18:15:41 +0200 Subject: [PATCH] Fix testdata handling Make sure to handle glob expressions in the entire path given, not just the end of the path. This handles tests like qsslkey and qnetworkreply. Also copy/install the testdata in the final test directory path under a "testdata" subdir. Previously INSTALL_TESTDIR was used, which was never set to anything. Change-Id: I2408e12f586cadeb524ffa249e851a4179324b23 Reviewed-by: Qt CMake Build Bot Reviewed-by: Simon Hausmann Reviewed-by: Leander Beernaert --- cmake/QtBuild.cmake | 11 ++++++++++- util/cmake/pro2cmake.py | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index ff9109afbe3..d9afbfc0650 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -192,6 +192,11 @@ unset(__config_path_part) # at the QtPostProcess stage. set(QT_BUILD_INTERNALS_EXTRA_CMAKE_CODE "") +# Save the value of the current first project source dir. +# This will be /path/to/qtbase for qtbase both in a super-build and a non super-build. +# This will be /path/to/qtbase/tests when building standalone tests. +set(QT_TOP_LEVEL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + # Functions and macros: # qt_remove_args can remove arguments from an existing list of function @@ -2145,7 +2150,11 @@ function(add_qt_test name) endif() else() # Install test data - qt_path_join(testdata_install_dir ${QT_INSTALL_DIR} "${INSTALL_TESTDIR}/${name}") + file(RELATIVE_PATH relative_path_to_test_project + "${QT_TOP_LEVEL_SOURCE_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}") + qt_path_join(testdata_install_dir ${QT_INSTALL_DIR} + "${relative_path_to_test_project}/testdata") foreach(testdata IN LISTS arg_TESTDATA) set(testdata "${CMAKE_CURRENT_SOURCE_DIR}/${testdata}") if (IS_DIRECTORY "${testdata}") diff --git a/util/cmake/pro2cmake.py b/util/cmake/pro2cmake.py index c505a48e79a..23d459d765a 100755 --- a/util/cmake/pro2cmake.py +++ b/util/cmake/pro2cmake.py @@ -31,6 +31,7 @@ from __future__ import annotations from argparse import ArgumentParser +from textwrap import dedent import copy import xml.etree.ElementTree as ET from itertools import chain @@ -1602,11 +1603,17 @@ def write_main_part(cm_fh: typing.IO[str], name: str, typename: str, has_test_data = True cm_fh.write('# Collect test data\n') for data in test_data: - if data.endswith('*'): - cm_fh.write('{}file(GLOB test_data_glob \n{}LIST_DIRECTORIES' - ' true\n{}RELATIVE ${{CMAKE_CURRENT_SOURCE_DIR}}\n{}"{}")\n'\ - .format(spaces(indent), spaces(indent + 1), \ - spaces(indent + 1), spaces(indent + 1), data)) + if '*' in data: + cm_fh.write(dedent(""" + {indent}file(GLOB test_data_glob + {indent1}LIST_DIRECTORIES true + {indent1}RELATIVE ${{CMAKE_CURRENT_SOURCE_DIR}} + {indent1}"{}") + """).format( + data, + indent=spaces(indent), + indent1=spaces(indent + 1) + )) cm_fh.write('{}list(APPEND test_data ${{test_data_glob}})\n'.format(spaces(indent))) else: cm_fh.write('{}list(APPEND test_data "{}")\n'.format(spaces(indent), data))