Skip to content

Commit 6237346

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

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
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
@@ -348,7 +348,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
348348
if not self.ccache:
349349
info('ccache is missing, the build will not be optimized in the '
350350
'future.')
351-
for cython_fn in ("cython2", "cython-2.7", "cython"):
351+
for cython_fn in ("cython", "cython3", "cython2", "cython-2.7"):
352352
cython = sh.which(cython_fn)
353353
if cython:
354354
self.cython = cython

pythonforandroid/recipe.py

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

836-
if self.ctx.python_recipe.from_crystax:
839+
if (self.ctx.python_recipe.from_crystax or
840+
self.ctx.python_recipe.name == 'python3'):
837841
hpenv = env.copy()
838842
shprint(hostpython, 'setup.py', 'install', '-O2',
839843
'--root={}'.format(self.ctx.get_python_install_dir()),
@@ -1013,7 +1017,7 @@ def build_cython_components(self, arch):
10131017
shprint(sh.find, build_lib[0], '-name', '*.o', '-exec',
10141018
env['STRIP'], '{}', ';', _env=env)
10151019

1016-
if 'python3crystax' in self.ctx.recipe_build_order:
1020+
else: # python3crystax or python3
10171021
info('Stripping object files')
10181022
shprint(sh.find, '.', '-iname', '*.so', '-exec',
10191023
'/usr/bin/echo', '{}', ';', _env=env)
@@ -1057,8 +1061,8 @@ def get_recipe_env(self, arch, with_flags_in_cc=True):
10571061
if self.ctx.python_recipe.from_crystax:
10581062
env['LDFLAGS'] = (env['LDFLAGS'] +
10591063
' -L{}'.format(join(self.ctx.bootstrap.build_dir, 'libs', arch.arch)))
1060-
# ' -L/home/asandy/.local/share/python-for-android/build/bootstrap_builds/sdl2/libs/armeabi '
1061-
if self.ctx.python_recipe.from_crystax:
1064+
1065+
if self.ctx.python_recipe.from_crystax or self.ctx.python_recipe.name == 'python3':
10621066
env['LDSHARED'] = env['CC'] + ' -shared'
10631067
else:
10641068
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)