Skip to content

Commit 01dc4b4

Browse files
committed
Terrible hacks to make python3 work
1 parent 3f0fea9 commit 01dc4b4

File tree

10 files changed

+83
-26
lines changed

10 files changed

+83
-26
lines changed

pythonforandroid/archs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def get_env(self):
7272
env['AR'] = '{}-ar'.format(command_prefix)
7373
env['RANLIB'] = '{}-ranlib'.format(command_prefix)
7474
env['LD'] = '{}-ld'.format(command_prefix)
75+
# env['LDSHARED'] = join(self.ctx.root_dir, 'tools', 'liblink-jb')
76+
env['LDSHARED'] = env['LD']
7577
env['STRIP'] = '{}-strip --strip-unneeded'.format(command_prefix)
7678
env['MAKE'] = 'make -j5'
7779
env['READELF'] = '{}-readelf'.format(command_prefix)

pythonforandroid/bootstraps/sdl2/build/src/org/kivy/android/PythonActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
5555
SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", mFilesDirectory);
5656
SDLActivity.nativeSetEnv("ANDROID_APP_PATH", mFilesDirectory);
5757
SDLActivity.nativeSetEnv("PYTHONHOME", mFilesDirectory);
58-
SDLActivity.nativeSetEnv("", mFilesDirectory + ":" + mFilesDirectory + "/lib");
58+
SDLActivity.nativeSetEnv("PYTHONPATH", mFilesDirectory + ":" + mFilesDirectory + "/lib");
5959

6060

6161
// nativeSetEnv("ANDROID_ARGUMENT", getFilesDir());

pythonforandroid/bootstraps/sdl2python3/build/jni/Application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# APP_STL := stlport_static
55

66
# APP_ABI := armeabi armeabi-v7a x86
7-
APP_ABI := armeabi
7+
APP_ABI := $(ARCH)

pythonforandroid/build.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ def ndk_ver(self, value):
130130
def ndk_is_crystax(self):
131131
return True if self.ndk_ver[:7] == 'crystax' else False
132132

133+
def ensure_crystax_python_install_dir(self):
134+
dirn = self.get_python_install_dir()
135+
ensure_dir(dirn)
136+
ensure_dir(join(dirn, 'lib'))
137+
sh.cp('-r', '/home/asandy/kivytest/crystax_stdlib', join(dirn, 'lib', 'python3.5'))
138+
sh.cp('-r', '/home/asandy/android/crystax-ndk-10.3.0/sources/python/3.5/libs/armeabi/modules', join(dirn, 'lib', 'python3.5', 'lib-dynload'))
139+
ensure_dir(join(dirn, 'lib', 'site-packages'))
140+
133141
@property
134142
def sdk_dir(self):
135143
'''The path to the Android SDK.'''
@@ -325,6 +333,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
325333
if cython:
326334
self.cython = cython
327335
break
336+
self.cython = 'cython'
328337
if not self.cython:
329338
ok = False
330339
warning("Missing requirement: cython is not installed")
@@ -466,6 +475,8 @@ def get_site_packages_dir(self, arch=None):
466475
# AND: This *must* be replaced with something more general in
467476
# order to support multiple python versions and/or multiple
468477
# archs.
478+
if self.ndk_is_crystax:
479+
return self.get_python_install_dir()
469480
return join(self.get_python_install_dir(),
470481
'lib', 'python2.7', 'site-packages')
471482

@@ -538,7 +549,10 @@ def build_recipes(build_order, python_modules, ctx):
538549
# 4) biglink everything
539550
# AND: Should make this optional
540551
info_main('# Biglinking object files')
541-
biglink(ctx, arch)
552+
if not ctx.ndk_is_crystax:
553+
biglink(ctx, arch)
554+
else:
555+
info('NDK is crystax, skipping biglink (will this work?)')
542556

543557
# 5) postbuild packages
544558
info_main('# Postbuilding recipes')

pythonforandroid/recipe.py

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from os.path import join, dirname, isdir, exists, isfile
1+
from os.path import join, dirname, isdir, exists, isfile, split, realpath
22
import importlib
33
import zipfile
44
import glob
55
import sh
66
import shutil
7-
from os import listdir, unlink, environ, mkdir
7+
from os import listdir, unlink, environ, mkdir, curdir
88
from sys import stdout
99
try:
1010
from urlparse import urlparse
@@ -671,8 +671,30 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
671671
with current_directory(self.get_build_dir(arch.arch)):
672672
# hostpython = sh.Command(self.ctx.hostpython)
673673
hostpython = sh.Command(self.hostpython_location)
674+
hostpython = sh.Command('python3.5')
674675

675-
if self.call_hostpython_via_targetpython:
676+
677+
if self.ctx.ndk_is_crystax:
678+
hppath = join(dirname(self.hostpython_location), 'Lib',
679+
'site-packages')
680+
hpenv = env.copy()
681+
if 'PYTHONPATH' in hpenv:
682+
hpenv['PYTHONPATH'] = ':'.join([hppath] +
683+
hpenv['PYTHONPATH'].split(':'))
684+
else:
685+
hpenv['PYTHONPATH'] = hppath
686+
# hpenv['PYTHONHOME'] = self.ctx.get_python_install_dir()
687+
# shprint(hostpython, 'setup.py', 'build',
688+
# _env=hpenv, *self.setup_extra_args)
689+
shprint(hostpython, 'setup.py', 'install', '-O2',
690+
'--root={}'.format(self.ctx.get_python_install_dir()),
691+
'--install-lib=lib/python3.5/site-packages',
692+
_env=hpenv, *self.setup_extra_args)
693+
site_packages_dir = self.ctx.get_site_packages_dir()
694+
built_files = glob.glob(join('build', 'lib*', '*'))
695+
for filen in built_files:
696+
shprint(sh.cp, '-r', filen, join(site_packages_dir, split(filen)[-1]))
697+
elif self.call_hostpython_via_targetpython:
676698
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env,
677699
*self.setup_extra_args)
678700
else:
@@ -749,8 +771,13 @@ def build_arch(self, arch):
749771
def build_cython_components(self, arch):
750772
info('Cythonizing anything necessary in {}'.format(self.name))
751773
env = self.get_recipe_env(arch)
774+
# env['PYTHONHOME'] = self.ctx.get_python_install_dir()
775+
env['PYTHONPATH'] = '/usr/lib/python3.5/site-packages/:/usr/lib/python3.5'
752776
with current_directory(self.get_build_dir(arch.arch)):
753-
hostpython = sh.Command(self.ctx.hostpython)
777+
# hostpython = sh.Command(self.ctx.hostpython)
778+
hostpython = sh.Command('python3.5')
779+
shprint(hostpython, '-c', 'import sys; print(sys.path)', _env=env)
780+
print('cwd is', realpath(curdir))
754781
info('Trying first build of {} to get cython files: this is '
755782
'expected to fail'.format(self.name))
756783
try:
@@ -761,17 +788,19 @@ def build_cython_components(self, arch):
761788
info('{} first build failed (as expected)'.format(self.name))
762789

763790
info('Running cython where appropriate')
791+
# shprint(sh.find, self.get_build_dir(arch.arch), '-iname', '*.pyx',
792+
# '-exec', self.ctx.cython, '{}', ';', _env=env)
764793
shprint(sh.find, self.get_build_dir(arch.arch), '-iname', '*.pyx',
765-
'-exec', self.ctx.cython, '{}', ';', _env=env)
794+
'-exec', self.ctx.cython, '{}', ';')
766795
info('ran cython')
767796

768797
shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env,
769798
_tail=20, _critical=True, *self.setup_extra_args)
770799

771-
print('stripping')
772-
build_lib = glob.glob('./build/lib*')
773-
shprint(sh.find, build_lib[0], '-name', '*.o', '-exec',
774-
env['STRIP'], '{}', ';', _env=env)
800+
# print('stripping')
801+
# build_lib = glob.glob('./build/lib*')
802+
# shprint(sh.find, build_lib[0], '-name', '*.o', '-exec',
803+
# env['STRIP'], '{}', ';', _env=env)
775804
print('stripped!?')
776805
# exit(1)
777806

@@ -792,10 +821,12 @@ def build_cython_components(self, arch):
792821

793822
def get_recipe_env(self, arch):
794823
env = super(CythonRecipe, self).get_recipe_env(arch)
795-
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(
824+
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{} '.format(
796825
self.ctx.get_libs_dir(arch.arch) +
797-
'-L{}'.format(self.ctx.libs_dir))
798-
env['LDSHARED'] = join(self.ctx.root_dir, 'tools', 'liblink')
826+
' -L{} '.format(self.ctx.libs_dir)) + ' -L/home/asandy/.local/share/python-for-android/build/bootstrap_builds/sdl2python3crystax/libs/armeabi '
827+
# env['LDSHARED'] = join(self.ctx.root_dir, 'tools', 'liblink-jb')
828+
env['LDSHARED'] = env['CC'] + ' -shared'
829+
shprint(sh.whereis, env['LDSHARED'], _env=env)
799830
env['LIBLINK'] = 'NOTNONE'
800831
env['NDKPLATFORM'] = self.ctx.ndk_platform
801832

@@ -805,4 +836,7 @@ def get_recipe_env(self, arch):
805836
'objects_{}'.format(self.name))
806837
env['LIBLINK_PATH'] = liblink_path
807838
ensure_dir(liblink_path)
839+
840+
env['CFLAGS'] = '-I/home/asandy/android/crystax-ndk-10.3.0/sources/python/3.5/include/python ' + env['CFLAGS']
841+
808842
return env

pythonforandroid/recipes/hostpython3/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77

88
class Hostpython3Recipe(Recipe):
9-
version = '3.4.2'
10-
url = 'http://python.org/ftp/python/{version}/Python-{version}.tgz'
9+
version = '3.5'
10+
# url = 'http://python.org/ftp/python/{version}/Python-{version}.tgz'
11+
url = 'https://github.com/crystax/android-vendor-python-3-5/archive/master.zip'
1112
name = 'hostpython3'
1213

1314
conflicts = ['hostpython2']
@@ -17,13 +18,13 @@ class Hostpython3Recipe(Recipe):
1718
# shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),
1819
# join(self.get_build_dir('armeabi'), 'Modules', 'Setup'))
1920

20-
def build_armeabi(self):
21+
def build_arch(self, arch):
2122
# AND: Should use an i386 recipe system
2223
warning('Running hostpython build. Arch is armeabi! '
2324
'This is naughty, need to fix the Arch system!')
2425

2526
# AND: Fix armeabi again
26-
with current_directory(self.get_build_dir('armeabi')):
27+
with current_directory(self.get_build_dir(arch.arch)):
2728

2829
if exists('hostpython'):
2930
info('hostpython already exists, skipping build')
@@ -53,8 +54,8 @@ def build_armeabi(self):
5354
'hostpython build! Exiting.')
5455
exit(1)
5556

56-
self.ctx.hostpython = join(self.get_build_dir('armeabi'), 'hostpython')
57-
self.ctx.hostpgen = join(self.get_build_dir('armeabi'), 'hostpgen')
57+
self.ctx.hostpython = join(self.get_build_dir(arch.arch), 'hostpython')
58+
self.ctx.hostpgen = join(self.get_build_dir(arch.arch), 'hostpgen')
5859

5960

6061
recipe = Hostpython3Recipe()

pythonforandroid/recipes/kivy/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ class KivyRecipe(CythonRecipe):
1111
url = 'https://github.com/kivy/kivy/archive/{version}.zip'
1212
name = 'kivy'
1313

14-
depends = [('sdl2', 'pygame'), 'pyjnius']
14+
depends = [('sdl2', 'pygame', 'sdl2python3crystax'), 'pyjnius']
15+
16+
# patches = ['setargv.patch']
1517

1618
def get_recipe_env(self, arch):
1719
env = super(KivyRecipe, self).get_recipe_env(arch)
18-
if 'sdl2' in self.ctx.recipe_build_order:
20+
if ('sdl2' in self.ctx.recipe_build_order or 'sdl2python3crystax' in self.ctx.recipe_build_order):
1921
env['USE_SDL2'] = '1'
2022
env['KIVY_SDL2_PATH'] = ':'.join([
2123
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include'),

pythonforandroid/recipes/pyjnius/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ class PyjniusRecipe(CythonRecipe):
99
version = 'master'
1010
url = 'https://github.com/kivy/pyjnius/archive/{version}.zip'
1111
name = 'pyjnius'
12-
depends = ['python2', ('sdl2', 'sdl'), 'six']
12+
depends = [('python2', 'python3crystax'), ('sdl2', 'sdl', 'sdl2python3crystax'), 'six']
1313
site_packages_name = 'jnius'
1414

15-
patches = [('sdl2_jnienv_getter.patch', will_build('sdl2'))]
15+
patches = [('sdl2_jnienv_getter.patch', will_build('sdl2python3crystax')),
16+
'getenv.patch']
1617

1718
def postbuild_arch(self, arch):
1819
super(PyjniusRecipe, self).postbuild_arch(arch)

pythonforandroid/recipes/python3crystax/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def __init__(self, **kwargs):
1818
super(Python3Recipe, self).__init__(**kwargs)
1919
self.crystax = lambda *args: True if self.ctx.ndk_is_crystax else False
2020

21+
def prebuild_arch(self, arch):
22+
self.ctx.ensure_crystax_python_install_dir()
23+
2124
def build_arch(self, arch):
2225
info('doing nothing, the crystax python3 is included in the ndk!')
2326

pythonforandroid/recipes/six/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
class SixRecipe(PythonRecipe):
66
version = '1.9.0'
77
url = 'https://pypi.python.org/packages/source/s/six/six-{version}.tar.gz'
8-
depends = ['python2']
8+
depends = [('python2', 'python3crystax')]
99

1010
recipe = SixRecipe()

0 commit comments

Comments
 (0)