|
| 1 | +import glob |
| 2 | +from logging import info |
| 3 | + |
| 4 | +import sh |
| 5 | +from pythonforandroid.logger import shprint |
| 6 | +from pythonforandroid.recipe import CppCompiledComponentsPythonRecipe |
| 7 | +from pythonforandroid.util import current_directory |
| 8 | + |
| 9 | + |
| 10 | +class GrpcioRecipe(CppCompiledComponentsPythonRecipe): |
| 11 | + version = '1.64.0' |
| 12 | + url = 'https://files.pythonhosted.org/packages/source/g/grpcio/grpcio-{version}.tar.gz' |
| 13 | + depends = ["setuptools", "librt", "libpthread"] |
| 14 | + patches = ["comment-getserverbyport-r-args.patch", "remove-android-log-write.patch"] |
| 15 | + |
| 16 | + def get_recipe_env(self, arch, **kwargs): |
| 17 | + env = super().get_recipe_env(arch, **kwargs) |
| 18 | + env['NDKPLATFORM'] = "NOTNONE" |
| 19 | + env['GRPC_PYTHON_BUILD_WITH_CYTHON'] = '1' |
| 20 | + env["CFLAGS"] += " -U__ANDROID_API__" |
| 21 | + env["CFLAGS"] += " -D__ANDROID_API__={}".format(self.ctx.ndk_api) |
| 22 | + |
| 23 | + # turn off c++11 warning error of "invalid suffix on literal" |
| 24 | + env["CFLAGS"] += " -Wno-reserved-user-defined-literal" |
| 25 | + env['PLATFORM'] = 'android' |
| 26 | + env["LDFLAGS"] += " -llog -landroid" |
| 27 | + return env |
| 28 | + |
| 29 | + def build_compiled_components(self, arch): |
| 30 | + info('Building compiled components in {}'.format(self.name)) |
| 31 | + |
| 32 | + env = self.get_recipe_env(arch) |
| 33 | + hostpython = sh.Command(self.hostpython_location) |
| 34 | + with current_directory(self.get_build_dir(arch.arch)): |
| 35 | + if self.install_in_hostpython: |
| 36 | + shprint(hostpython, 'setup.py', 'clean', '--all', _env=env) |
| 37 | + shprint(hostpython, 'setup.py', self.build_cmd, '-v', |
| 38 | + _env=env, *self.setup_extra_args) |
| 39 | + |
| 40 | + # grpcio creates a build directory and names it `pyb` |
| 41 | + build_dir = glob.glob('pyb/lib.*')[0] |
| 42 | + shprint(sh.find, build_dir, '-name', '"*.o"', '-exec', |
| 43 | + env['STRIP'], '{}', ';', _env=env) |
| 44 | + |
| 45 | + |
| 46 | +recipe = GrpcioRecipe() |
0 commit comments