aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools/deploy_lib/commands.py
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-10-17 11:27:13 +0200
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2022-12-29 10:04:41 +0000
commite37f082c958b7a5349e245af0586b7e5e9c358ae (patch)
treef8c1d1d33258504208805085a935a23f5b913022 /sources/pyside-tools/deploy_lib/commands.py
parent134adfc99bf57acf84df8bfa74c545d0e43879a5 (diff)
Deploy tool: Reduce QML executable size + tests
- Added more Nuitka options to reduce the size of QML executable. Some binaries which cause the QML executable to become heavy eg: QtWebEngine are removed, if they are not used - Add new log messages for --verbose option - Add deploy.pyproject file - Modifies pyside6-deploy tests to consider the QML options, by mocking pyside6-qmlimportscanner Task-number: PYSIDE-1612 Change-Id: Id2e94217e99eedbf41ecfc8de1a37e94c7edaa52 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside-tools/deploy_lib/commands.py')
-rw-r--r--sources/pyside-tools/deploy_lib/commands.py46
1 files changed, 39 insertions, 7 deletions
diff --git a/sources/pyside-tools/deploy_lib/commands.py b/sources/pyside-tools/deploy_lib/commands.py
index 2733dd4c1..53ad633ea 100644
--- a/sources/pyside-tools/deploy_lib/commands.py
+++ b/sources/pyside-tools/deploy_lib/commands.py
@@ -4,29 +4,61 @@
import subprocess
import sys
import logging
+from typing import List
+
+import json
+from pathlib import Path
"""
All utility functions for deployment
"""
-def run_command(command, dry_run: bool):
+def run_command(command, dry_run: bool, fetch_output: bool = False):
command_str = " ".join([str(cmd) for cmd in command])
+ output = None
+ is_windows = (sys.platform == "win32")
try:
if not dry_run:
- subprocess.check_call(command, shell=(sys.platform == "win32"))
+ if fetch_output:
+ output = subprocess.check_output(command, shell=is_windows)
+ else:
+ subprocess.check_call(command, shell=is_windows)
else:
print(command_str + "\n")
except FileNotFoundError as error:
- logging.exception(f"[DEPLOY]: {error.filename} not found")
+ logging.exception(f"[DEPLOY] {error.filename} not found")
raise
except subprocess.CalledProcessError as error:
logging.exception(
- f"[DEPLOY]: Command {command_str} failed with error {error} and return_code"
- f"{error.returncode}"
+ f"[DEPLOY] Command {command_str} failed with error {error} and return_code"
+ f"{error.returncode}"
)
raise
except Exception as error:
- logging.exception(f"[DEPLOY]: Command {command_str} failed with error {error}")
+ logging.exception(f"[DEPLOY] Command {command_str} failed with error {error}")
raise
- return command_str
+ return command_str, output
+
+
+def run_qmlimportscanner(qml_files: List[Path], dry_run: bool):
+ """
+ Runs pyside6-qmlimportscanner to find all the imported qml modules
+ """
+ if not qml_files:
+ return []
+
+ qml_modules = []
+ cmd = ["pyside6-qmlimportscanner", "-qmlFiles"]
+ cmd.extend([str(qml_file) for qml_file in qml_files])
+
+ if dry_run:
+ run_command(command=cmd, dry_run=True)
+
+ # we need to run qmlimportscanner during dry_run as well to complete the
+ # command being run by nuitka
+ _, json_string = run_command(command=cmd, dry_run=False, fetch_output=True)
+ json_string = json_string.decode("utf-8")
+ json_array = json.loads(json_string)
+ qml_modules = [item['name'] for item in json_array if item['type'] == "module"]
+ return qml_modules