|
1 | 1 | from pythonforandroid.toolchain import Bootstrap, current_directory, info, info_main, shprint |
| 2 | +from pythonforandroid.util import ensure_dir |
2 | 3 | from os.path import join, exists |
3 | | -from os import walk |
4 | | -import glob |
5 | 4 | import sh |
6 | 5 |
|
7 | 6 |
|
8 | 7 | class PygameBootstrap(Bootstrap): |
9 | 8 | name = 'pygame' |
10 | 9 |
|
11 | | - recipe_depends = ['hostpython2', 'python2', 'pyjnius', 'sdl', 'pygame', |
12 | | - 'android', 'kivy'] |
| 10 | + recipe_depends = ['hostpython2legacy', 'python2legacy', 'pyjnius', |
| 11 | + 'sdl', 'pygame', 'android', 'kivy'] |
13 | 12 |
|
14 | 13 | def run_distribute(self): |
15 | 14 | info_main('# Creating Android project from build and {} bootstrap'.format( |
@@ -45,53 +44,30 @@ def run_distribute(self): |
45 | 44 | fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir)) |
46 | 45 |
|
47 | 46 | info('Copying python distribution') |
48 | | - hostpython = sh.Command(self.ctx.hostpython) |
49 | | - try: |
50 | | - shprint(hostpython, '-OO', '-m', 'compileall', self.ctx.get_python_install_dir(), |
51 | | - _tail=10, _filterout="^Listing") |
52 | | - except sh.ErrorReturnCode: |
53 | | - pass |
54 | | - if not exists('python-install'): |
55 | | - shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install') |
56 | | - |
57 | | - self.distribute_libs(arch, [join(self.build_dir, 'libs', arch.arch), self.ctx.get_libs_dir(arch.arch)]) |
| 47 | + |
| 48 | + python_bundle_dir = join('_python_bundle', '_python_bundle') |
| 49 | + if 'python2legacy' in self.ctx.recipe_build_order: |
| 50 | + # a special case with its own packaging location |
| 51 | + python_bundle_dir = 'private' |
| 52 | + # And also must had an install directory, make sure of that |
| 53 | + self.ctx.python_recipe.create_python_install(self.dist_dir) |
| 54 | + |
| 55 | + self.distribute_libs( |
| 56 | + arch, [join(self.build_dir, 'libs', arch.arch), |
| 57 | + self.ctx.get_libs_dir(arch.arch)]) |
58 | 58 | self.distribute_aars(arch) |
59 | 59 | self.distribute_javaclasses(self.ctx.javaclass_dir) |
60 | 60 |
|
61 | | - info('Filling private directory') |
62 | | - if not exists(join('private', 'lib')): |
63 | | - shprint(sh.cp, '-a', join('python-install', 'lib'), 'private') |
64 | | - shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7')) |
65 | | - |
66 | | - shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/') |
67 | | - shprint(sh.cp, join('python-install', 'include', 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/')) |
68 | | - |
69 | | - info('Removing some unwanted files') |
70 | | - shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so')) |
71 | | - shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig')) |
72 | | - |
73 | | - with current_directory(join(self.dist_dir, 'private', 'lib', 'python2.7')): |
74 | | - # shprint(sh.xargs, 'rm', sh.grep('-E', '*\.(py|pyx|so\.o|so\.a|so\.libs)$', sh.find('.'))) |
75 | | - removes = [] |
76 | | - for dirname, something, filens in walk('.'): |
77 | | - for filename in filens: |
78 | | - for suffix in ('py', 'pyc', 'so.o', 'so.a', 'so.libs'): |
79 | | - if filename.endswith(suffix): |
80 | | - removes.append(filename) |
81 | | - shprint(sh.rm, '-f', *removes) |
82 | | - |
83 | | - info('Deleting some other stuff not used on android') |
84 | | - # To quote the original distribute.sh, 'well...' |
85 | | - # shprint(sh.rm, '-rf', 'ctypes') |
86 | | - shprint(sh.rm, '-rf', 'lib2to3') |
87 | | - shprint(sh.rm, '-rf', 'idlelib') |
88 | | - for filename in glob.glob('config/libpython*.a'): |
89 | | - shprint(sh.rm, '-f', filename) |
90 | | - shprint(sh.rm, '-rf', 'config/python.o') |
91 | | - shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so') |
92 | | - shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so') |
| 61 | + ensure_dir(python_bundle_dir) |
| 62 | + site_packages_dir = self.ctx.python_recipe.create_python_bundle( |
| 63 | + join(self.dist_dir, python_bundle_dir), arch) |
| 64 | + |
| 65 | + if 'sqlite3' not in self.ctx.recipe_build_order: |
| 66 | + with open('blacklist.txt', 'a') as fileh: |
| 67 | + fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n') |
93 | 68 |
|
94 | 69 | self.strip_libraries(arch) |
| 70 | + self.fry_eggs(site_packages_dir) |
95 | 71 | super(PygameBootstrap, self).run_distribute() |
96 | 72 |
|
97 | 73 |
|
|
0 commit comments