Skip to content

Commit 6c1c06a

Browse files
committed
Made pyjnius recipe work
1 parent ab5cbce commit 6c1c06a

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

recipes/pyjnius/__init__.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

2-
from toolchain import CythonRecipe, shprint
2+
from toolchain import CythonRecipe, shprint, ArchAndroid, current_directory
3+
import sh
4+
import glob
5+
from os.path import join
36

47

58
class PyjniusRecipe(CythonRecipe):
@@ -8,5 +11,45 @@ class PyjniusRecipe(CythonRecipe):
811
name = 'pyjnius'
912
depends = ['python2', 'sdl']
1013

14+
def build_armeabi(self):
15+
env = ArchAndroid(self.ctx).get_env()
16+
17+
env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(self.ctx.libs_dir)
18+
env['LDSHARED'] = env['LIBLINK']
19+
20+
# AND: Hack to make pyjnius setup.py detect android build
21+
env['NDKPLATFORM'] = 'NOTNONE'
22+
23+
with current_directory(self.get_actual_build_dir('armeabi')):
24+
hostpython = sh.Command(self.ctx.hostpython)
25+
26+
# First build is fake in order to generate files that will be cythonized
27+
print('First build attempt will fail as hostpython doesn\'t have cython available:')
28+
try:
29+
shprint(hostpython, 'setup.py', 'build_ext', _env=env)
30+
except sh.ErrorReturnCode_1:
31+
print('failed (as expected)')
32+
33+
34+
print('Running cython where appropriate')
35+
shprint(sh.find, self.get_actual_build_dir('armeabi'), '-iname', '*.pyx', '-exec',
36+
self.ctx.cython, '{}', ';', _env=env)
37+
print('ran cython')
38+
39+
print('testing')
40+
shprint(sh.echo, 'test', '')
41+
42+
shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env)
43+
44+
build_lib = glob.glob('./build/lib*')
45+
shprint(sh.find, build_lib[0], '-name', '"*.o"', '-exec',
46+
env['STRIP'], '{}', ';', _env=env)
47+
48+
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env)
49+
50+
shprint(sh.cp, '-a', join('jnius', 'src', 'org'), self.ctx.javaclass_dir)
51+
52+
53+
1154

1255
recipe = PyjniusRecipe()

recipes/python2/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def build_armeabi(self):
4040
print('sqlite or openssl support not yet enabled in python recipe')
4141
exit(1)
4242

43-
self.ctx.hostpython = join(self.ctx.build_dir, 'python-install',
44-
'bin', 'python.host')
45-
4643
if exists(join(self.ctx.libs_dir, 'libpython2.7.so')):
4744
print('libpython2.7.so already exists, skipping python build.')
45+
self.ctx.hostpython = join(self.ctx.build_dir, 'python-install',
46+
'bin', 'python.host')
47+
4848
return
4949

5050
with current_directory(self.get_actual_build_dir('armeabi')):

toolchain.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def shprint(command, *args, **kwargs):
4242
kwargs["_iter"] = True
4343
kwargs["_out_bufsize"] = 1
4444
kwargs["_err_to_out"] = True
45+
print('EXEC: ', command, *args)
4546
output = command(*args, **kwargs)
4647
for line in output:
4748
stdout.write(line)
@@ -261,7 +262,8 @@ def get_env(self):
261262

262263
# AND: This stuff is set elsewhere in distribute.sh. Does that matter?
263264
env['ARCH'] = self.arch
264-
env['LIBLINK_PATH'] = join(self.ctx.build_dir, 'other_builds')
265+
env['LIBLINK_PATH'] = join(self.ctx.build_dir, 'other_builds', 'objects')
266+
ensure_dir(env['LIBLINK_PATH']) # AND: This should be elsewhere
265267
env['LIBLINK'] = join(self.ctx.bootstrap.build_dir, 'tools', 'liblink')
266268
env['BIGLINK'] = join(self.ctx.bootstrap.build_dir, 'tools', 'biglink')
267269

@@ -353,6 +355,7 @@ class Context(object):
353355
build_dir = None # in which bootstraps are copied for building and recipes are built
354356
dist_dir = None # the Android project folder where everything ends up
355357
libs_dir = None
358+
javaclass_dir = None
356359
ccache = None # whether to use ccache
357360
cython = None # the cython interpreter name
358361

@@ -427,6 +430,7 @@ def __init__(self):
427430
# AND: Are the install_dir and include_dir the same for Android?
428431
self.install_dir = "{}/dist/root".format(self.root_dir)
429432
self.include_dir = "{}/dist/include".format(self.root_dir)
433+
self.javaclass_dir = join(self.build_dir, 'java')
430434
self.archs = (
431435
ArchAndroid(self), # AND: Just 32 bit for now?
432436
)
@@ -468,6 +472,7 @@ def __init__(self):
468472
ensure_dir(self.dist_dir)
469473
ensure_dir(self.install_dir)
470474
ensure_dir(self.libs_dir)
475+
ensure_dir(self.javaclass_dir)
471476

472477
ensure_dir(join(self.build_dir, 'bootstrap_builds'))
473478
ensure_dir(join(self.build_dir, 'other_builds')) # where everything else is built

0 commit comments

Comments
 (0)