8000 Fixed some problems with distribute (but not all) · kivy/python-for-android@4c8b5bc · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c8b5bc

Browse files
committed
Fixed some problems with distribute (but not all)
1 parent 2680591 commit 4c8b5bc

File tree

2 files changed

+< 8000 !-- -->123
-6
lines changed

2 files changed

+123
-6
lines changed

recipes/python2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def build_armeabi(self):
8888
shprint(make, '-j5', 'install', 'HOSTPYTHON={}'.format(self.ctx.hostpython),
8989
'HOSTPGEN={}'.format(self.ctx.hostpgen),
9090
'CROSS_COMPILE_TARGET=yes',
91-
'INSTONAME=libpython2.7.so',
91+
'INSTSONAME=libpython2.7.so',
9292
_env=env)
9393

9494
if uname()[0] == 'Darwin':

toolchain.py

Lines changed: 122 additions & 5 deletions
23D3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import importlib
1818
import io
1919
import json
20+
import glob
2021
import shutil
2122
import fnmatch
2223
import re
@@ -61,6 +62,24 @@ def get_directory(filename):
6162
return basename(filename[:-4])
6263
print('Unknown file extension for {}'.format(filename))
6364
exit(1)
65+
66+
def which(program, path_env):
67+
import os
68+
def is_exe(fpath):
69+
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
70+
71+
fpath, fname = os.path.split(program)
72+
if fpath:
73+
if is_exe(program):
74+
return program
75+
else:
76+
for path in path_env.split(os.pathsep):
77+
path = path.strip('"')
78+
exe_file = os.path.join(path, program)
79+
if is_exe(exe_file):
80+
return exe_file
81+
82+
return None
6483

6584

6685
import contextlib
@@ -538,11 +557,17 @@ def prepare_build_dir(self):
538557
def prepare_dist_dir(self, name):
539558
self.dist_dir = join(self.ctx.dist_dir, name + '_' +
540559
self.bootstrap_template_dir)
541-
shprint(sh.cp, '-r',
542-
join(self.ctx.root_dir,
543-
'bootstrap_templates',
544-
self.bootstrap_template_dir),
545-
self.dist_dir)
560+
# shprint(sh.cp, '-r',
561+
# join(self.ctx.root_dir,
562+
# 'bootstrap_templates',
563+
# self.bootstrap_template_dir),
564+
# self.dist_dir)
565+
ensure_dir(self.dist_dir)
566+
567+
def run_distribute(self):
568+
print('Running distribute')
569+
print('Default bootstrap being used doesn\'t know how to distribute...failing.')
570+
exit(1)
546571

547572

548573
class PygameBootstrap(Bootstrap):
@@ -551,6 +576,96 @@ class PygameBootstrap(Bootstrap):
551576
recipe_depends = ['hostpython2', 'python2', 'pyjnius', 'sdl', 'pygame',
552577
'android', 'kivy']
553578

579+
def run_distribute(self):
580+
print('Running distribute!')
581+
582+
src_path = join(self.ctx.root_dir, 'bootstrap_templates',
583+
self.bootstrap_template_dir)
584+
585+
with current_directory(self.dist_dir):
586+
587+
print('Creating initial layout')
588+
for dirname in ('assets', 'bin', 'private', 'res', 'templates'):
589+
if not exists(dirname):
590+
shprint(sh.mkdir, dirname)
591+
592+
print('Copying default files')
593+
shprint(sh.cp, '-a', join(src_path, 'default.properties'), '.')
594+
shprint(sh.cp, '-a', join(src_path, 'local.properties'), '.')
595+
shprint(sh.cp, '-a', join(src_path, 'build.py'), '.')
596+
shprint(sh.cp, '-a', join(src_path, 'buildlib'), '.')
597+
shprint(sh.cp, '-a', join(src_path, 'src'), '.')
598+
shprint(sh.cp, '-a', join(src_path, 'templates'), '.')
599+
shprint(sh.cp, '-a', join(src_path, 'res'), '.')
600+
shprint(sh.cp, '-a', join(src_path, 'blacklist.txt'), '.')
601+
shprint(sh.cp, '-a', join(src_path, 'whitelist.txt'), '.')
602+
603+
print('Copying python distribution')
604+
hostpython = sh.Command(self.ctx.hostpython)
605+
shprint(hostpython, '-OO', '-m', 'compileall', join(self.ctx.build_dir, 'python-install'))
606+
if not exists('python-install'):
607+
shprint(sh.cp, '-a', join(self.ctx.build_dir, 'python-install'), '.')
608+
609+
print('Copying libs')
610+
# AND: Hardcoding armeabi - naughty!
611+
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
612+
for lib in glob.glob(join(self.ctx.libs_dir, '*')):
613+
shprint(sh.cp, '-a', lib, join('libs', 'armeabi'))
614+
615+
print('Copying java files')
616+
for filename in glob.glob(join(self.ctx.build_dir, 'java', '*')):
617+
shprint(sh.cp, '-a', filename, 'src')
618+
619+
print('Filling private directory')
620+
if not exists(join('private', 'lib')):
621+
shprint(sh.cp, '-a', join('python-install', 'lib'), 'private')
622+
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))
623+
624+
# AND: Copylibs stuff should go here
625+
shprint(sh.mv, join('libs', 'armeabi', 'libpymodules.so'), 'private/')
626+
shprint(sh.cp, join('python-install', 'include' , 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))
627+
628+
print('Remove some unwanted files')
629+
shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so'))
630+
shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig'))
631+
632+
with current_directory(join(self.dist_dir, 'private', 'lib', 'python2.7')):
633+
# shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.')))
634+
removes = []
635+
for dirname, something, filens in walk('.'):
636+
for filename in filens:
637+
for suffix in ('py', 'pyc', 'so.o', 'so.a', 'so.libs'):
638+
if filename.endswith(suffix):
639+
removes.append(filename)
640+
shprint(sh.rm, '-f', *removes)
641+
642+
print('Deleting some other stuff not used on android')
643+
# To quote the original distribute.sh, 'well...'
644+
shprint(sh.rm, '-rf', 'ctypes')
645+
shprint(sh.rm, '-rf', 'lib2to3')
646+
shprint(sh.rm, '-rf', 'idlelib')
647+
for filename in glob.glob('config/libpython*.a'):
648+
shprint(sh.rm, '-f', filename)
649+
shprint(sh.rm, '-rf', 'config/python.o')
650+
shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so')
651+
shprint(sh.rm, '-rf', 'lib-dynloat/_testcapi.so')
652+
653+
654+
print('Stripping libraries')
655+
env = ArchAndroid(self.ctx).get_env()
656+
print('env is', env)
657+
strip = which('arm-linux-androideabi-strip', env['PATH'])
658+
if strip is None:
659+
print('Can\'t find strip in PATH...')
660+
strip = sh.Command(strip)
661+
filens = shprint(sh.find, join(self.dist_dir, 'private'), join(self.dist_dir, 'libs'),
662+
'-iname', '*.so', _env=env).stdout
663+
for filen in filens.split('\n'):
664+
try:
665+
shprint(strip, filen, _env=env)
666+
except sh.ErrorReturnCode_1:
667+
print('Something went wrong with strip...not sure if this is important.')
668+
554669

555670

556671
class Recipe(object):
@@ -1472,6 +1587,8 @@ def create_android_project(self):
14721587

14731588
run_pymodules_install([])
14741589

1590+
ctx.bootstrap.run_distribute()
1591+
14751592
print('Done building recipes, exiting for now.')
14761593
return
14771594

0 commit comments

Comments
 (0)
0