-
Notifications
You must be signed in to change notification settings - Fork 582
/
BinLog.fs
89 lines (74 loc) · 2.72 KB
/
BinLog.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
namespace Fake.DotNet
/// <summary>
/// Analyse a binlog and emit proper CI messages
/// </summary>
module MSBuildBinLog =
open System
open Microsoft.Build.Framework
open Microsoft.Build.Logging.StructuredLogger
open System.Collections.Generic
open Fake.Core
let internal structuredLogAssemblyPath = typeof<BinLogReader>.Assembly.Location
let internal emitMessages (messages: ConsoleMessage list) =
let knownErrors = HashSet<string>()
let traceError msg =
if knownErrors.Add(msg) then
Trace.traceError msg
let knownWarnings = HashSet<string>()
let traceWarning msg =
if knownWarnings.Add(msg) then
Trace.traceFAKE "%s" msg
for msg in messages do
if not msg.IsError then
traceWarning msg.Message
for msg in messages do
if msg.IsError then
traceError msg.Message
let getErrorsAndWarnings (binLogFilePath: string) =
let binLogReader = BinLogReader()
use stream =
new System.IO.FileStream(
binLogFilePath,
System.IO.FileMode.Open,
System.IO.FileAccess.Read,
System.IO.FileShare.Read
)
binLogReader.ReadRecords(stream)
|> Seq.choose (fun record ->
if isNull record then
None
else if isNull record.Args then
None
else
let buildEventArgs = record.Args
match buildEventArgs with
| :? BuildErrorEventArgs as a ->
let msg =
sprintf
"%s: %s(%d,%d): error %s: %s"
a.SenderName
a.File
a.LineNumber
a.ColumnNumber
a.Code
a.Message
{ IsError = true
Message = msg
Timestamp = DateTimeOffset a.Timestamp }
|> Some
| :? BuildWarningEventArgs as a ->
let msg =
sprintf
"%s: %s(%d,%d): warning %s: %s"
a.SenderName
a.File
a.LineNumber
a.ColumnNumber
a.Code
a.Message
{ IsError = false
Message = msg
Timestamp = DateTimeOffset a.Timestamp }
|> Some
| _ -> None)
|> Seq.toList