Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Add '--tail' option
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslo committed Oct 1, 2015
1 parent 29164e0 commit 8926b09
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
10 changes: 9 additions & 1 deletion bin/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def PositiveInt(string):
' (note that full log is still available in log.txt)'
)

parser.add_argument(
'--tail',
type=PositiveInt,
help='Print last N lines if build failed'
)

args = parser.parse_args()

polly_toolchain = detail.toolchain_name.get(args.toolchain)
Expand Down Expand Up @@ -247,7 +253,9 @@ def PositiveInt(string):
polly_temp_dir = os.path.join(build_dir, '_3rdParty', 'polly')
if not os.path.exists(polly_temp_dir):
os.makedirs(polly_temp_dir)
logging = detail.logging.Logging(polly_temp_dir, args.verbose, args.discard)
logging = detail.logging.Logging(
polly_temp_dir, args.verbose, args.discard, args.tail
)

if os.name == 'nt':
# Windows
Expand Down
2 changes: 2 additions & 0 deletions bin/detail/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def call(call_args, logging, cache_file='', ignore=False):
return
if os.path.exists(cache_file):
os.unlink(cache_file)
logging.log_file.close()
print('Command exit with status "{}": {}'.format(x, oneline))
print('Log: {}'.format(logging.log_path))
logging.print_last_lines()
print('*** FAILED ***')
sys.exit(1)
14 changes: 13 additions & 1 deletion bin/detail/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@
import os

class Logging:
def __init__(self, polly_temp_dir, verbose, discard):
def __init__(self, polly_temp_dir, verbose, discard, tail_N):
self.verbose = verbose
self.discard = discard
self.tail_N = tail_N
self.log_path = os.path.join(polly_temp_dir, 'log.txt')
self.log_file = open(self.log_path, 'w')

def print_last_lines(self):
if self.tail_N is None:
return
lines = open(self.log_path, 'r').readlines()
tail = lines[-self.tail_N:]
print('Last {} lines\n'.format(self.tail_N))
print('-' * 80)
for i in tail:
print(' {}'.format(i), end='')
print('-' * 80)

0 comments on commit 8926b09

Please sign in to comment.