Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracing Updates #2009

Merged
merged 12 commits into from
Jul 4, 2018
4 changes: 3 additions & 1 deletion src/app/Fake.BuildServer.AppVeyor/AppVeyor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ module AppVeyor =
| TraceData.BuildState state ->
ConsoleWriter.writeAnsiColor false color true (sprintf "Changing BuildState to: %A" state)
| TraceData.OpenTag (tag, descr) ->
ConsoleWriter.writeAnsiColor false color true (sprintf "Starting %s '%s': %s" tag.Type tag.Name descr)
match descr with
| Some d -> ConsoleWriter.writeAnsiColor false color true (sprintf "Starting %s '%s': %s" tag.Type tag.Name d)
| _ -> ConsoleWriter.writeAnsiColor false color true (sprintf "Starting %s '%s'" tag.Type tag.Name)
| TraceData.CloseTag (tag, time, state) ->
ConsoleWriter.writeAnsiColor false color true (sprintf "Finished (%A) '%s' in %O" state tag.Name time)
| TraceData.ImportantMessage text | TraceData.ErrorMessage text ->
Expand Down
4 changes: 3 additions & 1 deletion src/app/Fake.BuildServer.GitLab/GitLab.fs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ module GitLab =
| TraceData.LogMessage(text, newLine) | TraceData.TraceMessage(text, newLine) ->
write false color newLine text
| TraceData.OpenTag (tag, descr) ->
write false color true (sprintf "Starting %s '%s': %s" tag.Type tag.Name descr)
match descr with
| Some d -> write false color true (sprintf "Starting %s '%s': %s" tag.Type tag.Name d)
| _ -> write false color true (sprintf "Starting %s '%s'" tag.Type tag.Name)
| TraceData.CloseTag (tag, time, state) ->
write false color true (sprintf "Finished (%A) '%s' in %O" state tag.Name time)
| TraceData.BuildState state ->
Expand Down
4 changes: 3 additions & 1 deletion src/app/Fake.BuildServer.TeamCity/TeamCity.fs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ module TeamCity =
| TraceData.CloseTag (KnownTags.TestSuite name, _, _) ->
finishTestSuite name
| TraceData.OpenTag (tag, description) ->
TeamCityWriter.sendOpenBlock tag.Name (sprintf "%s: %s" tag.Type description)
match description with
| Some d -> TeamCityWriter.sendOpenBlock tag.Name (sprintf "%s: %s" tag.Type d)
| _ -> TeamCityWriter.sendOpenBlock tag.Name tag.Type
| TraceData.CloseTag (tag, _, _) ->
TeamCityWriter.sendCloseBlock tag.Name
| TraceData.ImportantMessage text | TraceData.ErrorMessage text ->
Expand Down
5 changes: 4 additions & 1 deletion src/app/Fake.BuildServer.TeamFoundation/TeamFoundation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ module TeamFoundation =
| (_, id) :: _ -> Some id
openTags.Value <- (tag,id) :: openTags.Value
let order = System.Threading.Interlocked.Increment(&order)
createLogDetail id parentId tag.Type tag.Name order descr

match descr with
| Some d -> createLogDetail id parentId tag.Type tag.Name order d
| _ -> createLogDetail id parentId tag.Type tag.Name order null
| TraceData.CloseTag (tag, time, state) ->
ignore time
let id, rest =
Expand Down
4 changes: 3 additions & 1 deletion src/app/Fake.BuildServer.Travis/Travis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ module Travis =
| TraceData.LogMessage(text, newLine) | TraceData.TraceMessage(text, newLine) ->
write false color newLine text
| TraceData.OpenTag (tag, descr) ->
write false color true (sprintf "Starting %s '%s': %s" tag.Type tag.Name descr)
match descr with
| Some d -> write false color true (sprintf "Starting %s '%s': %s" tag.Type tag.Name d)
| _ -> write false color true (sprintf "Starting %s '%s'" tag.Type tag.Name)
| TraceData.CloseTag (tag, time, state) ->
write false color true (sprintf "Finished (%A) '%s' in %O" state tag.Name time)
| TraceData.ImportData (typ, path) ->
Expand Down
24 changes: 17 additions & 7 deletions src/app/Fake.Core.Target/Target.fs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,14 @@ module Target =
|> Seq.filter (fun kv -> kv.Value) // only if activated
|> Seq.map (fun kv -> kv.Key)
|> Seq.fold (fun context name ->
Trace.tracefn "Starting FinalTarget: %s" name
let target = get name
runSimpleContextInternal target context) context
let target = get name
use t = Trace.traceFinalTarget target.Name target.Description (dependencyString target)
let res = runSimpleContextInternal target context
if res.HasError
then t.MarkFailed()
else t.MarkSuccess()
res
) context

/// Runs all build failure targets.
/// [omit]
Expand All @@ -328,9 +333,14 @@ module Target =
|> Seq.filter (fun kv -> kv.Value) // only if activated
|> Seq.map (fun kv -> kv.Key)
|> Seq.fold (fun context name ->
Trace.tracefn "Starting BuildFailureTarget: %s" name
let target = get name
runSimpleContextInternal target context) context
let target = get name
use t = Trace.traceFailureTarget target.Name target.Description (dependencyString target)
let res = runSimpleContextInternal target context
if res.HasError
then t.MarkFailed()
else t.MarkSuccess()
res
) context

/// List all targets available.
let listAvailable() =
Expand Down Expand Up @@ -496,7 +506,7 @@ module Target =
/// Runs a single target without its dependencies... only when no error has been detected yet.
let internal runSingleTarget (target : Target) (context:TargetContext) =
if not context.HasError then
use t = Trace.traceTarget target.Name (match target.Description with Some d -> d | _ -> null) (dependencyString target)
use t = Trace.traceTarget target.Name target.Description (dependencyString target)
let res = runSimpleContextInternal target context
if res.HasError
then t.MarkFailed()
Expand Down
48 changes: 45 additions & 3 deletions src/app/Fake.Core.Trace/Trace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ let closeAllOpenTags() = Seq.iter (fun (_, tag) -> closeTagUnsafeEx TagStatus.Fa
let traceStartTargetUnsafe name description (dependencyString:string) =
openTagUnsafe (KnownTags.Target name) description

/// Traces the begin of a final target
let traceStartFinalTargetUnsafe name description (dependencyString:string) =
openTagUnsafe (KnownTags.FinalTarget name) description

/// Traces the begin of a failure target
let traceStartFailureTargetUnsafe name description (dependencyString:string) =
openTagUnsafe (KnownTags.FailureTarget name) description

/// Traces the begin of a target
[<System.Obsolete("Consider using traceTarget instead and 'use' to properly call traceEndTask in case of exceptions. To remove this warning use 'traceStartTargetUnsafe'.")>]
let traceStartTarget name description dependencyString =
Expand All @@ -201,11 +209,18 @@ let traceStartTarget name description dependencyString =
let traceEndTargetUnsafeEx state name =
closeTagUnsafeEx state (KnownTags.Target name)

/// Traces the end of a final target
let traceEndFinalTargetUnsafeEx state name =
closeTagUnsafeEx state (KnownTags.FinalTarget name)

/// Traces the end of a failure target
let traceEndFailureTargetUnsafeEx state name =
closeTagUnsafeEx state (KnownTags.FailureTarget name)

/// Traces the end of a target
let traceEndTargetUnsafe name =
traceEndTargetUnsafeEx TagStatus.Success name


/// Traces the end of a target
[<System.Obsolete("Consider using traceTarget instead and 'use' to properly call traceEndTask in case of exceptions. To remove this warning use 'traceEndTargetUnsafe'.")>]
let traceEndTarget name = traceEndTargetUnsafe name
Expand All @@ -214,9 +229,20 @@ let traceTarget name description dependencyString =
traceStartTargetUnsafe name description dependencyString
asSafeDisposable (fun state -> traceEndTargetUnsafeEx state name)

let traceFinalTarget name description dependencyString =
traceStartFinalTargetUnsafe name description dependencyString
asSafeDisposable (fun state -> traceEndFinalTargetUnsafeEx state name)

let traceFailureTarget name description dependencyString =
traceStartFailureTargetUnsafe name description dependencyString
asSafeDisposable (fun state -> traceEndFailureTargetUnsafeEx state name)

/// Traces the begin of a task
let traceStartTaskUnsafe task description =
openTagUnsafe (KnownTags.Task task) description
if String.IsNullOrWhiteSpace description then
openTagUnsafe (KnownTags.Task task) None
else
openTagUnsafe (KnownTags.Task task) (Some(description))

/// Traces the begin of a task
[<System.Obsolete("Consider using traceTask instead and 'use' to properly call traceEndTask in case of exceptions. To remove this warning use 'traceStartTaskUnsafe'.")>]
Expand All @@ -232,11 +258,27 @@ let traceEndTaskUnsafe task = traceEndTaskUnsafeEx TagStatus.Success task
/// Traces the end of a task
[<System.Obsolete("Consider using traceTask instead and 'use' to properly call traceEndTask in case of exceptions. To remove this warning use 'traceEndTask'.")>]
let traceEndTask task = traceEndTaskUnsafe task


/// Wrap functions in a 'use' of this function
let traceTask name description =
traceStartTaskUnsafe name description
asSafeDisposable (fun state -> traceEndTaskUnsafeEx state name)

/// Allows automatic or manual tracing around a function being run
/// If in automatic success mode and no exception is thrown then trace is marked as success
/// Any exception thrown will result in a mark failed and exception re-thrown
let inline useWith automaticSuccess func (trace:ISafeDisposable) =
try
try
let result = func trace
if automaticSuccess then trace.MarkSuccess()
result
with _ ->
trace.MarkFailed()
reraise()
finally
trace.Dispose()

open System.Diagnostics
#if DOTNETCORE
type EventLogEntryType =
Expand Down
30 changes: 18 additions & 12 deletions src/app/Fake.Core.Trace/TraceListener.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ open System
type KnownTags =
| Task of name:string
| Target of name:string
| FinalTarget of name:string
| FailureTarget of name:string
| Compilation of compiler:string
| TestSuite of suiteName:string
| Test of testName:string
Expand All @@ -15,6 +17,8 @@ type KnownTags =
match x with
| Task n
| Target n
| FinalTarget n
| FailureTarget n
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change and you need to update the various listeners (AppVeyor, Travis, ...) to handle these new cases.
Problem is we don't have warning as errors on for "missing cases on match"

An alternative would be to add the info to the Target case and add a "Targettype" or something like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only listener which mentions Target is the console one, so i didn't think this would be a breaking change...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok makes sense, so we go like this because adding another TargetType would most likely be more breaking.

| Compilation n
| TestSuite n
| Test n
Expand All @@ -23,6 +27,8 @@ type KnownTags =
match x with
| Task _ -> "task"
| Target _ -> "target"
| FinalTarget _ -> "final target"
| FailureTarget _ -> "failure target"
| Compilation _ -> "compilation"
| TestSuite _ -> "testsuite"
| Test _ -> "test"
Expand Down Expand Up @@ -119,7 +125,7 @@ type TraceData =
| TraceMessage of text:string * newLine:bool
/// Happens when a tag (Task, Target, Test, ...) has started.
/// description is 'null' when missing.
| OpenTag of KnownTags * description:string
| OpenTag of KnownTags * description:string option
| TestStatus of testName:string * status:TestStatus
| TestOutput of testName:string * out:string * err:string
| CloseTag of KnownTags * time:TimeSpan * TagStatus
Expand Down Expand Up @@ -244,17 +250,17 @@ type ConsoleTraceListener(importantMessagesToStdErr, colorMap, ansiColor) =
write importantMessagesToStdErr color true text
| TraceData.LogMessage(text, newLine) | TraceData.TraceMessage(text, newLine) ->
write false color newLine text
| TraceData.OpenTag(KnownTags.Target _ as tag, description) ->
let msg = TraceData.TraceMessage("", true)
let color2 = colorMap msg
let msgToPrint =
let initial = sprintf "Starting %s '%s'" tag.Type tag.Name
if String.IsNullOrWhiteSpace description then
initial
else sprintf "%s: %s" initial description
write false color2 true msgToPrint
| TraceData.OpenTag (tag, descr) ->
write false color true (sprintf "Starting %s '%s': %s" tag.Type tag.Name descr)
| TraceData.OpenTag(KnownTags.Target _ as tag, description)
| TraceData.OpenTag(KnownTags.FailureTarget _ as tag, description)
| TraceData.OpenTag(KnownTags.FinalTarget _ as tag, description) ->
let color2 = colorMap (TraceData.TraceMessage("", true))
match description with
| Some d -> write false color2 true (sprintf "Starting %s '%s': %s" tag.Type tag.Name d)
| _ -> write false color2 true (sprintf "Starting %s '%s'" tag.Type tag.Name)
| TraceData.OpenTag (tag, description) ->
match description with
| Some d -> write false color true (sprintf "Starting %s '%s': %s" tag.Type tag.Name d)
| _ -> write false color true (sprintf "Starting %s '%s'" tag.Type tag.Name)
| TraceData.CloseTag (tag, time, status) ->
write false color true (sprintf "Finished (%A) '%s' in %O" status tag.Name time)
| TraceData.ImportData (typ, path) ->
Expand Down
9 changes: 0 additions & 9 deletions src/app/Fake.DotNet.AssemblyInfoFile/AssemblyInfoFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ module AssemblyInfoFile =
use f = fi.Open(FileMode.Create)
use writer = new System.IO.StreamWriter(f, System.Text.Encoding.UTF8)
lines |> Seq.iter writer.WriteLine
Trace.tracefn "Created AssemblyInfo file \"%s\"." outputFileName

let private getDependencies attributes =
attributes
Expand Down Expand Up @@ -214,7 +213,6 @@ module AssemblyInfoFile =
/// Creates a C# AssemblyInfo file with the given attributes and configuration.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
let createCSharpWithConfig outputFileName attributes (config : AssemblyInfoFileConfig) =
use __ = Trace.traceTask "AssemblyInfo" outputFileName
let generateClass, useNamespace, emitResharperSupressions = config.GenerateClass, config.UseNamespace, config.EmitResharperSuppressions

let dependencies =
Expand Down Expand Up @@ -255,12 +253,10 @@ module AssemblyInfoFile =

attributeLines @ sourceLines
|> writeToFile outputFileName
__.MarkSuccess()

/// Creates a F# AssemblyInfo file with the given attributes and configuration.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
let createFSharpWithConfig outputFileName attributes (config : AssemblyInfoFileConfig) =
use __ = Trace.traceTask "AssemblyInfo" outputFileName
let generateClass, useNamespace = config.GenerateClass, config.UseNamespace

let sourceLines =
Expand All @@ -286,12 +282,10 @@ module AssemblyInfoFile =
]

sourceLines |> writeToFile outputFileName
__.MarkSuccess()

/// Creates a VB AssemblyInfo file with the given attributes and configuration.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
let createVisualBasicWithConfig outputFileName attributes (config : AssemblyInfoFileConfig) =
use __ = Trace.traceTask "AssemblyInfo" outputFileName
let generateClass, _ = config.GenerateClass, config.UseNamespace

let attributeLines =
Expand All @@ -314,12 +308,10 @@ module AssemblyInfoFile =

attributeLines @ sourceLines
|> writeToFile outputFileName
__.MarkSuccess()

/// Creates a C++/CLI AssemblyInfo file with the given attributes and configuration.
/// Does not generate an AssemblyVersionInformation class.
let createCppCliWithConfig outputFileName attributes (config : AssemblyInfoFileConfig) =
use __ = Trace.traceTask "AssemblyInfo" outputFileName
let _, _ = config.GenerateClass, config.UseNamespace
//C++/CLI namespaces cannot be fully qualified; you must
// namespace Namespace1 { namespace Namespace2 { }} //etc
Expand All @@ -334,7 +326,6 @@ module AssemblyInfoFile =

attributeLines
|> writeToFile outputFileName
__.MarkSuccess()

/// Creates a C# AssemblyInfo file with the given attributes.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
Expand Down