Skip to content

Commit f891bdc

Browse files
committed
cosmetic toolchain logging outputs
1 parent 9bc52b6 commit f891bdc

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

pythonforandroid/recipes/vlc/__init__.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,9 @@ def build_arch(self, arch):
5555
})
5656
info("compiling vlc from sources")
5757
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")
58+
if not exists(join(port_dir, 'bin', 'VLC-debug.apk')):
59+
shprint(sh.Command('./compile.sh'), _env=env, _tail=50, _critical=True)
60+
shprint(sh.Command('./compile-libvlc.sh'), _env=env, _tail=50, _critical=True)
7461
shprint(sh.cp, '-a', aar, self.ctx.aars_dir)
7562

7663
recipe = VlcRecipe()

pythonforandroid/toolchain.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,24 +127,41 @@ def shprint(command, *args, **kwargs):
127127
else:
128128
logger.debug(string + Style.RESET_ALL)
129129

130-
output = command(*args, **kwargs)
131-
need_closing_newline = False
132-
for line in output:
133-
if logger.level > logging.DEBUG:
134-
string = ''.join([Style.RESET_ALL, '\r', ' '*11, 'working ... ',
135-
line[:100].replace('\n', '').rstrip(), ' ...'])
136-
if len(string) < 20:
137-
continue
138-
if len(string) < 120:
139-
string = string + ' '*(120 - len(string))
140-
sys.stdout.write(string)
141-
sys.stdout.flush()
142-
need_closing_newline = True
130+
try:
131+
output = command(*args, **kwargs)
132+
need_closing_newline = False
133+
for line in output:
134+
if logger.level > logging.DEBUG:
135+
string = ''.join([Style.RESET_ALL, '\r', ' '*11, 'working ... ',
136+
line[:100].replace('\n', '').rstrip(), ' ...'])
137+
if len(string) < 20:
138+
continue
139+
if len(string) < 120:
140+
string = string + ' '*(120 - len(string))
141+
sys.stdout.write(string)
142+
sys.stdout.flush()
143+
need_closing_newline = True
144+
else:
145+
logger.debug(''.join(['\t', line.rstrip()]))
146+
if logger.level > logging.DEBUG and need_closing_newline:
147+
print()
148+
except sh.ErrorReturnCode_1, err:
149+
N = kwargs.get('_tail', 0)
150+
if N:
151+
warning("Error: {} failed".format(command))
152+
lines = err.stdout.splitlines()
153+
if len(lines) <= N:
154+
info('STDOUT:\n{}\t{}{}'.format(Fore.YELLOW, '\t\n'.join(lines), Fore.RESET))
155+
else:
156+
info('STDOUT (last {} lines of {}):\n{}\t{}{}'.format(N, len(lines), Fore.YELLOW, '\t\n'.join(lines[-N:]), Fore.RESET))
157+
lines = err.stderr.splitlines()
158+
if len(lines):
159+
warning('STDERR:\n{}\t{}{}'.format(Fore.RED, '\t\n'.join(lines), Fore.RESET))
160+
if kwargs.get('_critical', False):
161+
exit(1)
143162
else:
144-
logger.debug(''.join(['\t', line.rstrip()]))
145-
if logger.level > logging.DEBUG and need_closing_newline:
146-
print()
147-
163+
raise
164+
148165
return output
149166

150167
# shprint(sh.ls, '-lah')
@@ -2849,7 +2866,7 @@ def apk(self, args):
28492866
build = imp.load_source('build', join(dist.dist_dir, 'build.py'))
28502867
with current_directory(dist.dist_dir):
28512868
build.parse_args(args)
2852-
shprint(sh.ant, 'debug')
2869+
shprint(sh.ant, 'debug', _tail=20, _critical=True)
28532870

28542871
# AND: This is very crude, needs improving. Also only works
28552872
# for debug for now.

0 commit comments

Comments
 (0)