diff options
| author | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2024-02-02 10:04:46 +0100 |
|---|---|---|
| committer | Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> | 2024-03-11 10:56:24 +0100 |
| commit | 45d03020d756d302dca19e62288dde1bcd3526d1 (patch) | |
| tree | 415fab112ba4005a439cf6cf231269ab01ff406d /sources/pyside-tools/deploy_lib/config.py | |
| parent | dec0ac7a94c787d100d1ca3f9298b7c3b07712aa (diff) | |
Deployment: add permission support and create macOS bundle application
- Look at the ast of the python files of the application to identify
the permissions used by the application. Once the permissions
are identified, pass the necessary NS property list key to be added
to the Info.plist file to Nuitka.
- For macOS, when deploying create a macOS application bundle (.app)
by default. This makes it align more with Apple recommendations
and Qt deployment.
- Fix tests.
- Fix wheel_tester.py to consider .app for macOS.
Task-number: PYSIDE-1612
Task-number: PYSIDE-2468
Change-Id: Ie225c9a92c845b432a8e7eaa791a8aeb86ecd988
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside-tools/deploy_lib/config.py')
| -rw-r--r-- | sources/pyside-tools/deploy_lib/config.py | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/sources/pyside-tools/deploy_lib/config.py b/sources/pyside-tools/deploy_lib/config.py index f1c877cac..2ca6ff895 100644 --- a/sources/pyside-tools/deploy_lib/config.py +++ b/sources/pyside-tools/deploy_lib/config.py @@ -1,5 +1,7 @@ # 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 sys import configparser import logging import warnings @@ -8,12 +10,23 @@ from typing import List from pathlib import Path from project import ProjectData -from . import DEFAULT_APP_ICON, find_pyside_modules, run_qmlimportscanner, QtDependencyReader +from . import (DEFAULT_APP_ICON, find_pyside_modules, find_permission_categories, + QtDependencyReader, run_qmlimportscanner) # Some QML plugins like QtCore are excluded from this list as they don't contribute much to # executable size. Excluding them saves the extra processing of checking for them in files EXCLUDED_QML_PLUGINS = {"QtQuick", "QtQuick3D", "QtCharts", "QtWebEngine", "QtTest", "QtSensors"} +PERMISSION_MAP = {"Bluetooth": "NSBluetoothAlwaysUsageDescription:BluetoothAccess", + "Camera": "NSCameraUsageDescription:CameraAccess", + "Microphone": "NSMicrophoneUsageDescription:MicrophoneAccess", + "Contacts": "NSContactsUsageDescription:ContactsAccess", + "Calendar": "NSCalendarsUsageDescription:CalendarAccess", + # for iOS NSLocationWhenInUseUsageDescription and + # NSLocationAlwaysAndWhenInUseUsageDescription are also required. + "Location": "NSLocationUsageDescription:LocationAccess", + } + class BaseConfig: """Wrapper class around any .spec file with function to read and set values for the .spec file @@ -22,7 +35,8 @@ class BaseConfig: existing_config_file: bool = False) -> None: self.config_file = config_file self.existing_config_file = existing_config_file - self.parser = ConfigParser(comment_prefixes=comment_prefixes, allow_no_value=True) + self.parser = ConfigParser(comment_prefixes=comment_prefixes, strict=False, + allow_no_value=True) self.parser.read(self.config_file) def update_config(self): @@ -379,6 +393,14 @@ class DesktopConfig(Config): else: self.qt_plugins = self.dependency_reader.find_plugin_dependencies(self.modules) + self._permissions = [] + if sys.platform == "darwin": + nuitka_macos_permissions = self.get_value("nuitka", "macos.permissions") + if nuitka_macos_permissions: + self._permissions = nuitka_macos_permissions.split(",") + else: + self._find_and_set_permissions() + @property def qt_plugins(self): return self._qt_plugins @@ -388,6 +410,15 @@ class DesktopConfig(Config): self._qt_plugins = qt_plugins self.set_value("qt", "plugins", ",".join(qt_plugins)) + @property + def permissions(self): + return self._permissions + + @permissions.setter + def permissions(self, permissions): + self._permissions = permissions + self.set_value("nuitka", "macos.permissions", ",".join(permissions)) + def _find_dependent_qt_modules(self): """ Given pysidedeploy_config.modules, find all the other dependent Qt modules. @@ -404,3 +435,24 @@ class DesktopConfig(Config): self.dependency_reader.find_dependencies(module=module_name, used_modules=all_modules) self.modules = list(all_modules) + + def _find_and_set_permissions(self): + """ + Finds and sets the usage description string required for each permission requested by the + macOS application. + """ + permissions = [] + perm_categories = find_permission_categories(project_dir=self.project_dir, + extra_ignore_dirs=self.extra_ignore_dirs, + project_data=self.project_data) + + perm_categories_str = ",".join(perm_categories) + logging.info(f"[DEPLOY] Usage descriptions for the {perm_categories_str} will be added to " + "the Info.plist file of the macOS application bundle") + + # handling permissions + for perm_category in perm_categories: + if perm_category in PERMISSION_MAP: + permissions.append(PERMISSION_MAP[perm_category]) + + self.permissions = permissions |
