Skip to content

Commit 43ce635

Browse files
committed
Made other recipe types build properly when using python3
This is just a preliminary, hacky implementation.
1 parent a99478d commit 43ce635

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
1212
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
1313
start.c
1414

15-
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS)
15+
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/include/python2.7 $(EXTRA_CFLAGS) -I$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/Include -I$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/android-build
1616

1717
LOCAL_SHARED_LIBRARIES := SDL2 python_shared
1818

19-
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS)
19+
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog $(EXTRA_LDLIBS) -lpython3.7m
2020

21-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
21+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/$(PYTHON2_NAME)/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS) -L$(LOCAL_PATH)/../../../../other_builds/python3/$(ARCH)/python3/android-build
2222

2323
include $(BUILD_SHARED_LIBRARY)
2424

pythonforandroid/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
355355
if not self.ccache:
356356
info('ccache is missing, the build will not be optimized in the '
357357
'future.')
358-
for cython_fn in ("cython2", "cython-2.7", "cython"):
358+
for cython_fn in ("cython", "cython3", "cython2", "cython-2.7"):
359359
cython = sh.which(cython_fn)
360360
if cython:
361361
self.cython = cython

pythonforandroid/recipe.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,9 @@ def real_hostpython_location(self):
742742
return join(
743743
Recipe.get_recipe('hostpython3crystax', self.ctx).get_build_dir(),
744744
'hostpython')
745+
elif 'hostpython3' in self.ctx.recipe_build_order:
746+
return join(Recipe.get_recipe('hostpython3', self.ctx).get_build_dir(),
747+
'native-build', 'python')
745748
else:
746749
python_recipe = self.ctx.python_recipe
747750
return 'python{}'.format(python_recipe.version)
@@ -785,15 +788,15 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
785788
join(ndk_dir_python, 'libs', arch.arch))
786789
env['LDFLAGS'] += ' -lpython{}m'.format(python_short_version)
787790
elif 'python3' in self.ctx.recipe_build_order:
788-
# This headers are unused cause python3 recipe was removed
789-
# TODO: should be reviewed when python3 recipe added
790-
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
791-
env['CFLAGS'] += ' -I' + env[
792-
'PYTHON_ROOT'] + '/include/python{}m'.format(
793-
python_short_version)
791+
# TODO: Make the recipe env get these details from the
792+
# python recipe instead of hardcoding
793+
env['PYTHON_ROOT'] = Recipe.get_recipe('python3', self.ctx).get_build_dir(arch.arch)
794+
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/Include'
794795
env['LDFLAGS'] += (
795-
' -L' + env['PYTHON_ROOT'] + '/lib' +
796-
' -lpython{}m'.format(python_short_version))
796+
' -L' +
797+
join(env['PYTHON_ROOT'], 'android-build') +
798+
' -lpython3.7m')
799+
797800
hppath = []
798801
hppath.append(join(dirname(self.hostpython_location), 'Lib'))
799802
hppath.append(join(hppath[0], 'site-packages'))
@@ -834,7 +837,8 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
834837
with current_directory(self.get_build_dir(arch.arch)):
835838
hostpython = sh.Command(self.hostpython_location)
836839

837-
if self.ctx.python_recipe.from_crystax:
840+
if (self.ctx.python_recipe.from_crystax or
841+
self.ctx.python_recipe.name == 'python3'):
838842
hpenv = env.copy()
839843
shprint(hostpython, 'setup.py', 'install', '-O2',
840844
'--root={}'.format(self.ctx.get_python_install_dir()),
@@ -1016,7 +1020,7 @@ def build_cython_components(self, arch):
10161020
shprint(sh.find, build_lib[0], '-name', '*.o', '-exec',
10171021
env['STRIP'], '{}', ';', _env=env)
10181022

1019-
if 'python3crystax' in self.ctx.recipe_build_order:
1023+
else: # python3crystax or python3
10201024
info('Stripping object files')
10211025
shprint(sh.find, '.', '-iname', '*.so', '-exec',
10221026
'/usr/bin/echo', '{}', ';', _env=env)
@@ -1060,8 +1064,8 @@ def get_recipe_env(self, arch, with_flags_in_cc=True):
10601064
if self.ctx.python_recipe.from_crystax:
10611065
env['LDFLAGS'] = (env['LDFLAGS'] +
10621066
' -L{}'.format(join(self.ctx.bootstrap.build_dir, 'libs', arch.arch)))
1063-
# ' -L/home/asandy/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi '
1064-
if self.ctx.python_recipe.from_crystax:
1067+
1068+
if self.ctx.python_recipe.from_crystax or self.ctx.python_recipe.name == 'python3':
10651069
env['LDSHARED'] = env['CC'] + ' -shared'
10661070
else:
10671071
env['LDSHARED'] = join(self.ctx.root_dir, 'tools', 'liblink.sh')

pythonforandroid/recipes/python3/__init__.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ def build_arch(self, arch):
8080

8181
env['SYSROOT'] = sysroot
8282

83-
print('CPPflags', env['CPPFLAGS'])
84-
print('LDFLAGS', env['LDFLAGS'])
85-
86-
print('LD is', env['LD'])
87-
8883
if not exists('config.status'):
8984
shprint(sh.Command(join(recipe_build_dir, 'configure')),
9085
*(' '.join(('--host={android_host}',
@@ -102,9 +97,11 @@ def build_arch(self, arch):
10297
prefix=sys_prefix,
10398
exec_prefix=sys_exec_prefix)).split(' '), _env=env)
10499

105-
import ipdb
106-
ipdb.set_trace()
100+
if not exists('python'):
101+
shprint(sh.make, 'all', _env=env)
107102

108-
shprint(sh.make, 'all', _env=env)
103+
# TODO: Look into passing the path to pyconfig.h in a
104+
# better way, although this is probably acceptable
105+
sh.cp('pyconfig.h', join(recipe_build_dir, 'Include'))
109106

110107
recipe = Python3Recipe()

0 commit comments

Comments
 (0)