Skip to content

Commit c57e802

Browse files
committed
updated recipes for android
1 parent 8dd72fb commit c57e802

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

android/libhackrf/__init__.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
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
71
import 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

1011
class 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'))

android/libusb/__init__.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
from pythonforandroid.util import current_directory # type: ignore
2-
from pythonforandroid.recipe import NDKRecipe # type: ignore
3-
from pythonforandroid.logger import shprint # type: ignore
4-
import shutil
5-
import sh # type: ignore
61
import 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
8+
from pythonforandroid.util import current_directory
79

810

911
class LibusbRecipe(NDKRecipe):
1012

1113
url = 'https://github.com/libusb/libusb/archive/refs/tags/v{version}.tar.gz'
12-
generated_libraries = ['libusb-1.0.so']
14+
generated_libraries = ('libusb-1.0.so', )
1315
site_packages_name = 'libusb'
1416
version = '1.0.26'
1517
name = 'libusb'
1618

17-
def should_build(self, arch):
18-
return True
19+
def should_build(self, arch: Arch) -> bool:
20+
return not os.path.exists(os.path.join(self.ctx.get_libs_dir(arch.arch), 'libusb1.0.so'))
1921

20-
def get_jni_dir(self, arch):
22+
def get_jni_dir(self, arch: Arch) -> str:
2123
return os.path.join(self.get_build_dir(arch.arch), 'android', 'jni')
2224

23-
def get_lib_dir(self, arch):
25+
def get_lib_dir(self, arch: Arch) -> str:
2426
return os.path.join(self.get_build_dir(arch.arch), 'android', 'obj', 'local', arch.arch)
2527

26-
def build_arch(self, arch, *extra_args):
28+
def build_arch(self, arch: Arch, *extra_args) -> None:
2729
env = self.get_recipe_env(arch)
2830
with current_directory(self.get_build_dir(arch.arch)):
2931
shprint(
3032
sh.Command(os.path.join(self.ctx.ndk_dir, 'ndk-build')),
3133
'NDK_PROJECT_PATH=' + self.get_build_dir(arch.arch) + '/android',
3234
'APP_PLATFORM=android-' + str(self.ctx.ndk_api),
33-
'NDK='+self.ctx.ndk_dir,
35+
'NDK=' + self.ctx.ndk_dir,
3436
'APP_ABI=' + arch.arch,
3537
*extra_args,
36-
_env=env
38+
_env=env,
3739
)
3840

3941
shutil.copyfile(os.path.join(self.get_build_dir(arch.arch), 'android', 'libs', arch.arch, 'libusb1.0.so'), os.path.join(self.ctx.get_libs_dir(arch.arch), 'libusb1.0.so'))

android/python_hackrf/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
from pythonforandroid.recipe import CythonRecipe # type: ignore
2-
from pythonforandroid.recipe import Recipe # type: ignore
31
import os
42

3+
from pythonforandroid.archs import Arch
4+
from pythonforandroid.recipe import (
5+
CythonRecipe,
6+
Recipe,
7+
)
8+
59

610
class PythonHackrfRecipe(CythonRecipe):
711
url = 'https://github.com/GvozdevLeonid/python_hackrf/releases/download/v.{version}/python_hackrf-{version}.tar.gz'
8-
depends = ['python3', 'setuptools', 'numpy', 'pyjnius', 'libhackrf']
12+
depends = ('python3', 'setuptools', 'numpy', 'pyjnius', 'libhackrf')
913
site_packages_name = 'python_hackrf'
1014
name = 'python_hackrf'
11-
version = '1.2.1'
15+
version = '1.2.2'
1216

13-
def get_recipe_env(self, arch):
17+
def get_recipe_env(self, arch: Arch) -> dict:
1418
env = super().get_recipe_env(arch)
1519

1620
libhackrf_recipe = Recipe.get_recipe('libhackrf', arch)

0 commit comments

Comments
 (0)