Dynamically generate __main__.py of Android aar package

This commit is contained in:
Anonymous Maarten 2024-08-29 13:50:51 +02:00
parent a5866809bb
commit d6ad28a4cb
3 changed files with 20 additions and 13 deletions

View File

@ -609,21 +609,28 @@ class Releaser:
aar_path = self.dist_path / f"{self.project}-{self.version}.aar"
added_global_files = False
with zipfile.ZipFile(aar_path, "w", compression=zipfile.ZIP_DEFLATED) as zip_object:
install_txt = (self.root / "build-scripts/pkg-support/android/INSTALL.md.in").read_text()
install_txt = install_txt.replace("@PROJECT_VERSION@", self.version)
install_txt = install_txt.replace("@PROJECT_NAME@", self.project)
def configure_file(path: Path) -> str:
text = path.read_text()
text = text.replace("@PROJECT_VERSION@", self.version)
text = text.replace("@PROJECT_NAME@", self.project)
return text
install_txt = configure_file(self.root / "build-scripts/pkg-support/android/INSTALL.md.in")
zip_object.writestr("INSTALL.md", install_txt)
project_description = {
"name": self.project,
"version": self.version,
"git-hash": self.commit,
}
zip_object.writestr("description.json", json.dumps(project_description, indent=0))
main_py = configure_file(self.root / "build-scripts/pkg-support/android/__main__.py.in")
zip_object.writestr("__main__.py", main_py)
zip_object.writestr("AndroidManifest.xml", self.get_android_manifest_text())
zip_object.write(self.root / "android-project/app/proguard-rules.pro", arcname="proguard.txt")
zip_object.write(self.root / "LICENSE.txt", arcname="META-INF/LICENSE.txt")
zip_object.write(self.root / "cmake/sdlcpu.cmake", arcname="cmake/sdlcpu.cmake")
zip_object.write(self.root / "build-scripts/pkg-support/android/__main__.py", arcname="__main__.py")
zip_object.write(self.root / "build-scripts/pkg-support/android/cmake/SDL3Config.cmake", arcname="cmake/SDL3Config.cmake")
zip_object.write(self.root / "build-scripts/pkg-support/android/cmake/SDL3ConfigVersion.cmake", arcname="cmake/SDL3ConfigVersion.cmake")
zip_object.writestr("prefab/prefab.json", self.get_prefab_json_text())

View File

@ -1,12 +1,12 @@
#!/usr/bin/env python
"""
Create a SDL SDK prefix from an Android archive
Create a @PROJECT_NAME@ SDK prefix from an Android archive
This file is meant to be placed in a the root of an android .aar archive
Example usage:
```sh
python SDL3-3.2.0.aar -o /usr/opt/android-sdks
python @PROJECT_NAME@-@PROJECT_VERSION@.aar -o /usr/opt/android-sdks
cmake -S my-project \
-DCMAKE_PREFIX_PATH=/usr/opt/android-sdks \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
@ -31,13 +31,13 @@ ANDROID_ARCHS = { "armeabi-v7a", "arm64-v8a", "x86", "x86_64" }
def main():
parser = argparse.ArgumentParser(
description="Convert an Android .aar archive into a SDK",
description="Convert a @PROJECT_NAME@ Android .aar archive into a SDK",
allow_abbrev=False,
)
parser.add_argument("-o", dest="output", type=pathlib.Path, required=True, help="Folder where to store the SDK")
args = parser.parse_args()
print(f"Creating a SDK at {args.output}...")
print(f"Creating a @PROJECT_NAME@ SDK at {args.output}...")
prefix = args.output
incdir = prefix / "include"

View File

@ -47,11 +47,11 @@ get_filename_component(_sdl3_prefix "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
get_filename_component(_sdl3_prefix "${_sdl3_prefix}/.." ABSOLUTE)
get_filename_component(_sdl3_prefix "${_sdl3_prefix}/.." ABSOLUTE)
set_and_check(_sdl3_prefix "${_sdl3_prefix}")
set(_sdl3_include_dirs "${_sdl3_prefix}/include")
set_and_check(_sdl3_include_dirs "${_sdl3_prefix}/include")
set(_sdl3_lib "${_sdl3_prefix}/lib/${_sdl_arch_subdir}/libSDL3.so")
set(_sdl3test_lib "${_sdl3_prefix}/lib/${_sdl_arch_subdir}/libSDL3_test.a")
set(_sdl3_jar "${_sdl3_prefix}/share/java/SDL3/SDL3-${SDL3_VERSION}.jar")
set_and_check(_sdl3_lib "${_sdl3_prefix}/lib/${_sdl_arch_subdir}/libSDL3.so")
set_and_check(_sdl3test_lib "${_sdl3_prefix}/lib/${_sdl_arch_subdir}/libSDL3_test.a")
set_and_check(_sdl3_jar "${_sdl3_prefix}/share/java/SDL3/SDL3-${SDL3_VERSION}.jar")
unset(_sdl_arch_subdir)
unset(_sdl3_prefix)