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

Commit 8926b09

Browse files
committed
Add '--tail' option
1 parent 29164e0 commit 8926b09

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

bin/build.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ def PositiveInt(string):
150150
' (note that full log is still available in log.txt)'
151151
)
152152

153+
parser.add_argument(
154+
'--tail',
155+
type=PositiveInt,
156+
help='Print last N lines if build failed'
157+
)
158+
153159
args = parser.parse_args()
154160

155161
polly_toolchain = detail.toolchain_name.get(args.toolchain)
@@ -247,7 +253,9 @@ def PositiveInt(string):
247253
polly_temp_dir = os.path.join(build_dir, '_3rdParty', 'polly')
248254
if not os.path.exists(polly_temp_dir):
249255
os.makedirs(polly_temp_dir)
250-
logging = detail.logging.Logging(polly_temp_dir, args.verbose, args.discard)
256+
logging = detail.logging.Logging(
257+
polly_temp_dir, args.verbose, args.discard, args.tail
258+
)
251259

252260
if os.name == 'nt':
253261
# Windows

bin/detail/call.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ def call(call_args, logging, cache_file='', ignore=False):
7979
return
8080
if os.path.exists(cache_file):
8181
os.unlink(cache_file)
82+
logging.log_file.close()
8283
print('Command exit with status "{}": {}'.format(x, oneline))
8384
print('Log: {}'.format(logging.log_path))
85+
logging.print_last_lines()
8486
print('*** FAILED ***')
8587
sys.exit(1)

bin/detail/logging.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@
44
import os
55

66
class Logging:
7-
def __init__(self, polly_temp_dir, verbose, discard):
7+
def __init__(self, polly_temp_dir, verbose, discard, tail_N):
88
self.verbose = verbose
99
self.discard = discard
10+
self.tail_N = tail_N
1011
self.log_path = os.path.join(polly_temp_dir, 'log.txt')
1112
self.log_file = open(self.log_path, 'w')
13+
14+
def print_last_lines(self):
15+
if self.tail_N is None:
16+
return
17+
lines = open(self.log_path, 'r').readlines()
18+
tail = lines[-self.tail_N:]
19+
print('Last {} lines\n'.format(self.tail_N))
20+
print('-' * 80)
21+
for i in tail:
22+
print(' {}'.format(i), end='')
23+
print('-' * 80)

0 commit comments

Comments
 (0)