aboutsummaryrefslogtreecommitdiffstats
path: root/build_scripts/qtinfo.py
diff options
context:
space:
mode:
Diffstat (limited to 'build_scripts/qtinfo.py')
-rw-r--r--build_scripts/qtinfo.py215
1 files changed, 105 insertions, 110 deletions
diff --git a/build_scripts/qtinfo.py b/build_scripts/qtinfo.py
index 4fdc77d7f..1eb7c4909 100644
--- a/build_scripts/qtinfo.py
+++ b/build_scripts/qtinfo.py
@@ -1,66 +1,12 @@
-#############################################################################
-##
-## Copyright (C) 2018 The Qt Company Ltd.
-## Contact: https://www.qt.io/licensing/
-##
-## This file is part of Qt for Python.
-##
-## $QT_BEGIN_LICENSE:LGPL$
-## 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 Lesser General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU Lesser
-## General Public License version 3 as published by the Free Software
-## Foundation and appearing in the file LICENSE.LGPL3 included in the
-## packaging of this file. Please review the following information to
-## ensure the GNU Lesser General Public License version 3 requirements
-## will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-##
-## GNU General Public License Usage
-## Alternatively, this file may be used under the terms of the GNU
-## General Public License version 2.0 or (at your option) the GNU General
-## Public license version 3 or any later version approved by the KDE Free
-## Qt Foundation. The licenses are as published by the Free Software
-## Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-## 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-2.0.html and
-## https://www.gnu.org/licenses/gpl-3.0.html.
-##
-## $QT_END_LICENSE$
-##
-#############################################################################
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
import os
-import sys
-import re
import subprocess
-import tempfile
from pathlib import Path
-
-_CMAKE_LISTS = """cmake_minimum_required(VERSION 3.18)
-project(dummy LANGUAGES CXX)
-
-find_package(Qt6 COMPONENTS Core)
-
-get_target_property(darwin_target Qt6::Core QT_DARWIN_MIN_DEPLOYMENT_TARGET)
-message(STATUS "mkspec_qt_darwin_min_deployment_target=${darwin_target}")
-
-if(QT_FEATURE_debug_and_release)
- message(STATUS "mkspec_build_type=debug_and_release")
-elseif(QT_FEATURE_debug)
- message(STATUS "mkspec_build_type=debug")
-else()
- message(STATUS "mkspec_build_type=release")
-endif()
-"""
+from .utils import (configure_cmake_project, parse_cmake_project_message_info,
+ platform_cmake_options)
class QtInfo(object):
@@ -83,32 +29,62 @@ class QtInfo(object):
self._cmake_command = None
self._qmake_command = None
self._force_qmake = False
+ self._use_cmake = False
+ self._qt_target_path = None
+ self._cmake_toolchain_file = None
# Dict to cache qmake values.
self._query_dict = {}
- def setup(self, qtpaths, cmake, qmake, force_qmake):
+ def setup(self, qtpaths, cmake, qmake, force_qmake, use_cmake, qt_target_path,
+ cmake_toolchain_file):
self._qtpaths_command = qtpaths
self._cmake_command = cmake
self._qmake_command = qmake
self._force_qmake = force_qmake
+ self._use_cmake = use_cmake
+ self._qt_target_path = qt_target_path
+ self._cmake_toolchain_file = cmake_toolchain_file
@property
def qmake_command(self):
return self._qmake_command
@property
+ def qtpaths_command(self):
+ return self._qtpaths_command
+
+ @property
def version(self):
return self.get_property("QT_VERSION")
@property
+ def version_tuple(self):
+ return tuple(map(int, self.version.split(".")))
+
+ @property
def bins_dir(self):
return self.get_property("QT_INSTALL_BINS")
@property
+ def data_dir(self):
+ return self.get_property("QT_INSTALL_DATA")
+
+ @property
def libs_dir(self):
return self.get_property("QT_INSTALL_LIBS")
@property
+ def module_json_files_dir(self):
+ # FIXME: Use INSTALL_DESCRIPTIONSDIR once QTBUG-116983 is done.
+ result = Path(self.arch_data) / "modules"
+ return os.fspath(result)
+
+ @property
+ def metatypes_dir(self):
+ parent = self.arch_data if self.version_tuple >= (6, 5, 0) else self.libs_dir
+ return os.fspath(Path(parent) / "metatypes")
+
+ @property
def lib_execs_dir(self):
return self.get_property("QT_INSTALL_LIBEXECS")
@@ -121,6 +97,10 @@ class QtInfo(object):
return self.get_property("QT_INSTALL_PREFIX")
@property
+ def arch_data(self):
+ return self.get_property("QT_INSTALL_ARCHDATA")
+
+ @property
def imports_dir(self):
return self.get_property("QT_INSTALL_IMPORTS")
@@ -165,9 +145,11 @@ class QtInfo(object):
return None
return self._query_dict[prop_name]
- def _get_qtpaths_output(self, args_list=[], cwd=None):
+ def _get_qtpaths_output(self, args_list=None, cwd=None):
+ if args_list is None:
+ args_list = []
assert self._qtpaths_command
- cmd = [self._qtpaths_command]
+ cmd = [str(self._qtpaths_command)]
cmd.extend(args_list)
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False,
cwd=cwd, universal_newlines=True)
@@ -178,7 +160,9 @@ class QtInfo(object):
return output
# FIXME PYSIDE7: Remove qmake handling
- def _get_qmake_output(self, args_list=[], cwd=None):
+ def _get_qmake_output(self, args_list=None, cwd=None):
+ if args_list is None:
+ args_list = []
assert self._qmake_command
cmd = [self._qmake_command]
cmd.extend(args_list)
@@ -203,64 +187,75 @@ class QtInfo(object):
return props
def _get_query_properties(self):
- if self._force_qmake:
- output = self._get_qmake_output(["-query"])
+ if self._use_cmake:
+ setup_script_dir = Path.cwd()
+ sources_dir = setup_script_dir / "sources"
+ qt_target_info_dir = sources_dir / "shiboken6" / "config.tests" / "target_qt_info"
+ qt_target_info_dir = os.fspath(qt_target_info_dir)
+ config_tests_dir = setup_script_dir / "build" / "config.tests"
+ config_tests_dir = os.fspath(config_tests_dir)
+
+ cmake_cache_args = []
+ if self._cmake_toolchain_file:
+ cmake_cache_args.append(("CMAKE_TOOLCHAIN_FILE", self._cmake_toolchain_file))
+
+ if self._qt_target_path:
+ cmake_cache_args.append(("QFP_QT_TARGET_PATH", self._qt_target_path))
+ qt_target_info_output = configure_cmake_project(
+ qt_target_info_dir,
+ self._cmake_command,
+ temp_prefix_build_path=config_tests_dir,
+ cmake_cache_args=cmake_cache_args)
+ qt_target_info = parse_cmake_project_message_info(qt_target_info_output)
+ self._query_dict = qt_target_info['qt_info']
else:
- output = self._get_qtpaths_output(["--qt-query"])
- self._query_dict = self._parse_query_properties(output)
+ if self._force_qmake:
+ output = self._get_qmake_output(["-query"])
+ else:
+ output = self._get_qtpaths_output(["--qt-query"])
+ self._query_dict = self._parse_query_properties(output)
def _get_other_properties(self):
# Get the src property separately, because it is not returned by
# qmake unless explicitly specified.
key = "QT_INSTALL_PREFIX/src"
- if self._force_qmake:
- result = self._get_qmake_output(["-query", key])
- else:
- result = self._get_qtpaths_output(["--qt-query", key])
- self._query_dict[key] = result
+ if not self._use_cmake:
+ if self._force_qmake:
+ result = self._get_qmake_output(["-query", key])
+ else:
+ result = self._get_qtpaths_output(["--qt-query", key])
+ self._query_dict[key] = result
# Get mkspecs variables and cache them.
# FIXME Python 3.9 self._query_dict |= other_dict
for key, value in self._get_cmake_mkspecs_variables().items():
self._query_dict[key] = value
- @staticmethod
- def _parse_cmake_mkspecs_variables(output):
- # Helper for _get_cmake_mkspecs_variables(). Parse the output for
- # anything prefixed '-- mkspec_' as created by the message() calls
- # in _CMAKE_LISTS.
- result = {}
- pattern = re.compile(r"^-- mkspec_(.*)=(.*)$")
- for line in output.splitlines():
- found = pattern.search(line.strip())
- if found:
- key = found.group(1).strip()
- value = found.group(2).strip()
- # Get macOS minimum deployment target.
- if key == 'qt_darwin_min_deployment_target':
- result['QMAKE_MACOSX_DEPLOYMENT_TARGET'] = value
- # Figure out how Qt was built
- elif key == 'build_type':
- result['BUILD_TYPE'] = value
- return result
-
def _get_cmake_mkspecs_variables(self):
- # Create an empty cmake project file in a temporary directory and
- # parse the output to determine some mkspec values.
- output = ''
- error = ''
- return_code = 0
- with tempfile.TemporaryDirectory() as tempdir:
- cmake_list_file = Path(tempdir) / 'CMakeLists.txt'
- cmake_list_file.write_text(_CMAKE_LISTS)
- cmd = [self._cmake_command, '-G', 'Ninja', '.']
- # FIXME Python 3.7: Use subprocess.run()
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=False,
- cwd=tempdir, universal_newlines=True)
- output, error = proc.communicate()
- proc.wait()
- return_code = proc.returncode
-
- if return_code != 0:
- raise RuntimeError(f"Could not determine cmake variables: {error}")
- return QtInfo.__QtInfo._parse_cmake_mkspecs_variables(output)
+ setup_script_dir = Path.cwd()
+ sources_dir = setup_script_dir / "sources"
+ qt_target_mkspec_dir = sources_dir / "shiboken6" / "config.tests" / "target_qt_mkspec"
+ qt_target_mkspec_dir = qt_target_mkspec_dir.as_posix()
+ config_tests_dir = setup_script_dir / "build" / "config.tests"
+ config_tests_dir = config_tests_dir.as_posix()
+
+ cmake_cache_args = []
+ if self._cmake_toolchain_file:
+ cmake_cache_args.append(("CMAKE_TOOLCHAIN_FILE", self._cmake_toolchain_file))
+ if self._qt_target_path:
+ cmake_cache_args.append(("QFP_QT_TARGET_PATH", self._qt_target_path))
+ else:
+ qt_prefix = Path(self.prefix_dir).as_posix()
+ cmake_cache_args.append(("CMAKE_PREFIX_PATH", qt_prefix))
+
+ cmake_cache_args.extend(platform_cmake_options(as_tuple_list=True))
+ qt_target_mkspec_output = configure_cmake_project(
+ qt_target_mkspec_dir,
+ self._cmake_command,
+ temp_prefix_build_path=config_tests_dir,
+ cmake_cache_args=cmake_cache_args)
+
+ qt_target_mkspec_info = parse_cmake_project_message_info(qt_target_mkspec_output)
+ qt_target_mkspec_info = qt_target_mkspec_info['qt_info']
+
+ return qt_target_mkspec_info