diff options
Diffstat (limited to 'util/cmake/tests')
-rw-r--r-- | util/cmake/tests/data/condition_operator_precedence.pro | 11 | ||||
-rw-r--r-- | util/cmake/tests/data/conversion/optional_qt_modules.pro | 4 | ||||
-rw-r--r-- | util/cmake/tests/data/conversion/qt_version_check.pro | 8 | ||||
-rw-r--r-- | util/cmake/tests/data/conversion/required_qt_modules.pro | 3 | ||||
-rw-r--r-- | util/cmake/tests/data/standardpaths.pro | 2 | ||||
-rwxr-xr-x | util/cmake/tests/test_conversion.py | 66 | ||||
-rwxr-xr-x | util/cmake/tests/test_lc_fixup.py | 29 | ||||
-rwxr-xr-x | util/cmake/tests/test_logic_mapping.py | 32 | ||||
-rwxr-xr-x | util/cmake/tests/test_operations.py | 29 | ||||
-rwxr-xr-x | util/cmake/tests/test_parsing.py | 47 | ||||
-rwxr-xr-x | util/cmake/tests/test_scope_handling.py | 44 |
11 files changed, 126 insertions, 149 deletions
diff --git a/util/cmake/tests/data/condition_operator_precedence.pro b/util/cmake/tests/data/condition_operator_precedence.pro new file mode 100644 index 0000000000..8af628404d --- /dev/null +++ b/util/cmake/tests/data/condition_operator_precedence.pro @@ -0,0 +1,11 @@ +a1|a2 { + DEFINES += d +} + +b1|b2:b3 { + DEFINES += d +} + +c1|c2:c3|c4 { + DEFINES += d +} diff --git a/util/cmake/tests/data/conversion/optional_qt_modules.pro b/util/cmake/tests/data/conversion/optional_qt_modules.pro new file mode 100644 index 0000000000..b9522169fc --- /dev/null +++ b/util/cmake/tests/data/conversion/optional_qt_modules.pro @@ -0,0 +1,4 @@ +TARGET = myapp +QT = core network widgets +win32: QT += opengl +SOURCES = main.cpp diff --git a/util/cmake/tests/data/conversion/qt_version_check.pro b/util/cmake/tests/data/conversion/qt_version_check.pro new file mode 100644 index 0000000000..cf3697bb64 --- /dev/null +++ b/util/cmake/tests/data/conversion/qt_version_check.pro @@ -0,0 +1,8 @@ +QT += core gui +SOURCES += main.cpp +greaterThan(QT_MAJOR_VERSION, 5):lessThan(QT_MINOR_VERSION, 1):equals(QT_PATCH_VERSION, 0) { + DEFINES += SUPER_FRESH_MAJOR_QT_RELEASE +} +greaterThan(QT_VERSION, 6.6.5):lessThan(QT_VERSION, 6.6.7):equals(QT_VERSION, 6.6.6): { + DEFINES += QT_VERSION_OF_THE_BEAST +} diff --git a/util/cmake/tests/data/conversion/required_qt_modules.pro b/util/cmake/tests/data/conversion/required_qt_modules.pro new file mode 100644 index 0000000000..287bb46831 --- /dev/null +++ b/util/cmake/tests/data/conversion/required_qt_modules.pro @@ -0,0 +1,3 @@ +TARGET = myapp +QT = core network widgets +SOURCES = main.cpp diff --git a/util/cmake/tests/data/standardpaths.pro b/util/cmake/tests/data/standardpaths.pro index 4b45788e4f..b9896b8e29 100644 --- a/util/cmake/tests/data/standardpaths.pro +++ b/util/cmake/tests/data/standardpaths.pro @@ -7,7 +7,7 @@ win32 { } else:unix { mac { OBJECTIVE_SOURCES += io/qstandardpaths_mac.mm - } else:android:!android-embedded { + } else:android { SOURCES += io/qstandardpaths_android.cpp } else:haiku { SOURCES += io/qstandardpaths_haiku.cpp diff --git a/util/cmake/tests/test_conversion.py b/util/cmake/tests/test_conversion.py new file mode 100755 index 0000000000..0cdfb51976 --- /dev/null +++ b/util/cmake/tests/test_conversion.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +from pro2cmake import Scope, SetOperation, merge_scopes, recursive_evaluate_scope +from tempfile import TemporaryDirectory + +import os +import pathlib +import pytest +import re +import shutil +import subprocess +import tempfile +import typing + +debug_mode = bool(os.environ.get("DEBUG_PRO2CMAKE_TEST_CONVERSION")) +test_script_dir = pathlib.Path(__file__).parent.resolve() +pro2cmake_dir = test_script_dir.parent.resolve() +pro2cmake_py = pro2cmake_dir.joinpath("pro2cmake.py") +test_data_dir = test_script_dir.joinpath("data", "conversion") + + +def convert(base_name: str): + pro_file_name = str(base_name) + ".pro" + pro_file_path = test_data_dir.joinpath(pro_file_name) + assert(pro_file_path.exists()) + with TemporaryDirectory(prefix="testqmake2cmake") as tmp_dir_str: + tmp_dir = pathlib.Path(tmp_dir_str) + output_file_path = tmp_dir.joinpath("CMakeLists.txt") + exit_code = subprocess.call([pro2cmake_py, "--is-example", "-o", output_file_path, pro_file_path]) + assert(exit_code == 0) + if debug_mode: + shutil.copyfile(output_file_path, tempfile.gettempdir() + "/pro2cmake/CMakeLists.txt") + f = open(output_file_path, "r") + assert(f) + content = f.read() + assert(content) + return content + + +def test_qt_modules(): + output = convert("required_qt_modules") + find_package_lines = [] + for line in output.split("\n"): + if "find_package(" in line: + find_package_lines.append(line.strip()) + assert(["find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)", + "find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network Widgets)"] == find_package_lines) + + output = convert("optional_qt_modules") + find_package_lines = [] + for line in output.split("\n"): + if "find_package(" in line: + find_package_lines.append(line.strip()) + assert(["find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core)", + "find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Network Widgets)", + "find_package(Qt${QT_VERSION_MAJOR} OPTIONAL_COMPONENTS OpenGL)"] == find_package_lines) + +def test_qt_version_check(): + output = convert("qt_version_check") + interesting_lines = [] + for line in output.split("\n"): + if line.startswith("if(") and "QT_VERSION" in line: + interesting_lines.append(line.strip()) + assert(["if(( ( (QT_VERSION_MAJOR GREATER 5) ) AND (QT_VERSION_MINOR LESS 1) ) AND (QT_VERSION_PATCH EQUAL 0))", "if(( ( (QT_VERSION VERSION_GREATER 6.6.5) ) AND (QT_VERSION VERSION_LESS 6.6.7) ) AND (QT_VERSION VERSION_EQUAL 6.6.6))"] == interesting_lines) diff --git a/util/cmake/tests/test_lc_fixup.py b/util/cmake/tests/test_lc_fixup.py index 42094a5288..aa63e02fe1 100755 --- a/util/cmake/tests/test_lc_fixup.py +++ b/util/cmake/tests/test_lc_fixup.py @@ -1,31 +1,6 @@ #!/usr/bin/env python3 -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the plugins 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$ -## -############################################################################# +# Copyright (C) 2018 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 from qmake_parser import fixup_linecontinuation diff --git a/util/cmake/tests/test_logic_mapping.py b/util/cmake/tests/test_logic_mapping.py index 6e4fd20590..cc7d5a3636 100755 --- a/util/cmake/tests/test_logic_mapping.py +++ b/util/cmake/tests/test_logic_mapping.py @@ -1,31 +1,6 @@ #!/usr/bin/env python3 -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the plugins 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$ -## -############################################################################# +# Copyright (C) 2018 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 from condition_simplifier import simplify_condition @@ -182,5 +157,4 @@ def test_simplify_complex_false(): def test_simplify_android_not_apple(): - validate_simplify('ANDROID AND NOT ANDROID_EMBEDDED AND NOT MACOS', - 'ANDROID AND NOT ANDROID_EMBEDDED') + validate_simplify('ANDROID AND NOT MACOS', 'ANDROID') diff --git a/util/cmake/tests/test_operations.py b/util/cmake/tests/test_operations.py index c1e5f1b250..95f894dae4 100755 --- a/util/cmake/tests/test_operations.py +++ b/util/cmake/tests/test_operations.py @@ -1,31 +1,6 @@ #!/usr/bin/env python3 -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the plugins 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$ -## -############################################################################# +# Copyright (C) 2018 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 from pro2cmake import AddOperation, SetOperation, UniqueAddOperation, RemoveOperation diff --git a/util/cmake/tests/test_parsing.py b/util/cmake/tests/test_parsing.py index 9acee46007..ceda348f53 100755 --- a/util/cmake/tests/test_parsing.py +++ b/util/cmake/tests/test_parsing.py @@ -1,34 +1,11 @@ #!/usr/bin/env python3 -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the plugins 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$ -## -############################################################################# +# Copyright (C) 2018 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 import os +from pro2cmake import map_condition from qmake_parser import QmakeParser +from condition_simplifier import simplify_condition _tests_path = os.path.dirname(os.path.abspath(__file__)) @@ -239,7 +216,7 @@ def test_realworld_standardpaths(): # android / else: (cond4, if_branch4, else_branch4) = evaluate_condition(else_branch3[0]) - assert cond4 == 'android && !android-embedded' + assert cond4 == 'android' assert len(if_branch4) == 1 validate_op('SOURCES', '+=', ['io/qstandardpaths_android.cpp'], if_branch4[0]) assert len(else_branch4) == 1 @@ -259,7 +236,7 @@ def test_realworld_comment_scope(): (cond, if_branch, else_branch) = evaluate_condition(result[0]) assert cond == 'freebsd|openbsd' assert len(if_branch) == 1 - validate_op('QMAKE_LFLAGS_NOUNDEF', '=', None, if_branch[0]) + validate_op('QMAKE_LFLAGS_NOUNDEF', '=', [], if_branch[0]) assert 'included' in result[1] assert result[1]['included'].get('value', '') == 'animation/animation.pri' @@ -352,3 +329,15 @@ def test_value_function(): assert target == 'Dummy' value = result[1]['value'] assert value[0] == '$$TARGET' + + +def test_condition_operator_precedence(): + result = parse_file(_tests_path + '/data/condition_operator_precedence.pro') + + def validate_simplify(input_str: str, expected: str) -> None: + output = simplify_condition(map_condition(input_str)) + assert output == expected + + validate_simplify(result[0]["condition"], "a1 OR a2") + validate_simplify(result[1]["condition"], "b3 AND (b1 OR b2)") + validate_simplify(result[2]["condition"], "c4 OR (c1 AND c3) OR (c2 AND c3)") diff --git a/util/cmake/tests/test_scope_handling.py b/util/cmake/tests/test_scope_handling.py index 51e569fb09..b36c5d5bcd 100755 --- a/util/cmake/tests/test_scope_handling.py +++ b/util/cmake/tests/test_scope_handling.py @@ -1,31 +1,6 @@ #!/usr/bin/env python3 -############################################################################# -## -## Copyright (C) 2018 The Qt Company Ltd. -## Contact: https://www.qt.io/licensing/ -## -## This file is part of the plugins 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$ -## -############################################################################# +# Copyright (C) 2021 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 from pro2cmake import Scope, SetOperation, merge_scopes, recursive_evaluate_scope @@ -306,12 +281,10 @@ def test_qstandardpaths_scopes(): # mac { # OBJECTIVE_SOURCES += io/qstandardpaths_mac.mm scope7 = _new_scope(parent_scope=scope6, condition='MACOS', SOURCES='qsp_mac.mm') - # } else:android:!android-embedded { + # } else:android { # SOURCES += io/qstandardpaths_android.cpp scope8 = _new_scope(parent_scope=scope6, condition='else') - scope9 = _new_scope(parent_scope=scope8, - condition='ANDROID AND NOT ANDROID_EMBEDDED', - SOURCES='qsp_android.cpp') + scope9 = _new_scope(parent_scope=scope8, condition='ANDROID AND NOT UNKNOWN_PLATFORM', SOURCES='qsp_android.cpp') # } else:haiku { # SOURCES += io/qstandardpaths_haiku.cpp scope10 = _new_scope(parent_scope=scope8, condition='else') @@ -332,10 +305,10 @@ def test_qstandardpaths_scopes(): assert scope6.total_condition == 'UNIX' assert scope7.total_condition == 'MACOS' assert scope8.total_condition == 'UNIX AND NOT MACOS' - assert scope9.total_condition == 'ANDROID AND NOT ANDROID_EMBEDDED' - assert scope10.total_condition == 'UNIX AND NOT MACOS AND (ANDROID_EMBEDDED OR NOT ANDROID)' - assert scope11.total_condition == 'HAIKU AND (ANDROID_EMBEDDED OR NOT ANDROID)' - assert scope12.total_condition == 'UNIX AND NOT MACOS AND NOT HAIKU AND (ANDROID_EMBEDDED OR NOT ANDROID)' + assert scope9.total_condition == 'ANDROID AND NOT UNKNOWN_PLATFORM' + assert scope10.total_condition == 'UNIX AND NOT MACOS AND (UNKNOWN_PLATFORM OR NOT ANDROID)' + assert scope11.total_condition == 'HAIKU AND (UNKNOWN_PLATFORM OR NOT ANDROID)' + assert scope12.total_condition == 'UNIX AND NOT HAIKU AND NOT MACOS AND (UNKNOWN_PLATFORM OR NOT ANDROID)' def test_recursive_expansion(): scope = _new_scope(A='Foo',B='$$A/Bar') @@ -343,4 +316,3 @@ def test_recursive_expansion(): assert scope.get_string('B') == '$$A/Bar' assert scope._expand_value('$$B/Source.cpp') == ['Foo/Bar/Source.cpp'] assert scope._expand_value('$$B') == ['Foo/Bar'] - |