aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools/deploy_lib/commands.py
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-07-01 16:26:19 +0200
committerShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2024-08-05 17:08:13 +0200
commitb32183d2cd5fbbd1ac6a53827edf5d40428855ff (patch)
tree6737affc03a4f3b29b736bb26b45c9542dd9a2cf /sources/pyside-tools/deploy_lib/commands.py
parentc042e74cb490905c5cf5dc7d1c3887f627291019 (diff)
Desktop Deployment: Change qmlimportscanner usage parameters
- Previously, pyside6-qmlimportscanner was run on each of the QML files by listing the QML files. For projects with a large number of QML files, this leads to a long command line that exceeds the maximum command line length on Windows. - This change modifies the command to use `-rootPath` command line option to specify the root path of the project directory. This will recursively find all the QML files in the project directory and its subdirectories, and find the QML modules used. - This solution moves all the '.qml' files in the project directory into a temporary directory and running pyside6-qmlimportscanner on this temporary directory. - Additionally, memoize the function run_qmlimportscanner() to avoid running the qmlimportscanner multiple times for the same project. Pick-to: 6.7 Task-number: PYSIDE-1612 Task-number: PYSIDE-2803 Change-Id: Ie82fc4e5071debe505fae7b5815b76c89d99ff4c 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.py44
1 files changed, 28 insertions, 16 deletions
diff --git a/sources/pyside-tools/deploy_lib/commands.py b/sources/pyside-tools/deploy_lib/commands.py
index ee1abcb15..a45ced374 100644
--- a/sources/pyside-tools/deploy_lib/commands.py
+++ b/sources/pyside-tools/deploy_lib/commands.py
@@ -5,7 +5,11 @@ from __future__ import annotations
import json
import subprocess
import sys
+import shutil
+import tempfile
from pathlib import Path
+from functools import lru_cache
+
"""
All utility functions for deployment
@@ -37,24 +41,32 @@ def run_command(command, dry_run: bool, fetch_output: bool = False):
return command_str, output
+@lru_cache
def run_qmlimportscanner(qml_files: list[Path], dry_run: bool):
"""
- Runs pyside6-qmlimportscanner to find all the imported qml modules
+ Runs pyside6-qmlimportscanner to find all the imported qml modules in project_dir
"""
- 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"]
+ # Create a temporary directory to copy all the .qml_files
+ # TODO: Modify qmlimportscanner code in qtdeclarative to include a flag to ignore directories
+ # Then, this copy into a temporary directory can be avoided
+ # See 36b425ea8bf36d47694ea69fa7d129b6d5a2ca2d in gerrit
+ with tempfile.TemporaryDirectory() as temp_dir:
+ temp_path = Path(temp_dir)
+ # Copy only files with .qml suffix
+ for qml_file in qml_files:
+ if qml_file.suffix == ".qml":
+ shutil.copy2(qml_file.resolve(), temp_path / qml_file.name)
+
+ cmd = ["pyside6-qmlimportscanner", "-rootPath", str(temp_path)]
+
+ if dry_run:
+ run_command(command=cmd, dry_run=True)
+
+ # 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