11from pythonforandroid .recipe import PythonRecipe
22from pythonforandroid .logger import shprint , info_notify
33from pythonforandroid .util import current_directory , shutil
4- from os .path import exists , join , dirname
4+ from os .path import exists , join
55import sh
66from multiprocessing import cpu_count
77from pythonforandroid .toolchain import info
1111
1212class ProtobufCppRecipe (PythonRecipe ):
1313 name = 'protobuf_cpp'
14- version = '3.5 .1'
14+ version = '3.6 .1'
1515 url = 'https://github.com/google/protobuf/releases/download/v{version}/protobuf-python-{version}.tar.gz'
1616 call_hostpython_via_targetpython = False
1717 depends = ['cffi' , 'setuptools' ]
@@ -20,6 +20,12 @@ class ProtobufCppRecipe(PythonRecipe):
2020
2121 def prebuild_arch (self , arch ):
2222 super (ProtobufCppRecipe , self ).prebuild_arch (arch )
23+
24+ patch_mark = join (self .get_build_dir (arch .arch ), '.protobuf-patched' )
25+ if self .ctx .python_recipe .name == 'python3' and not exists (patch_mark ):
26+ self .apply_patch ('fix-python3-compatibility.patch' , arch .arch )
27+ shprint (sh .touch , patch_mark )
28+
2329 # During building, host needs to transpile .proto files to .py
2430 # ideally with the same version as protobuf runtime, or with an older one.
2531 # Because protoc is compiled for target (i.e. Android), we need an other binary
@@ -100,34 +106,18 @@ def install_python_package(self, arch):
100106 with current_directory (join (self .get_build_dir (arch .arch ), 'python' )):
101107 hostpython = sh .Command (self .hostpython_location )
102108
103- if self .ctx .python_recipe .from_crystax :
104- hpenv = env .copy ()
105- shprint (hostpython , 'setup.py' , 'install' , '-O2' ,
106- '--root={}' .format (self .ctx .get_python_install_dir ()),
107- '--install-lib=.' ,
108- '--cpp_implementation' ,
109- _env = hpenv , * self .setup_extra_args )
110- else :
111- hppath = join (dirname (self .hostpython_location ), 'Lib' ,
112- 'site-packages' )
113- hpenv = env .copy ()
114- if 'PYTHONPATH' in hpenv :
115- hpenv ['PYTHONPATH' ] = ':' .join ([hppath ] +
116- hpenv ['PYTHONPATH' ].split (':' ))
117- else :
118- hpenv ['PYTHONPATH' ] = hppath
119- shprint (hostpython , 'setup.py' , 'install' , '-O2' ,
120- '--root={}' .format (self .ctx .get_python_install_dir ()),
121- '--install-lib=lib/python2.7/site-packages' ,
122- '--cpp_implementation' ,
123- _env = hpenv , * self .setup_extra_args )
109+ hpenv = env .copy ()
110+ shprint (hostpython , 'setup.py' , 'install' , '-O2' ,
111+ '--root={}' .format (self .ctx .get_python_install_dir ()),
112+ '--install-lib=.' ,
113+ '--cpp_implementation' ,
114+ _env = hpenv , * self .setup_extra_args )
124115
125116 def get_recipe_env (self , arch ):
126117 env = super (ProtobufCppRecipe , self ).get_recipe_env (arch )
127118 if self .protoc_dir is not None :
128119 # we need protoc with binary for host platform
129120 env ['PROTOC' ] = join (self .protoc_dir , 'bin' , 'protoc' )
130- env ['PYTHON_ROOT' ] = self .ctx .get_python_install_dir ()
131121 env ['TARGET_OS' ] = 'OS_ANDROID_CROSSCOMPILE'
132122 env ['CFLAGS' ] += (
133123 ' -I' + self .ctx .ndk_dir + '/platforms/android-' +
@@ -136,17 +126,17 @@ def get_recipe_env(self, arch):
136126 ' -I' + self .ctx .ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' +
137127 self .ctx .toolchain_version + '/include' +
138128 ' -I' + self .ctx .ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' +
139- self .ctx .toolchain_version + '/libs/' + arch .arch + '/include' +
140- ' -I' + env ['PYTHON_ROOT ' ] + '/include/python2.7' )
129+ self .ctx .toolchain_version + '/libs/' + arch .arch + '/include' )
130+ env ['CFLAGS ' ] += ' -std=gnu++11'
141131 env ['CXXFLAGS' ] = env ['CFLAGS' ]
142132 env ['CXXFLAGS' ] += ' -frtti'
143133 env ['CXXFLAGS' ] += ' -fexceptions'
144134 env ['LDFLAGS' ] += (
145135 ' -L' + self .ctx .ndk_dir +
146136 '/sources/cxx-stl/gnu-libstdc++/' + self .ctx .toolchain_version +
147- '/libs/' + arch .arch + ' -lgnustl_shared -lpython2.7 -landroid -llog' )
137+ '/libs/' + arch .arch )
138+ env ['LIBS' ] = env .get ('LIBS' , '' ) + ' -lgnustl_shared -landroid -llog'
148139
149- env ['LDSHARED' ] = env ['CC' ] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
150140 return env
151141
152142
0 commit comments