aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside-tools/deploy_lib/android/android_helper.py
diff options
context:
space:
mode:
authorShyamnath Premnadh <Shyamnath.Premnadh@qt.io>2023-02-08 16:58:39 +0100
committerShyamnath Premnadh <shyamnath.premnadh@qt.io>2023-03-31 13:29:32 +0200
commit95abfa776411b6d7cd4296adf63bc7abce2270b6 (patch)
tree74e51c8c6d28044a60011158215919ab223d6fa5 /sources/pyside-tools/deploy_lib/android/android_helper.py
parent94b30c7207bea2467f0d7e41e99af27ecc749ed5 (diff)
Deployment: New pyside6-android-deploy tool
- Preliminary support for PySide6 Android deployment - Uses jinja2 to create PySide6 and shiboken6 recipes, to be used by buildozer when python_for_android builds the app distribution - Classes for Buildozer config interaction - Run deployment to android. Typical command looks like: """ pyside6-android-deploy --wheel-pyside=./PySide6-6.5.0a1-6.5.0-cp37-abi3-android_x86_64.whl --wheel-shiboken=./shiboken6-6.5.0a1-6.5.0-cp37-abi3-android_x86_64.whl --name=stringlistmodel """ - New entrypoint for pyside6-android-deploy - Helper functinos for Android Deployment - Remove unused function main_py_exists() - Added the new files to deploy.pyproject - Remove dry_run argument from install_python_dependencies() - new Python packages added in requirements.txt to enable the deploy and cross compile tool Note: python-for-android uses my local fork. This will be changed once it is merged into python-for-android dev. Task-number: PYSIDE-1612 Pick-to: 6.5 Change-Id: I7eb96fa5507a476b4e86ec0195a5e9869f0f85fd Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'sources/pyside-tools/deploy_lib/android/android_helper.py')
-rw-r--r--sources/pyside-tools/deploy_lib/android/android_helper.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/sources/pyside-tools/deploy_lib/android/android_helper.py b/sources/pyside-tools/deploy_lib/android/android_helper.py
new file mode 100644
index 000000000..b0c8254ab
--- /dev/null
+++ b/sources/pyside-tools/deploy_lib/android/android_helper.py
@@ -0,0 +1,59 @@
+# Copyright (C) 2023 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 logging
+from pathlib import Path
+from jinja2 import Environment, FileSystemLoader
+from zipfile import ZipFile
+from dataclasses import dataclass
+
+
+@dataclass
+class AndroidData:
+ wheel_pyside: Path
+ wheel_shiboken: Path
+ ndk_path: Path
+ sdk_path: Path
+
+
+def create_recipe(version: str, component: str, wheel_path: str, generated_files_path: Path):
+ '''
+ Create python_for_android recipe for PySide6 and shiboken6
+ '''
+ rcp_tmpl_path = Path(__file__).parent / "recipes" / f"{component}"
+ environment = Environment(loader=FileSystemLoader(rcp_tmpl_path))
+ template = environment.get_template("__init__.tmpl.py")
+ content = template.render(
+ version=version,
+ wheel_path=wheel_path,
+ )
+
+ recipe_path = generated_files_path / "recipes" / f"{component}"
+ recipe_path.mkdir(parents=True, exist_ok=True)
+ logging.info(f"Writing {component} recipe into {recipe_path}")
+ with open(recipe_path / "__init__.py", mode="w", encoding="utf-8") as recipe:
+ recipe.write(content)
+
+
+def extract_and_copy_jar(wheel_path: Path, generated_files_path: Path) -> str:
+ '''
+ extracts the PySide6 wheel and copies the 'jar' folder to 'generated_files_path'.
+ These .jar files are added to the buildozer.spec file to be later use by buildozer
+ '''
+ jar_path = generated_files_path / "jar"
+ jar_path.mkdir(parents=True, exist_ok=True)
+ archive = ZipFile(wheel_path)
+ jar_files = [file for file in archive.namelist() if file.startswith("PySide6/jar")]
+ for file in jar_files:
+ archive.extract(file, jar_path)
+ return jar_path
+
+
+def get_wheel_android_arch(wheel: str):
+ wheel = Path(wheel)
+ supported_archs = ["aarch64", "armv7a", "i686", "x86_64"]
+ for arch in supported_archs:
+ if arch in wheel.stem:
+ return arch
+
+ return None