1- from pythonforandroid .util import current_directory # type: ignore
2- from pythonforandroid .recipe import NDKRecipe # type: ignore
3- from pythonforandroid .recipe import Recipe # type: ignore
4- from pythonforandroid .logger import shprint # type: ignore
5- import shutil
6- import sh # type: ignore
71import os
2+ import shutil
3+
4+ import sh
5+ from pythonforandroid .archs import Arch
6+ from pythonforandroid .logger import shprint
7+ from pythonforandroid .recipe import NDKRecipe , Recipe
8+ from pythonforandroid .util import current_directory
89
910
1011class LibhackrfRecipe (NDKRecipe ):
1112
1213 url = 'https://github.com/greatscottgadgets/hackrf/releases/download/v{version}/hackrf-{version}.tar.xz'
13- patches = [ 'hackrf_android.patch' ]
14- generated_libraries = [ 'libhackrf.so' ]
14+ patches = ( 'hackrf_android.patch' , )
15+ generated_libraries = ( 'libhackrf.so' , )
1516 site_packages_name = 'libhackrf'
1617 version = '2024.02.1'
1718 library_release = '2024.02.1'
1819 library_version = '0.9'
19- depends = [ 'libusb' ]
20+ depends = ( 'libusb' , )
2021 name = 'libhackrf'
2122
22- def should_build (self , arch ) :
23- return True
23+ def should_build (self , arch : Arch ) -> bool :
24+ return not os . path . exists ( os . path . join ( self . ctx . get_libs_dir ( arch . arch ), 'libhackrf.so' ))
2425
25- def prebuild_arch (self , arch ) :
26+ def prebuild_arch (self , arch : Arch ) -> None :
2627 super ().prebuild_arch (arch )
2728
2829 if not os .path .exists (os .path .join (self .get_build_dir (arch .arch ), 'android' )):
@@ -38,19 +39,19 @@ def prebuild_arch(self, arch):
3839
3940 shutil .copy (os .path .join (libusb_recipe .get_build_dir (arch ), 'libusb' , 'libusb.h' ), os .path .join (self .get_build_dir (arch .arch ), 'android' , 'libusb' ))
4041
41- def get_recipe_env (self , arch ) :
42+ def get_recipe_env (self , arch : Arch ) -> dict :
4243 env = super ().get_recipe_env (arch )
4344 env ['LDFLAGS' ] += f'-L{ self .ctx .get_libs_dir (arch .arch )} '
4445
4546 return env
4647
47- def get_jni_dir (self , arch ) :
48+ def get_jni_dir (self , arch : Arch ) -> str :
4849 return os .path .join (self .get_build_dir (arch .arch ), 'android' , 'jni' )
4950
50- def get_lib_dir (self , arch ) :
51+ def get_lib_dir (self , arch : Arch ) -> str :
5152 return os .path .join (self .get_build_dir (arch .arch ), 'android' , 'obj' , 'local' , arch .arch )
5253
53- def build_arch (self , arch , * extra_args ):
54+ def build_arch (self , arch : Arch , * extra_args ) -> None :
5455 env = self .get_recipe_env (arch )
5556
5657 shutil .copyfile (os .path .join (self .ctx .get_libs_dir (arch .arch ), 'libusb1.0.so' ), os .path .join (self .get_build_dir (arch .arch ), 'android' , 'jni' , 'libusb1.0.so' ))
@@ -62,10 +63,10 @@ def build_arch(self, arch, *extra_args):
6263 'APP_PLATFORM=android-' + str (self .ctx .ndk_api ),
6364 'LIBRARY_VERSION=' + self .library_version ,
6465 'LIBRARY_RELEASE=' + self .library_release ,
65- 'NDK=' + self .ctx .ndk_dir ,
66+ 'NDK=' + self .ctx .ndk_dir ,
6667 'APP_ABI=' + arch .arch ,
6768 * extra_args ,
68- _env = env
69+ _env = env ,
6970 )
7071
7172 shutil .copyfile (os .path .join (self .get_build_dir (arch .arch ), 'android' , 'libs' , arch .arch , 'libhackrf.so' ), os .path .join (self .ctx .get_libs_dir (arch .arch ), 'libhackrf.so' ))
0 commit comments