|
| 1 | +from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, logger, info_main, which |
| 2 | +from os.path import join, exists |
| 3 | +from os import walk |
| 4 | +import glob |
| 5 | +import sh |
| 6 | + |
| 7 | +class SDL2Bootstrap(Bootstrap): |
| 8 | + name = 'sdl2python3' |
| 9 | + |
| 10 | + recipe_depends = ['sdl2python3', 'python3'] |
| 11 | + |
| 12 | + def run_distribute(self): |
| 13 | + info_main('# Creating Android project from build and {} bootstrap'.format( |
| 14 | + self.name)) |
| 15 | + |
| 16 | + info('This currently just copies the SDL2 build stuff straight from the build dir.') |
| 17 | + shprint(sh.rm, '-rf', self.dist_dir) |
| 18 | + shprint(sh.cp, '-r', self.build_dir, self.dist_dir) |
| 19 | + with current_directory(self.dist_dir): |
| 20 | + with open('local.properties', 'w') as fileh: |
| 21 | + fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir)) |
| 22 | + |
| 23 | + with current_directory(self.dist_dir): |
| 24 | + info('Copying python distribution') |
| 25 | + |
| 26 | + if not exists('private'): |
| 27 | + shprint(sh.mkdir, 'private') |
| 28 | + if not exists('assets'): |
| 29 | + shprint(sh.mkdir, 'assets') |
| 30 | + |
| 31 | + hostpython = sh.Command(self.ctx.hostpython) |
| 32 | + |
| 33 | + # AND: The compileall doesn't work with python3, tries to import a wrong-arch lib |
| 34 | + # shprint(hostpython, '-OO', '-m', 'compileall', join(self.ctx.build_dir, 'python-install')) |
| 35 | + if not exists('python-install'): |
| 36 | + shprint(sh.cp, '-a', join(self.ctx.build_dir, 'python-install'), '.') |
| 37 | + |
| 38 | + info('Copying libs') |
| 39 | + # AND: Hardcoding armeabi - naughty! |
| 40 | + shprint(sh.mkdir, '-p', join('libs', 'armeabi')) |
| 41 | + for lib in glob.glob(join(self.ctx.libs_dir, '*')): |
| 42 | + shprint(sh.cp, '-a', lib, join('libs', 'armeabi')) |
| 43 | + |
| 44 | + info('Copying java files') |
| 45 | + for filename in glob.glob(join(self.ctx.build_dir, 'java', '*')): |
| 46 | + shprint(sh.cp, '-a', filename, 'src') |
| 47 | + |
| 48 | + info('Filling private directory') |
| 49 | + if not exists(join('private', 'lib')): |
| 50 | + info('private/lib does not exist, making') |
| 51 | + shprint(sh.cp, '-a', join('python-install', 'lib'), 'private') |
| 52 | + shprint(sh.mkdir, '-p', join('private', 'include', 'python3.4m')) |
| 53 | + |
| 54 | + # AND: Copylibs stuff should go here |
| 55 | + if exists(join('libs', 'armeabi', 'libpymodules.so')): |
| 56 | + shprint(sh.mv, join('libs', 'armeabi', 'libpymodules.so'), 'private/') |
| 57 | + shprint(sh.cp, join('python-install', 'include' , 'python3.4m', 'pyconfig.h'), join('private', 'include', 'python3.4m/')) |
| 58 | + |
| 59 | + info('Removing some unwanted files') |
| 60 | + shprint(sh.rm, '-f', join('private', 'lib', 'libpython3.4m.so')) |
| 61 | + shprint(sh.rm, '-f', join('private', 'lib', 'libpython3.so')) |
| 62 | + shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig')) |
| 63 | + |
| 64 | + with current_directory(join(self.dist_dir, 'private', 'lib', 'python3.4')): |
| 65 | + # shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.'))) |
| 66 | + removes = [] |
| 67 | + for dirname, something, filens in walk('.'): |
| 68 | + for filename in filens: |
| 69 | + for suffix in ('py', 'pyc', 'so.o', 'so.a', 'so.libs'): |
| 70 | + if filename.endswith(suffix): |
| 71 | + removes.append(filename) |
| 72 | + shprint(sh.rm, '-f', *removes) |
| 73 | + |
| 74 | + info('Deleting some other stuff not used on android') |
| 75 | + # To quote the original distribute.sh, 'well...' |
| 76 | + # shprint(sh.rm, '-rf', 'ctypes') |
| 77 | + shprint(sh.rm, '-rf', 'lib2to3') |
| 78 | + shprint(sh.rm, '-rf', 'idlelib') |
| 79 | + for filename in glob.glob('config/libpython*.a'): |
| 80 | + shprint(sh.rm, '-f', filename) |
| 81 | + shprint(sh.rm, '-rf', 'config/python.o') |
| 82 | + # shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so') |
| 83 | + # shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so') |
| 84 | + |
| 85 | + |
| 86 | + info('Stripping libraries') |
| 87 | + env = ArchAndroid(self.ctx).get_env() |
| 88 | + strip = which('arm-linux-androideabi-strip', env['PATH']) |
| 89 | + if strip is None: |
| 90 | + warning('Can\'t find strip in PATH...') |
| 91 | + strip = sh.Command(strip) |
| 92 | + filens = shprint(sh.find, join(self.dist_dir, 'private'), join(self.dist_dir, 'libs'), |
| 93 | + '-iname', '*.so', _env=env).stdout.decode('utf-8') |
| 94 | + logger.info('Stripping libraries in private dir') |
| 95 | + for filen in filens.split('\n'): |
| 96 | + try: |
| 97 | + strip(filen, _env=env) |
| 98 | + except sh.ErrorReturnCode_1: |
| 99 | + logger.debug('Failed to strip ' + 'filen') |
| 100 | + super(SDL2Bootstrap, self).run_distribute() |
| 101 | + |
| 102 | +bootstrap = SDL2Bootstrap() |
0 commit comments