18
18
from buildbot .process .results import WARNINGS
19
19
from buildbot .process .results import statusToString
20
20
21
+ from zorg .buildbot .commands .LitTestCommand import LitLogObserver
22
+
21
23
def get_log_details (build ):
22
24
failed_step = None
23
25
text = ""
@@ -58,22 +60,37 @@ def get_log_details(build):
58
60
log_text = logs [log_index ]['content' ]['content' ]
59
61
if logs [log_index ]['type' ] == "s" :
60
62
# Parse stdio
61
- lines = log_text .splitlines ()
62
- for line in lines [:]:
63
- if line .startswith ("h" ):
64
- lines .remove (line )
65
- for j , line in enumerate (lines ):
66
- if line .startswith ("o" ) or line .startswith ("e" ):
67
- lines [j ] = line [1 :]
63
+ raw_lines = log_text .splitlines ()
64
+ lines = []
65
+ fail_index = - 1
66
+ for line in raw_lines :
67
+ if line .startswith ("h" ): # header
68
+ line = line [1 :]
69
+ if fail_index == - 1 :
70
+ # Check for "command timed out:"
71
+ if LitLogObserver .kTestLineKill .match (line ):
72
+ fail_index = len (lines )
73
+ else :
74
+ # Drop this header line
75
+ continue
76
+ elif line .startswith ("o" ) or line .startswith ("e" ):
77
+ # Adjust stdout or stderr line
78
+ line = line [1 :]
79
+ lines .append (line )
68
80
for j , line in enumerate (lines ):
81
+ if fail_index != - 1 and fail_index < j :
82
+ break
69
83
if line .startswith ("FAIL:" ) or line .find ("FAILED" ) != - 1 :
70
- if j > 10 :
71
- del lines [:j - 10 ] # Start 10 lines before FAIL
72
- lines = ["..." ] + lines
73
- del lines [50 :] # Keep up to 50 lines around FAIL
84
+ fail_index = j
74
85
break
75
- if len (lines ) > 50 :
76
- del lines [:len (lines )- 50 ] # Otherwise keep last 50 lines
86
+ if fail_index >= 0 :
87
+ if fail_index > 10 :
88
+ del lines [:fail_index - 10 ] # Start 10 lines before FAIL
89
+ lines = ["..." ] + lines
90
+ del lines [50 :] # Keep up to 50 lines around FAIL
91
+ elif len (lines ) > 50 :
92
+ # Otherwise keep last 50 lines
93
+ del lines [:len (lines )- 50 ]
77
94
lines = ["..." ] + lines
78
95
79
96
log_text = "\n " .join (lines )
@@ -239,13 +256,30 @@ def generate(self, master, reporter, key, build): # override
239
256
change = changes [0 ]
240
257
# Get the first line of the commit description.
241
258
title = change ["comments" ].split ("\n " )[0 ]
242
- # And store it in properties as 'title'.
243
- build ["properties" ]["title" ] = (
244
- title ,
259
+
260
+ # Search for PR# in the first line of the commit description, which looks like 'Some text (#123)'.
261
+ m = re .search (r"^.* \(#(\d+)\)$" , title )
262
+ if not m :
263
+ log .msg (
264
+ f"LLVMFailBuildGenerator.generate(buildid={ buildid } ): WARNING: Cannot extract PR# from the title '{ title } '."
265
+ )
266
+ return None
267
+
268
+ issue = m .group (1 )
269
+
270
+ # To play it safe for further processing we want a snapshot:
271
+ # a local shallow copy of build information,
272
+ # along with a copy of build properties.
273
+ build_info = build .copy ()
274
+ build_info ["properties" ] = build ["properties" ].copy ()
275
+
276
+ build_info ["properties" ]["issue" ] = (
277
+ issue ,
245
278
None ,
246
279
)
247
280
248
- report = yield self .build_message (self .formatter , master , reporter , build )
281
+ #log.msg(f"LLVMFailBuildGenerator.generate(buildid={buildid}): INFO: calling yield self.build_message build_info={build_info}")
282
+ report = yield self .build_message (self .formatter , master , reporter , build_info )
249
283
# log.msg(f"LLVMFailBuildGenerator.generate(buildid={buildid}): INFO: report={report}")
250
284
return report
251
285
@@ -255,13 +289,9 @@ class LLVMFailGitHubReporter(GitHubCommentPush):
255
289
256
290
def _extract_issue (self , props ): # override
257
291
log .msg (f"LLVMFailGitHubReporter._extract_issue: INFO: props={ props } " )
258
- title = props .getProperty ("title" )
259
- if title :
260
- # Search for PR# in the first line of the commit description, which looks like 'Some text (#123)'.
261
- m = re .search (r"^.* \(#(\d+)\)$" , title )
262
- if m :
263
- return m .group (1 )
264
- return None
292
+ issue = props .getProperty ("issue" )
293
+ log .msg (f"LLVMFailGitHubReporter._extract_issue: INFO: issue={ issue } " )
294
+ return issue
265
295
266
296
# This function is for logging purposes only.
267
297
# Could be removed completely if log verbosity would be reduced.
0 commit comments