Skip to content

Commit ae6b409

Browse files
committed
Terrible hacks to make python3 work
1 parent aea6dbd commit ae6b409

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
@@ -84,6 +84,8 @@ def get_env(self):
8484
env['AR'] = '{}-ar'.format(command_prefix)
8585
env['RANLIB'] = '{}-ranlib'.format(command_prefix)
8686
env['LD'] = '{}-ld'.format(command_prefix)
87+
# env['LDSHARED'] = join(self.ctx.root_dir, 'tools', 'liblink-jb')
88+
env['LDSHARED'] = env['LD']
8789
env['STRIP'] = '{}-strip --strip-unneeded'.format(command_prefix)
8890
env['MAKE'] = 'make -j5'
8991
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
@@ -60,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {
6060
SDLActivity.nativeSetEnv("ANDROID_ARGUMENT", mFilesDirectory);
6161
SDLActivity.nativeSetEnv("ANDROID_APP_PATH", mFilesDirectory);
6262
SDLActivity.nativeSetEnv("PYTHONHOME", mFilesDirectory);
63-
SDLActivity.nativeSetEnv("", mFilesDirectory + ":" + mFilesDirectory + "/lib");
63+
SDLActivity.nativeSetEnv("PYTHONPATH", mFilesDirectory + ":" + mFilesDirectory + "/lib");
6464

6565

6666
// 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.'''
@@ -332,6 +340,7 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
332340
if cython:
333341
self.cython = cython
334342
break
343+
self.cython = 'cython'
335344
if not self.cython:
336345
ok = False
337346
warning("Missing requirement: cython is not installed")
@@ -476,6 +485,8 @@ def get_site_packages_dir(self, arch=None):
476485
# AND: This *must* be replaced with something more general in
477486
# order to support multiple python versions and/or multiple
478487
# archs.
488+
if self.ndk_is_crystax:
489+
return self.get_python_install_dir()
479490
return join(self.get_python_install_dir(),
480491
'lib', 'python2.7', 'site-packages')
481492

@@ -549,7 +560,10 @@ def build_recipes(build_order, python_modules, ctx):
549560
# 4) biglink everything
550561
# AND: Should make this optional
551562
info_main('# Biglinking object files')
552-
biglink(ctx, arch)
563+
if not ctx.ndk_is_crystax:
564+
biglink(ctx, arch)
565+
else:
566+
info('NDK is crystax, skipping biglink (will this work?)')
553567

554568
# 5) postbuild packages
555569
info_main('# Postbuilding recipes')

pythonforandroid/recipe.py

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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
from six import PY2
66

77
import sh
88
import shutil
9-
from os import listdir, unlink, environ, mkdir
9+
from os import listdir, unlink, environ, mkdir, curdir
1010
from sys import stdout
1111
try:
1212
from urlparse import urlparse
@@ -715,8 +715,30 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
715715
with current_directory(self.get_build_dir(arch.arch)):
716716
# hostpython = sh.Command(self.ctx.hostpython)
717717
hostpython = sh.Command(self.hostpython_location)
718+
hostpython = sh.Command('python3.5')
718719

719-
if self.call_hostpython_via_targetpython:
720+
721+
if self.ctx.ndk_is_crystax:
722+
hppath = join(dirname(self.hostpython_location), 'Lib',
723+
'site-packages')
724+
hpenv = env.copy()
725+
if 'PYTHONPATH' in hpenv:
726+
hpenv['PYTHONPATH'] = ':'.join([hppath] +
727+
hpenv['PYTHONPATH'].split(':'))
728+
else:
729+
hpenv['PYTHONPATH'] = hppath
730+
# hpenv['PYTHONHOME'] = self.ctx.get_python_install_dir()
731+
# shprint(hostpython, 'setup.py', 'build',
732+
# _env=hpenv, *self.setup_extra_args)
733+
shprint(hostpython, 'setup.py', 'install', '-O2',
734+
'--root={}'.format(self.ctx.get_python_install_dir()),
735+
'--install-lib=lib/python3.5/site-packages',
736+
_env=hpenv, *self.setup_extra_args)
737+
site_packages_dir = self.ctx.get_site_packages_dir()
738+
built_files = glob.glob(join('build', 'lib*', '*'))
739+
for filen in built_files:
740+
shprint(sh.cp, '-r', filen, join(site_packages_dir, split(filen)[-1]))
741+
elif self.call_hostpython_via_targetpython:
720742
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env,
721743
*self.setup_extra_args)
722744
else:
@@ -793,8 +815,13 @@ def build_arch(self, arch):
793815
def build_cython_components(self, arch):
794816
info('Cythonizing anything necessary in {}'.format(self.name))
795817
env = self.get_recipe_env(arch)
818+
# env['PYTHONHOME'] = self.ctx.get_python_install_dir()
819+
env['PYTHONPATH'] = '/usr/lib/python3.5/site-packages/:/usr/lib/python3.5'
796820
with current_directory(self.get_build_dir(arch.arch)):
797-
hostpython = sh.Command(self.ctx.hostpython)
821+
# hostpython = sh.Command(self.ctx.hostpython)
822+
hostpython = sh.Command('python3.5')
823+
shprint(hostpython, '-c', 'import sys; print(sys.path)', _env=env)
824+
print('cwd is', realpath(curdir))
798825
info('Trying first build of {} to get cython files: this is '
799826
'expected to fail'.format(self.name))
800827
try:
@@ -805,17 +832,19 @@ def build_cython_components(self, arch):
805832
info('{} first build failed (as expected)'.format(self.name))
806833

807834
info('Running cython where appropriate')
835+
# shprint(sh.find, self.get_build_dir(arch.arch), '-iname', '*.pyx',
836+
# '-exec', self.ctx.cython, '{}', ';', _env=env)
808837
shprint(sh.find, self.get_build_dir(arch.arch), '-iname', '*.pyx',
809-
'-exec', self.ctx.cython, '{}', ';', _env=env)
838+
'-exec', self.ctx.cython, '{}', ';')
810839
info('ran cython')
811840

812841
shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env,
813842
_tail=20, _critical=True, *self.setup_extra_args)
814843

815-
print('stripping')
816-
build_lib = glob.glob('./build/lib*')
817-
shprint(sh.find, build_lib[0], '-name', '*.o', '-exec',
818-
env['STRIP'], '{}', ';', _env=env)
844+
# print('stripping')
845+
# build_lib = glob.glob('./build/lib*')
846+
# shprint(sh.find, build_lib[0], '-name', '*.o', '-exec',
847+
# env['STRIP'], '{}', ';', _env=env)
819848
print('stripped!?')
820849
# exit(1)
821850

@@ -836,10 +865,12 @@ def build_cython_components(self, arch):
836865

837866
def get_recipe_env(self, arch):
838867
env = super(CythonRecipe, self).get_recipe_env(arch)
839-
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(
868+
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{} '.format(
840869
self.ctx.get_libs_dir(arch.arch) +
841-
'-L{}'.format(self.ctx.libs_dir))
842-
env['LDSHARED'] = join(self.ctx.root_dir, 'tools', 'liblink')
870+
' -L{} '.format(self.ctx.libs_dir)) + ' -L/home/asandy/.local/share/python-for-android/build/bootstrap_builds/sdl2python3crystax/libs/armeabi '
871+
# env['LDSHARED'] = join(self.ctx.root_dir, 'tools', 'liblink-jb')
872+
env['LDSHARED'] = env['CC'] + ' -shared'
873+
shprint(sh.whereis, env['LDSHARED'], _env=env)
843874
env['LIBLINK'] = 'NOTNONE'
844875
env['NDKPLATFORM'] = self.ctx.ndk_platform
845876

@@ -849,4 +880,7 @@ def get_recipe_env(self, arch):
849880
'objects_{}'.format(self.name))
850881
env['LIBLINK_PATH'] = liblink_path
851882
ensure_dir(liblink_path)
883+
884+
env['CFLAGS'] = '-I/home/asandy/android/crystax-ndk-10.3.0/sources/python/3.5/include/python ' + env['CFLAGS']
885+
852886
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)