1
1
from pythonforandroid .recipe import PythonRecipe
2
2
from pythonforandroid .logger import shprint , info_notify
3
3
from pythonforandroid .util import current_directory , shutil
4
- from os .path import exists , join , dirname
4
+ from os .path import exists , join
5
5
import sh
6
6
from multiprocessing import cpu_count
7
7
from pythonforandroid .toolchain import info
11
11
12
12
class ProtobufCppRecipe (PythonRecipe ):
13
13
name = 'protobuf_cpp'
14
- version = '3.5 .1'
14
+ version = '3.6 .1'
15
15
url = 'https://github.com/google/protobuf/releases/download/v{version}/protobuf-python-{version}.tar.gz'
16
16
call_hostpython_via_targetpython = False
17
17
depends = ['cffi' , 'setuptools' ]
@@ -20,6 +20,12 @@ class ProtobufCppRecipe(PythonRecipe):
20
20
21
21
def prebuild_arch (self , arch ):
22
22
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
+
23
29
# During building, host needs to transpile .proto files to .py
24
30
# ideally with the same version as protobuf runtime, or with an older one.
25
31
# Because protoc is compiled for target (i.e. Android), we need an other binary
@@ -100,34 +106,18 @@ def install_python_package(self, arch):
100
106
with current_directory (join (self .get_build_dir (arch .arch ), 'python' )):
101
107
hostpython = sh .Command (self .hostpython_location )
102
108
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 )
124
115
125
116
def get_recipe_env (self , arch ):
126
117
env = super (ProtobufCppRecipe , self ).get_recipe_env (arch )
127
118
if self .protoc_dir is not None :
128
119
# we need protoc with binary for host platform
129
120
env ['PROTOC' ] = join (self .protoc_dir , 'bin' , 'protoc' )
130
- env ['PYTHON_ROOT' ] = self .ctx .get_python_install_dir ()
131
121
env ['TARGET_OS' ] = 'OS_ANDROID_CROSSCOMPILE'
132
122
env ['CFLAGS' ] += (
133
123
' -I' + self .ctx .ndk_dir + '/platforms/android-' +
@@ -136,17 +126,17 @@ def get_recipe_env(self, arch):
136
126
' -I' + self .ctx .ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' +
137
127
self .ctx .toolchain_version + '/include' +
138
128
' -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'
141
131
env ['CXXFLAGS' ] = env ['CFLAGS' ]
142
132
env ['CXXFLAGS' ] += ' -frtti'
143
133
env ['CXXFLAGS' ] += ' -fexceptions'
144
134
env ['LDFLAGS' ] += (
145
135
' -L' + self .ctx .ndk_dir +
146
136
'/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'
148
139
149
- env ['LDSHARED' ] = env ['CC' ] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
150
140
return env
151
141
152
142
0 commit comments