Skip to content

Commit 13b77da

Browse files
committed
sdl2/gradle: first version (not yet compiled) of a sdl2 build based on gradle
1 parent de3d353 commit 13b77da

Some content is hidden

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

54 files changed

+5933
-4
lines changed

pythonforandroid/bootstrap.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,21 @@ def get_bootstrap(cls, name, ctx):
190190
bootstrap.ctx = ctx
191191
return bootstrap
192192

193-
def distribute_libs(self, arch, src_dirs, wildcard='*'):
193+
def distribute_libs(self, arch, src_dirs, wildcard='*', dest_dir="libs"):
194194
'''Copy existing arch libs from build dirs to current dist dir.'''
195195
info('Copying libs')
196-
tgt_dir = join('libs', arch.arch)
196+
tgt_dir = join(dest_dir, arch.arch)
197197
ensure_dir(tgt_dir)
198198
for src_dir in src_dirs:
199199
for lib in glob.glob(join(src_dir, wildcard)):
200200
shprint(sh.cp, '-a', lib, tgt_dir)
201201

202-
def distribute_javaclasses(self, javaclass_dir):
202+
def distribute_javaclasses(self, javaclass_dir, dest_dir="src"):
203203
'''Copy existing javaclasses from build dir to current dist dir.'''
204204
info('Copying java files')
205+
ensure_dir(dest_dir)
205206
for filename in glob.glob(javaclass_dir):
206-
shprint(sh.cp, '-a', filename, 'src')
207+
shprint(sh.cp, '-a', filename, dest_dir)
207208

208209
def distribute_aars(self, arch):
209210
'''Process existing .aar bundles and copy to current dist dir.'''
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# coding=utf-8
2+
"""
3+
Bootstrap for SDL2, using gradlew for building
4+
==============================================
5+
6+
.. warning:: Experimental
7+
8+
Good point:
9+
- automatic dependencies management
10+
- no need to unpack aar
11+
12+
TODO:
13+
- test with crystax
14+
15+
"""
16+
17+
from pythonforandroid.toolchain import (
18+
Bootstrap, shprint, current_directory, info, warning, ArchARM, info_main)
19+
from pythonforandroid.utils import ensure_dir
20+
from os.path import join, exists, curdir, abspath
21+
from os import walk, makedirs
22+
import glob
23+
import sh
24+
25+
26+
EXCLUDE_EXTS = (".py", ".pyc", ".so.o", ".so.a", ".so.libs", ".pyx")
27+
28+
29+
class SDL2GradleBootstrap(Bootstrap):
30+
name = 'sdl2_gradle'
31+
32+
recipe_depends = ['sdl2', ('python2', 'python3crystax')]
33+
34+
def run_distribute(self):
35+
info_main("# Creating Android project ({})".format(self.name))
36+
37+
arch = self.ctx.archs[0]
38+
python_install_dir = self.ctx.get_python_install_dir()
39+
from_crystax = self.ctx.python_recipe.from_crystax
40+
crystax_python_dir = join("crystax_python", "crystax_python")
41+
42+
if len(self.ctx.archs) > 1:
43+
raise ValueError("SDL2/gradle support only one arch")
44+
45+
info("Copying SDL2/gradle build for {}".format(arch))
46+
shprint(sh.rm, "-rf", self.dist_dir)
47+
shprint(sh.cp, "-r", self.build_dir, self.dist_dir)
48+
49+
# either the build use environemnt variable (ANDROID_HOME)
50+
# or the local.properties if exists
51+
with current_directory(self.dist_dir):
52+
with open('local.properties', 'w') as fileh:
53+
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
54+
55+
with current_directory(self.dist_dir):
56+
info("Copying Python distribution")
57+
58+
if not exists("private") and not from_crystax:
59+
ensure_dir("private")
60+
if not exists("crystax_python") and from_crystax:
61+
ensure_dir(crystax_python_dir)
62+
63+
hostpython = sh.Command(self.ctx.hostpython)
64+
if not from_crystax:
65+
try:
66+
shprint(hostpython, '-OO', '-m', 'compileall',
67+
python_install_dir,
68+
_tail=10, _filterout="^Listing")
69+
except sh.ErrorReturnCode:
70+
pass
71+
if not exists('python-install'):
72+
shprint(
73+
sh.cp, '-a', python_install_dir, './python-install')
74+
75+
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)],
76+
dest_dir=join("src", "main", "jniLibs"))
77+
self.distribute_javaclasses(self.ctx.javaclass_dir,
78+
dest_dir=join("src", "main", "java"))
79+
80+
if not from_crystax:
81+
info("Filling private directory")
82+
if not exists(join("private", "lib")):
83+
info("private/lib does not exist, making")
84+
shprint(sh.cp, "-a",
85+
join("python-install", "lib"), "private")
86+
shprint(sh.mkdir, "-p",
87+
join("private", "include", "python2.7"))
88+
89+
# AND: Copylibs stuff should go here
90+
libpymodules_fn = join("libs", arch.arch, "libpymodules.so")
91+
if exists(libpymodules_fn):
92+
shprint(sh.mv, libpymodules_fn, 'private/')
93+
shprint(sh.cp,
94+
join('python-install', 'include',
95+
'python2.7', 'pyconfig.h'),
96+
join('private', 'include', 'python2.7/'))
97+
98+
info('Removing some unwanted files')
99+
shprint(sh.rm, '-f', join('private', 'lib', 'libpython2.7.so'))
100+
shprint(sh.rm, '-rf', join('private', 'lib', 'pkgconfig'))
101+
102+
libdir = join(self.dist_dir, 'private', 'lib', 'python2.7')
103+
site_packages_dir = join(libdir, 'site-packages')
104+
with current_directory(libdir):
105+
removes = []
106+
for dirname, root, filenames in walk("."):
107+
for filename in filenames:
108+
for suffix in EXCLUDE_EXTS:
109+
if filename.endswith(suffix):
110+
removes.append(filename)
111+
shprint(sh.rm, '-f', *removes)
112+
113+
info('Deleting some other stuff not used on android')
114+
# To quote the original distribute.sh, 'well...'
115+
shprint(sh.rm, '-rf', 'lib2to3')
116+
shprint(sh.rm, '-rf', 'idlelib')
117+
for filename in glob.glob('config/libpython*.a'):
118+
shprint(sh.rm, '-f', filename)
119+
shprint(sh.rm, '-rf', 'config/python.o')
120+
121+
else: # Python *is* loaded from crystax
122+
ndk_dir = self.ctx.ndk_dir
123+
py_recipe = self.ctx.python_recipe
124+
python_dir = join(ndk_dir, 'sources', 'python',
125+
py_recipe.version, 'libs', arch.arch)
126+
shprint(sh.cp, '-r', join(python_dir,
127+
'stdlib.zip'), crystax_python_dir)
128+
shprint(sh.cp, '-r', join(python_dir,
129+
'modules'), crystax_python_dir)
130+
shprint(sh.cp, '-r', self.ctx.get_python_install_dir(),
131+
crystax_python_dir)
132+
133+
info('Renaming .so files to reflect cross-compile')
134+
site_packages_dir = join(crystax_python_dir, "site-packages")
135+
find_ret = shprint(
136+
sh.find, site_packages_dir, '-iname', '*.so')
137+
filenames = find_ret.stdout.decode('utf-8').split('\n')[:-1]
138+
for filename in filenames:
139+
parts = filename.split('.')
140+
if len(parts) <= 2:
141+
continue
142+
shprint(sh.mv, filename, filename.split('.')[0] + '.so')
143+
site_packages_dir = join(abspath(curdir),
144+
site_packages_dir)
145+
if 'sqlite3' not in self.ctx.recipe_build_order:
146+
with open('blacklist.txt', 'a') as fileh:
147+
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
148+
149+
self.strip_libraries(arch)
150+
self.fry_eggs(site_packages_dir)
151+
super(SDL2GradleBootstrap, self).run_distribute()
152+
153+
154+
bootstrap = SDL2GradleBootstrap()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.gradle
2+
/build/
3+
4+
# Ignore Gradle GUI config
5+
gradle-app.setting
6+
7+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
8+
!gradle-wrapper.jar
9+
10+
# Cache of project
11+
.gradletasknamecache
12+
13+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
14+
# gradle/wrapper/gradle-wrapper.properties
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# prevent user to include invalid extensions
2+
*.apk
3+
*.pxd
4+
5+
# eggs
6+
*.egg-info
7+
8+
# unit test
9+
unittest/*
10+
11+
# python config
12+
config/makesetup
13+
14+
# unused kivy files (platform specific)
15+
kivy/input/providers/wm_*
16+
kivy/input/providers/mactouch*
17+
kivy/input/providers/probesysfs*
18+
kivy/input/providers/mtdev*
19+
kivy/input/providers/hidinput*
20+
kivy/core/camera/camera_videocapture*
21+
kivy/core/spelling/*osx*
22+
kivy/core/video/video_pyglet*
23+
kivy/tools
24+
kivy/tests/*
25+
kivy/*/*.h
26+
kivy/*/*.pxi
27+
28+
# unused encodings
29+
lib-dynload/*codec*
30+
encodings/cp*.pyo
31+
encodings/tis*
32+
encodings/shift*
33+
encodings/bz2*
34+
encodings/iso*
35+
encodings/undefined*
36+
encodings/johab*
37+
encodings/p*
38+
encodings/m*
39+
encodings/euc*
40+
encodings/k*
41+
encodings/unicode_internal*
42+
encodings/quo*
43+
encodings/gb*
44+
encodings/big5*
45+
encodings/hp*
46+
encodings/hz*
47+
48+
# unused python modules
49+
bsddb/*
50+
wsgiref/*
51+
hotshot/*
52+
pydoc_data/*
53+
tty.pyo
54+
anydbm.pyo
55+
nturl2path.pyo
56+
LICENCE.txt
57+
macurl2path.pyo
58+
dummy_threading.pyo
59+
audiodev.pyo
60+
antigravity.pyo
61+
dumbdbm.pyo
62+
sndhdr.pyo
63+
__phello__.foo.pyo
64+
sunaudio.pyo
65+
os2emxpath.pyo
66+
multiprocessing/dummy*
67+
68+
# unused binaries python modules
69+
lib-dynload/termios.so
70+
lib-dynload/_lsprof.so
71+
lib-dynload/*audioop.so
72+
lib-dynload/mmap.so
73+
lib-dynload/_hotshot.so
74+
lib-dynload/_heapq.so
75+
lib-dynload/_json.so
76+
lib-dynload/grp.so
77+
lib-dynload/resource.so
78+
lib-dynload/pyexpat.so
79+
lib-dynload/_ctypes_test.so
80+
lib-dynload/_testcapi.so
81+
82+
# odd files
83+
plat-linux3/regen

0 commit comments

Comments
 (0)