|
| 1 | +import sys |
| 2 | +import os |
| 3 | +import shutil |
| 4 | +from os.path import join, exists, basename |
| 5 | +import sh |
| 6 | +from pythonforandroid.recipe import Recipe |
| 7 | +from pythonforandroid.toolchain import shprint, current_directory |
| 8 | +from pythonforandroid.util import ensure_dir |
| 9 | + |
| 10 | + |
| 11 | +class SkiaRecipe(Recipe): |
| 12 | + version = "skia-binaries-m140-rev1.a0" |
| 13 | + url = "https://github.com/DexerBR/skia-builder/releases/download/{version}/android-merged.tar.gz" |
| 14 | + name = "skia" |
| 15 | + |
| 16 | + skia_libraries = [ |
| 17 | + "libskparagraph.a", |
| 18 | + "libskia.a", |
| 19 | + "libskottie.a", |
| 20 | + "libsksg.a", |
| 21 | + "libskshaper.a", |
| 22 | + "libskunicode_icu.a", |
| 23 | + "libskunicode_core.a", |
| 24 | + "libjsonreader.a", |
| 25 | + ] |
| 26 | + |
| 27 | + built_libraries = {"libskmerged.a": "bin"} |
| 28 | + |
| 29 | + def _get_skia_platform(self, arch): |
| 30 | + arch_map = { |
| 31 | + "arm64-v8a": "android-arm64", |
| 32 | + "armeabi-v7a": "android-arm", |
| 33 | + "x86_64": "android-x64", |
| 34 | + "x86": "android-x86", |
| 35 | + } |
| 36 | + arch_name = arch.arch if hasattr(arch, "arch") else arch |
| 37 | + return arch_map.get(arch_name, arch_name) |
| 38 | + |
| 39 | + def unpack(self, arch): |
| 40 | + build_dir = self.get_build_container_dir(arch) |
| 41 | + target_dir = self.get_build_dir(arch) |
| 42 | + |
| 43 | + if exists(target_dir): |
| 44 | + return |
| 45 | + |
| 46 | + ensure_dir(build_dir) |
| 47 | + |
| 48 | + filename = basename(self.versioned_url) |
| 49 | + archive_path = join(self.ctx.packages_path, self.name, filename) |
| 50 | + skia_platform = self._get_skia_platform(arch) |
| 51 | + |
| 52 | + with current_directory(build_dir): |
| 53 | + temp_extract_dir = join(build_dir, "temp_extract") |
| 54 | + ensure_dir(temp_extract_dir) |
| 55 | + |
| 56 | + with current_directory(temp_extract_dir): |
| 57 | + shprint(sh.tar, "xzf", archive_path) |
| 58 | + |
| 59 | + ensure_dir(target_dir) |
| 60 | + |
| 61 | + # Find and extract the architecture-specific tar.gz |
| 62 | + arch_file = f"{skia_platform}.tar.gz" |
| 63 | + arch_file_path = join(temp_extract_dir, arch_file) |
| 64 | + |
| 65 | + if exists(arch_file_path): |
| 66 | + print(f"Found {arch_file}, extracting...") |
| 67 | + with current_directory(target_dir): |
| 68 | + shprint(sh.tar, "xzf", arch_file_path) |
| 69 | + else: |
| 70 | + print(f"Architecture file not found: {arch_file}") |
| 71 | + print(f"Available files: {os.listdir(temp_extract_dir)}") |
| 72 | + sys.exit(1) |
| 73 | + |
| 74 | + shutil.rmtree(temp_extract_dir) |
| 75 | + |
| 76 | + def build_arch(self, arch): |
| 77 | + build_dir = self.get_build_dir(arch.arch) |
| 78 | + merged_lib_path = join(build_dir, "bin", "libskmerged.a") |
| 79 | + |
| 80 | + lib_files = [] |
| 81 | + for lib in self.skia_libraries: |
| 82 | + lib_path = join(build_dir, "bin", lib) |
| 83 | + if exists(lib_path): |
| 84 | + lib_files.append(lib_path) |
| 85 | + |
| 86 | + if lib_files: |
| 87 | + with current_directory(build_dir): |
| 88 | + shprint( |
| 89 | + sh.Command(self.ctx.ndk.llvm_ar), |
| 90 | + "rcs", |
| 91 | + merged_lib_path, |
| 92 | + *lib_files, |
| 93 | + ) |
| 94 | + |
| 95 | + def get_include_dirs(self, arch): |
| 96 | + build_dir = self.get_build_dir(arch.arch) |
| 97 | + return [ |
| 98 | + d |
| 99 | + for d in [ |
| 100 | + join(build_dir, subdir) |
| 101 | + for subdir in ["include", "modules", "src"] |
| 102 | + ] |
| 103 | + if exists(d) |
| 104 | + ] |
| 105 | + |
| 106 | + def get_lib_dir(self, arch): |
| 107 | + return self.get_build_dir(arch.arch) |
| 108 | + |
| 109 | + |
| 110 | +recipe = SkiaRecipe() |
0 commit comments