summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlexey Edelev <alexey.edelev@qt.io>2021-11-24 16:22:18 +0100
committerAlexey Edelev <alexey.edelev@qt.io>2021-12-02 16:34:23 +0100
commit63b8840380e70c1258f56c67a2ec5edb5bdea53d (patch)
tree465fedceda0553c0beec5e5e0f46cd03d1d97abf /tests
parent7a6dd6084cb6dc3d8ad0476d9630ad7c575bca19 (diff)
Fix dependency chain that collects the metatype json files
cmake_automoc_parser has the logic preventing the run of moc with the --collect-json parameter if metatype json files are not changed. This logic only verify if the file list is changed but not their content. This change adds a timestamp file that contains the last metatype json file timestamp that was modified during the last cmake_automoc_parser run. The logic still prevents of running 'moc --collect-json' when the list of metatype json files is not changed, but also checks if their content is no changed. Another approach it to generate the depfile that can be utilized by CMake in add_custom_command as DEPFILE argument. But this concept only works from the second build attempt because of an issue related to dyndep. Pick-to: 6.2 Fixes: QTBUG-98532 Change-Id: I713f8bfa9ae769cefe0beac0b7fa19750b00a765 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/cmake/CMakeLists.txt2
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt106
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/CMakeLists.txt21
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp29
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp32
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/.gitattributes1
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h35
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h36
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h35
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h38
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesEmpty.json2
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECT.json19
-rw-r--r--tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json34
13 files changed, 390 insertions, 0 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt
index dfbbb19828..8073a47c16 100644
--- a/tests/auto/cmake/CMakeLists.txt
+++ b/tests/auto/cmake/CMakeLists.txt
@@ -282,3 +282,5 @@ _qt_internal_test_expect_pass(test_static_resources
BINARY_ARGS "-V")
_qt_internal_test_expect_pass(test_generating_cpp_exports)
+
+_qt_internal_test_expect_pass(test_qt_extract_metatypes)
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt b/tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt
new file mode 100644
index 0000000000..51d78dd833
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/CMakeLists.txt
@@ -0,0 +1,106 @@
+cmake_minimum_required(VERSION 3.16)
+
+project(test_qt_extract_metatypes VERSION 0.1 LANGUAGES CXX)
+
+set(test_project_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/test_qt_extract_metatypes_project")
+set(test_project_build_dir "${CMAKE_CURRENT_BINARY_DIR}/build_qt_extract_metatypes_test_project")
+
+# Make sure that file paths are 'real' paths
+get_filename_component(test_project_source_dir "${test_project_source_dir}" REALPATH)
+get_filename_component(test_project_build_dir "${test_project_build_dir}" REALPATH)
+
+get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
+if (CMAKE_BUILD_TYPE AND NOT is_multi_config)
+ string(TOLOWER "qt6metatypetest_${CMAKE_BUILD_TYPE}" metatypes_file_basename)
+else()
+ string(TOLOWER "qt6metatypetest" metatypes_file_basename)
+endif()
+set(meta_types_file
+ "${test_project_build_dir}/meta_types/${metatypes_file_basename}_metatypes.json")
+
+file(REMOVE_RECURSE "${test_project_build_dir}")
+file(MAKE_DIRECTORY "${test_project_build_dir}")
+
+find_package(Qt6 COMPONENTS Core REQUIRED)
+
+include("${_Qt6CTestMacros}")
+
+macro(try_build)
+ execute_process(COMMAND
+ "${CMAKE_COMMAND}"
+ --build "${test_project_build_dir}"
+ RESULT_VARIABLE result
+ )
+ if(NOT result EQUAL 0)
+ message(FATAL_ERROR "Unable to build test project")
+ endif()
+endmacro()
+
+macro(copy_test_header header)
+ file(COPY "${test_project_source_dir}/testdata/${header}"
+ DESTINATION "${test_project_build_dir}")
+ file(RENAME "${test_project_build_dir}/${header}" "${test_project_build_dir}/MetaType.h")
+ file(TOUCH "${test_project_build_dir}/MetaType.h")
+endmacro()
+
+macro(check_generated_metatypes_file reference expect)
+ set(reference_meta_types_file "${test_project_source_dir}/testdata/${reference}")
+ execute_process(COMMAND
+ "${CMAKE_COMMAND}"
+ -E compare_files "${meta_types_file}" "${reference_meta_types_file}"
+ RESULT_VARIABLE compare_result
+ )
+ if(NOT compare_result EQUAL ${expect})
+ message(FATAL_ERROR "${meta_types_file} and ${reference_meta_types_file} content differs")
+ endif()
+ unset(reference_meta_types_file)
+endmacro()
+
+copy_test_header(MetaTypeQ_OBJECT.h)
+
+_qt_internal_get_cmake_test_configure_options(option_list)
+execute_process(COMMAND
+ "${CMAKE_COMMAND}"
+ "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}"
+ "-G${CMAKE_GENERATOR}"
+ ${option_list}
+ -B "${test_project_build_dir}"
+ -S "${test_project_source_dir}"
+ RESULT_VARIABLE result
+)
+if(NOT result EQUAL 0)
+ message(FATAL_ERROR "Unable to configure test project")
+endif()
+
+try_build()
+check_generated_metatypes_file(qt6metatypetest_metatypesQ_OBJECT.json 0)
+
+copy_test_header(MetaTypeQ_OBJECTandQ_PROPERTY.h)
+try_build()
+check_generated_metatypes_file(qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json 0)
+
+copy_test_header(MetaTypeEmpty.h)
+try_build()
+check_generated_metatypes_file(qt6metatypetest_metatypesEmpty.json 0)
+file(TIMESTAMP "${meta_types_file}" metatypes_timestamp)
+
+copy_test_header(MetaTypeEmptyWithComment.h)
+try_build()
+check_generated_metatypes_file(qt6metatypetest_metatypesEmpty.json 0)
+
+file(TIMESTAMP "${meta_types_file}" new_metatypes_timestamp)
+
+# Depending on the way how qt_extract_metatypes executes automoc it might or might not
+# change the resulting .json file content.
+set(extract_metatypes_uses_dep_files FALSE)
+if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.17") # Requires automoc changes present only in 3.17
+ if(CMAKE_GENERATOR STREQUAL "Ninja" OR CMAKE_GENERATOR STREQUAL "Ninja Multi-Config")
+ set(extract_metatypes_uses_dep_files TRUE)
+ endif()
+endif()
+
+if(extract_metatypes_uses_dep_files)
+ if(NOT metatypes_timestamp STREQUAL new_metatypes_timestamp)
+ message(FATAL_ERROR "${meta_types_file} timestamp is changed but should not")
+ endif()
+endif()
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/CMakeLists.txt b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/CMakeLists.txt
new file mode 100644
index 0000000000..88e51a0ed1
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/CMakeLists.txt
@@ -0,0 +1,21 @@
+cmake_minimum_required(VERSION 3.16)
+
+project(qt_extract_metatypes_test_project VERSION 0.1 LANGUAGES CXX)
+
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+
+find_package(Qt6 COMPONENTS Core REQUIRED)
+
+set(CMAKE_AUTOUIC ON)
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+
+qt_add_executable(MetaTypeTest
+ MetaType.cpp
+ "${CMAKE_CURRENT_BINARY_DIR}/MetaType.h"
+ main.cpp
+)
+target_include_directories(MetaTypeTest PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
+qt_extract_metatypes(MetaTypeTest)
+target_link_libraries(MetaTypeTest PRIVATE Qt6::Core)
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp
new file mode 100644
index 0000000000..1b1d060c6a
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/MetaType.cpp
@@ -0,0 +1,29 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "MetaType.h"
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp
new file mode 100644
index 0000000000..7c8b707b6e
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/main.cpp
@@ -0,0 +1,32 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+int main(int argc, char *argv[])
+{
+ return 0;
+}
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/.gitattributes b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/.gitattributes
new file mode 100644
index 0000000000..8f4efb84e5
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/.gitattributes
@@ -0,0 +1 @@
+*.json text eol=lf
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h
new file mode 100644
index 0000000000..aa76129a06
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmpty.h
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QObject>
+
+class MetaType : public QObject
+{
+};
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h
new file mode 100644
index 0000000000..5135ee098d
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeEmptyWithComment.h
@@ -0,0 +1,36 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QObject>
+
+class MetaType : public QObject
+{
+// Changes of no value to automoc
+};
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h
new file mode 100644
index 0000000000..2fcaf3c1bb
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECT.h
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+#include <QObject>
+
+class MetaType : public QObject
+{
+ Q_OBJECT
+};
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h
new file mode 100644
index 0000000000..680e2a8982
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/MetaTypeQ_OBJECTandQ_PROPERTY.h
@@ -0,0 +1,38 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#pragma once
+
+#include <QObject>
+
+class MetaType : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int test READ test)
+ int test() { return 0; }
+};
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesEmpty.json b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesEmpty.json
new file mode 100644
index 0000000000..0d4f101c7a
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesEmpty.json
@@ -0,0 +1,2 @@
+[
+]
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECT.json b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECT.json
new file mode 100644
index 0000000000..9393eda2df
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECT.json
@@ -0,0 +1,19 @@
+[
+ {
+ "classes": [
+ {
+ "className": "MetaType",
+ "object": true,
+ "qualifiedClassName": "MetaType",
+ "superClasses": [
+ {
+ "access": "public",
+ "name": "QObject"
+ }
+ ]
+ }
+ ],
+ "inputFile": "MetaType.h",
+ "outputRevision": 68
+ }
+]
diff --git a/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json
new file mode 100644
index 0000000000..f6a901952d
--- /dev/null
+++ b/tests/auto/cmake/test_qt_extract_metatypes/test_qt_extract_metatypes_project/testdata/qt6metatypetest_metatypesQ_OBJECTandQ_PROPERTY.json
@@ -0,0 +1,34 @@
+[
+ {
+ "classes": [
+ {
+ "className": "MetaType",
+ "object": true,
+ "properties": [
+ {
+ "constant": false,
+ "designable": true,
+ "final": false,
+ "index": 0,
+ "name": "test",
+ "read": "test",
+ "required": false,
+ "scriptable": true,
+ "stored": true,
+ "type": "int",
+ "user": false
+ }
+ ],
+ "qualifiedClassName": "MetaType",
+ "superClasses": [
+ {
+ "access": "public",
+ "name": "QObject"
+ }
+ ]
+ }
+ ],
+ "inputFile": "MetaType.h",
+ "outputRevision": 68
+ }
+]