Skip to content

Commit 8d20800

Browse files
committed
Added bootstrap and recipes for python3 (unfinished!)
1 parent 543d35b commit 8d20800

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+6361
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Replace org.libsdl.app with the identifier of your game below, e.g.
3+
com.gamemaker.game
4+
-->
5+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
6+
package="org.kivy.android"
7+
android:versionCode="1"
8+
android:versionName="1.0"
9+
android:installLocation="auto">
10+
11+
<!-- Android 2.3.3 -->
12+
<uses-sdk android:minSdkVersion="12" android:targetSdkVersion="12" />
13+
14+
<!-- OpenGL ES 2.0 -->
15+
<uses-feature android:glEsVersion="0x00020000" />
16+
17+
<!-- Allow writing to external storage -->
18+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
19+
20+
<!-- Create a Java class extending SDLActivity and place it in a
21+
directory under src matching the package, e.g.
22+
src/com/gamemaker/game/MyGame.java
23+
24+
then replace "SDLActivity" with the name of your class (e.g. "MyGame")
25+
in the XML below.
26+
27+
An example Java class can be found in README-android.txt
28+
-->
29+
<application android:label="@string/app_name"
30+
android:icon="@drawable/icon"
31+
android:allowBackup="true"
32+
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
33+
android:hardwareAccelerated="true" >
34+
<activity android:name="org.kivy.android.PythonActivity"
35+
android:label="@string/app_name"
36+
android:configChanges="keyboardHidden|orientation"
37+
>
38+
<intent-filter>
39+
<action android:name="android.intent.action.MAIN" />
40+
<category android:name="android.intent.category.LAUNCHER" />
41+
</intent-filter>
42+
</activity>
43+
</application>
44+
45+
</manifest>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is used to override default values used by the Ant build system.
2+
#
3+
# This file must be checked into Version Control Systems, as it is
4+
# integral to the build system of your project.
5+
6+
# This file is only used by the Ant script.
7+
8+
# You can use this to override default values such as
9+
# 'source.dir' for the location of your java source folder and
10+
# 'out.dir' for the location of your output folder.
11+
12+
# You can also use it define how the release builds are signed by declaring
13+
# the following properties:
14+
# 'key.store' for the location of your keystore and
15+
# 'key.alias' for the name of the key to use.
16+
# The password will be asked during the build when you use the 'release' target.
17+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is used to override default values used by the Ant build system.
2+
#
3+
# This file must be checked in Version Control Systems, as it is
4+
# integral to the build system of your project.
5+
6+
# This file is only used by the Ant script.
7+
8+
# You can use this to override default values such as
9+
# 'source.dir' for the location of your java source folder and
10+
# 'out.dir' for the location of your output folder.
11+
12+
# You can also use it define how the release builds are signed by declaring
13+
# the following properties:
14+
# 'key.store' for the location of your keystore and
15+
# 'key.alias' for the name of the key to use.
16+
# The password will be asked during the build when you use the 'release' target.
17+

0 commit comments

Comments
 (0)