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

Fixes To Target Traces #2016

Merged
merged 4 commits into from
Jul 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 26 additions & 39 deletions src/app/Fake.Core.Target/Target.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ and [<NoComparison>] [<NoEquality>] Target =
SoftDependencies: string list;
Description: TargetDescription option;
Function : TargetParameter -> unit}
member x.DescriptionAsString =
match x.Description with
| Some d -> d
| _ -> null

/// Exception for request errors
#if !NETSTANDARD1_6
Expand Down Expand Up @@ -174,6 +178,14 @@ module Target =
Trace.traceError <| sprintf " - %s" target.Value.Name
failwithf "Target \"%s\" is not defined." name

/// Returns the DependencyString for the given target.
let internal dependencyString target =
if target.Dependencies.IsEmpty then String.Empty else
target.Dependencies
|> Seq.map (fun d -> (get d).Name)
|> String.separated ", "
|> sprintf "(==> %s)"

let internal runSimpleInternal context target =
let watch = System.Diagnostics.Stopwatch.StartNew()
let error =
Expand All @@ -185,11 +197,16 @@ module Target =
with e -> Some e
watch.Stop()
{ Error = error; Time = watch.Elapsed; Target = target; WasSkipped = false }
let internal runSimpleContextInternal target context =

let internal runSimpleContextInternal (traceStart: string -> string -> string -> Trace.ISafeDisposable) context target =
use t = traceStart target.Name target.DescriptionAsString (dependencyString target)
let result = runSimpleInternal context target
if result.Error.IsSome then
t.MarkFailed()
else
t.MarkSuccess()
{ context with PreviousTargets = context.PreviousTargets @ [result] }


/// This simply runs the function of a target without doing anything (like tracing, stopwatching or adding it to the results at the end)
let runSimple name args =
let target = get name
Expand All @@ -202,14 +219,6 @@ module Target =
target
|> runSimpleInternal ctx

/// Returns the DependencyString for the given target.
let internal dependencyString target =
if target.Dependencies.IsEmpty then String.Empty else
target.Dependencies
|> Seq.map (fun d -> (get d).Name)
|> String.separated ", "
|> sprintf "(==> %s)"

/// Returns the soft DependencyString for the given target.
let internal softDependencyString target =
if target.SoftDependencies.IsEmpty then String.Empty else
Expand Down Expand Up @@ -262,7 +271,6 @@ module Target =

getTargetDict().[targetName] <- { target with Dependencies = target.Dependencies @ [dependentTargetName] }


/// Appends the dependency to the list of soft dependencies.
/// [omit]
let internal softDependencyAtEnd targetName dependentTargetName =
Expand Down Expand Up @@ -314,33 +322,17 @@ module Target =
/// [omit]
let internal runFinalTargets context =
getFinalTargets()
|> Seq.filter (fun kv -> kv.Value) // only if activated
|> Seq.map (fun kv -> kv.Key)
|> Seq.fold (fun context name ->
let target = get name
use t = Trace.traceFinalTarget target.Name (match target.Description with Some d -> d | _ -> null) (dependencyString target)
let res = runSimpleContextInternal target context
if res.HasError
then t.MarkFailed()
else t.MarkSuccess()
res
) context
|> Seq.filter (fun kv -> kv.Value) // only if activated
|> Seq.map (fun kv -> get kv.Key)
|> Seq.fold (fun context target -> runSimpleContextInternal Trace.traceFinalTarget context target) context

/// Runs all build failure targets.
/// [omit]
let internal runBuildFailureTargets (context) =
getBuildFailureTargets()
|> Seq.filter (fun kv -> kv.Value) // only if activated
|> Seq.map (fun kv -> kv.Key)
|> Seq.fold (fun context name ->
let target = get name
use t = Trace.traceFailureTarget target.Name (match target.Description with Some d -> d | _ -> null) (dependencyString target)
let res = runSimpleContextInternal target context
if res.HasError
then t.MarkFailed()
else t.MarkSuccess()
res
) context
|> Seq.filter (fun kv -> kv.Value) // only if activated
|> Seq.map (fun kv -> get kv.Key)
|> Seq.fold (fun context target -> runSimpleContextInternal Trace.traceFailureTarget context target) context

/// List all targets available.
let listAvailable() =
Expand Down Expand Up @@ -506,12 +498,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)
let res = runSimpleContextInternal target context
if res.HasError
then t.MarkFailed()
else t.MarkSuccess()
res
runSimpleContextInternal Trace.traceTarget context target
else
{ context with PreviousTargets = context.PreviousTargets @ [{ Error = None; Time = TimeSpan.Zero; Target = target; WasSkipped = true }] }

Expand Down
6 changes: 3 additions & 3 deletions src/app/Fake.Core.Trace/Trace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ let traceHeader name =
traceLine()

/// Puts an opening tag on the internal tag stack
let openTagUnsafe tag (description:string) =
let openTagUnsafe tag description =
let sw = System.Diagnostics.Stopwatch.StartNew()
openTags.Value <- (sw, tag) :: openTags.Value
TraceData.OpenTag(tag, if System.String.IsNullOrEmpty description then None else Some description) |> CoreTracing.postMessage
Expand Down Expand Up @@ -238,7 +238,7 @@ let traceFailureTarget name description dependencyString =
asSafeDisposable (fun state -> traceEndFailureTargetUnsafeEx state name)

/// Traces the begin of a task
let traceStartTaskUnsafe task (description:string) =
let traceStartTaskUnsafe task description =
openTagUnsafe (KnownTags.Task task) description

/// Traces the begin of a task
Expand All @@ -257,7 +257,7 @@ let traceEndTaskUnsafe task = traceEndTaskUnsafeEx TagStatus.Success task
let traceEndTask task = traceEndTaskUnsafe task

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

Expand Down