Skip to content

Commit ab8bf58

Browse files
author
bob
committed
recipes code cosmetic
1 parent 60acd88 commit ab8bf58

File tree

5 files changed

+132
-183
lines changed

5 files changed

+132
-183
lines changed
Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, logger, info_main, which
2-
from os.path import join, exists, basename, splitext
2+
from os.path import join, exists, basename
33
from os import walk
44
import glob
55
import sh
6-
from tempfile import mkdtemp
7-
from shutil import rmtree
86

97

108
class PygameBootstrap(Bootstrap):
@@ -21,6 +19,9 @@ def run_distribute(self):
2119
# self.name)
2220
src_path = join(self.bootstrap_dir, 'build')
2321

22+
# AND: Hardcoding armeabi - naughty!
23+
arch = ArchAndroid(self.ctx)
24+
2425
with current_directory(self.dist_dir):
2526

2627
info('Creating initial layout')
@@ -46,47 +47,9 @@ def run_distribute(self):
4647
if not exists('python-install'):
4748
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
4849

49-
info('Unpacking aars')
50-
for aar in glob.glob(join(self.ctx.aars_dir, '*.aar')):
51-
temp_dir = mkdtemp()
52-
name = splitext(basename(aar))[0]
53-
jar_name = name + '.jar'
54-
info("unpack {} jar".format(name))
55-
info(" from {}".format(aar))
56-
info(" to {}".format(temp_dir))
57-
shprint(sh.unzip, '-o', aar, '-d', temp_dir)
58-
59-
jar_src = join(temp_dir, 'classes.jar')
60-
jar_tgt = join('libs', jar_name)
61-
info("cp {} jar".format(name))
62-
info(" from {}".format(jar_src))
63-
info(" to {}".format(jar_tgt))
64-
shprint(sh.mkdir, '-p', 'libs')
65-
shprint(sh.cp, '-a',jar_src, jar_tgt)
66-
67-
so_src_dir = join(temp_dir, 'jni', 'armeabi')
68-
so_tgt_dir = join('libs', 'armeabi')
69-
info("cp {} .so".format(name))
70-
info(" from {}".format(so_src_dir))
71-
info(" to {}".format(so_tgt_dir))
72-
shprint(sh.mkdir, '-p', so_tgt_dir)
73-
so_files = glob.glob(join(so_src_dir, '*.so'))
74-
for f in so_files:
75-
shprint(sh.cp, '-a', f, so_tgt_dir)
76-
77-
rmtree(temp_dir)
78-
79-
info('Copying libs')
80-
# AND: Hardcoding armeabi - naughty!
81-
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
82-
for lib in glob.glob(join(self.build_dir, 'libs', 'armeabi', '*')):
83-
shprint(sh.cp, '-a', lib, join('libs', 'armeabi'))
84-
for lib in glob.glob(join(self.ctx.get_libs_dir('armeabi'), '*')):
85-
shprint(sh.cp, '-a', lib, join('libs', 'armeabi'))
86-
87-
info('Copying java files')
88-
for filename in glob.glob(self.ctx.javaclass_dir):
89-
shprint(sh.cp, '-a', filename, 'src')
50+
self.distribute_libs(arch, [join(self.build_dir, 'libs', arch.arch), self.ctx.get_libs_dir(arch.arch)]);
51+
self.distribute_aars(arch)
52+
self.distribute_javaclasses(self.ctx.javaclass_dir)
9053

9154
info('Filling private directory')
9255
if not exists(join('private', 'lib')):
@@ -123,21 +86,7 @@ def run_distribute(self):
12386
shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
12487

12588

126-
info('Stripping libraries')
127-
env = ArchAndroid(self.ctx).get_env()
128-
strip = which('arm-linux-androideabi-strip', env['PATH'])
129-
if strip is None:
130-
warning('Can\'t find strip in PATH...')
131-
strip = sh.Command(strip)
132-
filens = shprint(sh.find, join(self.dist_dir, 'private'), join(self.dist_dir, 'libs'),
133-
'-iname', '*.so', _env=env).stdout.decode('utf-8')
134-
logger.info('Stripping libraries in private dir')
135-
for filen in filens.split('\n'):
136-
try:
137-
strip(filen, _env=env)
138-
except sh.ErrorReturnCode_1:
139-
logger.debug('Failed to strip ' + 'filen')
140-
89+
self.strip_libraries(arch)
14190
super(PygameBootstrap, self).run_distribute()
14291

14392
bootstrap = PygameBootstrap()

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def run_distribute(self):
2222
with open('local.properties', 'w') as fileh:
2323
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
2424

25+
# AND: Hardcoding armeabi - naughty!
26+
arch = ArchAndroid(self.ctx)
27+
2528
with current_directory(self.dist_dir):
2629
info('Copying python distribution')
2730

@@ -37,45 +40,9 @@ def run_distribute(self):
3740
if not exists('python-install'):
3841
shprint(sh.cp, '-a', self.ctx.get_python_install_dir(), './python-install')
3942

40-
info('Unpacking aars')
41-
for aar in glob.glob(join(self.ctx.aars_dir, '*.aar')):
42-
temp_dir = mkdtemp()
43-
name = splitext(basename(aar))[0]
44-
jar_name = name + '.jar'
45-
info("unpack {} jar".format(name))
46-
info(" from {}".format(aar))
47-
info(" to {}".format(temp_dir))
48-
shprint(sh.unzip, '-o', aar, '-d', temp_dir)
49-
50-
jar_src = join(temp_dir, 'classes.jar')
51-
jar_tgt = join('libs', jar_name)
52-
info("cp {} jar".format(name))
53-
info(" from {}".format(jar_src))
54-
info(" to {}".format(jar_tgt))
55-
shprint(sh.mkdir, '-p', 'libs')
56-
shprint(sh.cp, '-a',jar_src, jar_tgt)
57-
58-
so_src_dir = join(temp_dir, 'jni', 'armeabi')
59-
so_tgt_dir = join('libs', 'armeabi')
60-
info("cp {} .so".format(name))
61-
info(" from {}".format(so_src_dir))
62-
info(" to {}".format(so_tgt_dir))
63-
shprint(sh.mkdir, '-p', so_tgt_dir)
64-
so_files = glob.glob(join(so_src_dir, '*.so'))
65-
for f in so_files:
66-
shprint(sh.cp, '-a', f, so_tgt_dir)
67-
68-
rmtree(temp_dir)
69-
70-
info('Copying libs')
71-
# AND: Hardcoding armeabi - naughty!
72-
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
73-
for lib in glob.glob(join(self.ctx.get_libs_dir('armeabi'), '*')):
74-
shprint(sh.cp, '-a', lib, join('libs', 'armeabi'))
75-
76-
info('Copying java files')
77-
for filename in glob.glob(self.ctx.javaclass_dir):
78-
shprint(sh.cp, '-a', filename, 'src')
43+
self.distribute_libs(arch, [self.ctx.get_libs_dir(arch.arch)])
44+
self.distribute_aars(arch)
45+
self.distribute_javaclasses(self.ctx.javaclass_dir)
7946

8047
info('Filling private directory')
8148
if not exists(join('private', 'lib')):
@@ -113,21 +80,7 @@ def run_distribute(self):
11380
# shprint(sh.rm, '-rf', 'lib-dynload/_ctypes_test.so')
11481
# shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
11582

116-
117-
info('Stripping libraries')
118-
env = ArchAndroid(self.ctx).get_env()
119-
strip = which('arm-linux-androideabi-strip', env['PATH'])
120-
if strip is None:
121-
warning('Can\'t find strip in PATH...')
122-
strip = sh.Command(strip)
123-
filens = shprint(sh.find, join(self.dist_dir, 'private'), join(self.dist_dir, 'libs'),
124-
'-iname', '*.so', _env=env).stdout.decode('utf-8')
125-
logger.info('Stripping libraries in private dir')
126-
for filen in filens.split('\n'):
127-
try:
128-
strip(filen, _env=env)
129-
except sh.ErrorReturnCode_1:
130-
logger.debug('Failed to strip ' + 'filen')
83+
self.strip_libraries(arch)
13184
super(SDL2Bootstrap, self).run_distribute()
13285

13386
bootstrap = SDL2Bootstrap()

pythonforandroid/bootstraps/sdl2python3/__init__.py

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ def run_distribute(self):
2424
with open('local.properties', 'w') as fileh:
2525
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
2626

27+
# AND: Hardcoding armeabi - naughty!
28+
arch = ArchAndroid(self.ctx)
29+
2730
with current_directory(self.dist_dir):
2831
info('Copying python distribution')
2932

@@ -39,45 +42,9 @@ def run_distribute(self):
3942
if not exists('python-install'):
4043
shprint(sh.cp, '-a', join(self.ctx.build_dir, 'python-install'), '.')
4144

42-
info('Unpacking aars')
43-
for aar in glob.glob(join(self.ctx.aars_dir, '*.aar')):
44-
temp_dir = mkdtemp()
45-
name = splitext(basename(aar))[0]
46-
jar_name = name + '.jar'
47-
info("unpack {} jar".format(name))
48-
info(" from {}".format(aar))
49-
info(" to {}".format(temp_dir))
50-
shprint(sh.unzip, '-o', aar, '-d', temp_dir)
51-
52-
jar_src = join(temp_dir, 'classes.jar')
53-
jar_tgt = join('libs', jar_name)
54-
info("cp {} jar".format(name))
55-
info(" from {}".format(jar_src))
56-
info(" to {}".format(jar_tgt))
57-
shprint(sh.mkdir, '-p', 'libs')
58-
shprint(sh.cp, '-a',jar_src, jar_tgt)
59-
60-
so_src_dir = join(temp_dir, 'jni', 'armeabi')
61-
so_tgt_dir = join('libs', 'armeabi')
62-
info("cp {} .so".format(name))
63-
info(" from {}".format(so_src_dir))
64-
info(" to {}".format(so_tgt_dir))
65-
shprint(sh.mkdir, '-p', so_tgt_dir)
66-
so_files = glob.glob(join(so_src_dir, '*.so'))
67-
for f in so_files:
68-
shprint(sh.cp, '-a', f, so_tgt_dir)
69-
70-
rmtree(temp_dir)
71-
72-
info('Copying libs')
73-
# AND: Hardcoding armeabi - naughty!
74-
shprint(sh.mkdir, '-p', join('libs', 'armeabi'))
75-
for lib in glob.glob(join(self.ctx.libs_dir, '*')):
76-
shprint(sh.cp, '-a', lib, join('libs', 'armeabi'))
77-
78-
info('Copying java files')
79-
for filename in glob.glob(join(self.ctx.build_dir, 'java', '*')):
80-
shprint(sh.cp, '-a', filename, 'src')
45+
self.distribute_libs(arch, [self.ctx.libs_dir])
46+
self.distribute_aars(arch)
47+
self.distribute_javaclasses(join(self.ctx.build_dir, 'java'))
8148

8249
info('Filling private directory')
8350
if not exists(join('private', 'lib')):
@@ -117,20 +84,7 @@ def run_distribute(self):
11784
# shprint(sh.rm, '-rf', 'lib-dynload/_testcapi.so')
11885

11986

120-
info('Stripping libraries')
121-
env = ArchAndroid(self.ctx).get_env()
122-
strip = which('arm-linux-androideabi-strip', env['PATH'])
123-
if strip is None:
124-
warning('Can\'t find strip in PATH...')
125-
strip = sh.Command(strip)
126-
filens = shprint(sh.find, join(self.dist_dir, 'private'), join(self.dist_dir, 'libs'),
127-
'-iname', '*.so', _env=env).stdout.decode('utf-8')
128-
logger.info('Stripping libraries in private dir')
129-
for filen in filens.split('\n'):
130-
try:
131-
strip(filen, _env=env)
132-
except sh.ErrorReturnCode_1:
133-
logger.debug('Failed to strip ' + 'filen')
87+
self.strip_libraries(arch)
13488
super(SDL2Bootstrap, self).run_distribute()
13589

13690
bootstrap = SDL2Bootstrap()
Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
from pythonforandroid.toolchain import Recipe, shprint, current_directory, info, warning
2-
from os.path import exists, join, expanduser, basename
1+
from pythonforandroid.toolchain import Recipe, shprint, current_directory, warning, info, debug
2+
from os.path import exists, join
33
from os import environ
44
import sh
5-
import glob
5+
from colorama import Fore, Style
66

77
class VlcRecipe(Recipe):
88
version = '3.0.0'
99
url = None
1010
name = 'vlc'
1111

12-
depends = ['pyjnius', 'android', 'kivy']
12+
depends = []
1313

1414
port_git = 'http://git.videolan.org/git/vlc-ports/android.git'
1515
vlc_git = 'http://git.videolan.org/git/vlc.git'
16+
ENV_LIBVLC_AAR = 'LIBVLC_AAR'
1617

1718
def prebuild_arch(self, arch):
1819
super(VlcRecipe, self).prebuild_arch(arch)
1920
build_dir = self.get_build_dir(arch.arch)
2021
port_dir = join(build_dir, 'vlc-port-android')
2122
aar_path = join(port_dir, 'libvlc', 'build', 'outputs', 'aar')
22-
aar = environ.get('LIBVLC_AAR',
23+
aar = environ.get(self.ENV_LIBVLC_AAR,
2324
join(aar_path, 'libvlc-{}.aar'.format(self.version)))
24-
jar = join(build_dir, 'libvlc.jar')
2525
if not exists(aar):
26-
if not environ.has_key('LIBVLC_AAR'):
27-
warning("set path to ready libvlc-<ver>.aar bundle in LIBVLC_AAR environment!")
26+
if environ.has_key(''):
27+
warning("Error: libvlc-<ver>.aar bundle not found in {}".format(aar))
28+
info("check {} environment!".format(self.ENV_LIBVLC_AAR))
29+
raise Exception("vlc .aar bundle not found by path specified in {}".format(self.ENV_LIBVLC_AAR))
30+
warning("set path to precompiled libvlc-<ver>.aar bundle in {} environment!".format(self.ENV_LIBVLC_AAR))
2831
info("libvlc-<ver>.aar for android not found!")
29-
info("should build sources at {}".format(port_dir))
32+
info("should build from sources at {}".format(port_dir))
3033
if not exists(join(port_dir, 'compile.sh')):
3134
info("clone vlc port for android sources from {}".format(self.port_git))
3235
shprint(sh.git, 'clone', self.port_git, port_dir)
@@ -40,9 +43,8 @@ def build_arch(self, arch):
4043
build_dir = self.get_build_dir(arch.arch)
4144
port_dir = join(build_dir, 'vlc-port-android')
4245
aar_path = join(port_dir, 'libvlc', 'build', 'outputs', 'aar')
43-
aar = environ.get('LIBVLC_AAR',
46+
aar = environ.get(self.ENV_LIBVLC_AAR,
4447
join(aar_path, 'libvlc-{}.aar'.format(self.version)))
45-
jar = join(build_dir, 'libvlc.jar')
4648
if not exists(aar):
4749
with current_directory(port_dir):
4850
env = dict(environ)
@@ -51,11 +53,24 @@ def build_arch(self, arch):
5153
'ANDROID_NDK': self.ctx.ndk_dir,
5254
'ANDROID_SDK': self.ctx.sdk_dir,
5355
})
54-
info("compile vlc from sources")
55-
info("environment: {}".format(env))
56-
if not exists(join(port_dir, 'bin', 'VLC-debug.apk')):
57-
shprint(sh.Command('./compile.sh'), _env=env)
58-
shprint(sh.Command('./compile-libvlc.sh'), _env=env)
56+
info("compiling vlc from sources")
57+
debug("environment: {}".format(env))
58+
try:
59+
if not exists(join(port_dir, 'bin', 'VLC-debug.apk')):
60+
shprint(sh.Command('./compile.sh'), _env=env)
61+
shprint(sh.Command('./compile-libvlc.sh'), _env=env)
62+
except sh.ErrorReturnCode_1, err:
63+
warning("Error: vlc compilation failed")
64+
lines = err.stdout.splitlines()
65+
N = 20
66+
if len(lines) <= N:
67+
info('STDOUT:\n{}\t{}{}'.format(Fore.YELLOW, '\t\n'.join(lines), Fore.RESET))
68+
else:
69+
info('STDOUT (last {} lines of {}):\n{}\t{}{}'.format(N, len(lines), Fore.YELLOW, '\t\n'.join(lines[-N:]), Fore.RESET))
70+
lines = err.stderr.splitlines()
71+
if len(lines):
72+
warning('STDERR:\n{}\t{}{}'.format(Fore.RED, '\t\n'.join(lines), Fore.RESET))
73+
raise Exception("vlc compilation failed")
5974
shprint(sh.cp, '-a', aar, self.ctx.aars_dir)
6075

6176
recipe = VlcRecipe()

0 commit comments

Comments
 (0)