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

Add support for MSBuild Distributed Loggers #536

Merged
merged 3 commits into from
Sep 19, 2014
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
123 changes: 77 additions & 46 deletions src/app/FakeLib/MSBuildHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
module Fake.MSBuildHelper

open System
open System.Text
open System.IO
open System.Configuration
open System.Xml
open System.Xml.Linq

/// An type to represent MSBuild project files.
Expand Down Expand Up @@ -113,6 +111,12 @@ type MSBuildFileLoggerConfig =
Verbosity : MSBuildVerbosity option
Parameters : MSBuildLogParameter list option }

type MSBuildDistributedLoggerConfig =
{
ClassName : string option
AssemblyPath : string
Parameters : (string * string) list option }

/// A type for MSBuild task parameters
type MSBuildParams =
{ Targets : string list
Expand All @@ -122,7 +126,8 @@ type MSBuildParams =
ToolsVersion : string option
Verbosity : MSBuildVerbosity option
NoConsoleLogger : bool
FileLoggers : MSBuildFileLoggerConfig list option }
FileLoggers : MSBuildFileLoggerConfig list option
DistributedLoggers : (MSBuildDistributedLoggerConfig * MSBuildDistributedLoggerConfig option) list option }

/// Defines a default for MSBuild task parameters
let mutable MSBuildDefaults =
Expand All @@ -133,12 +138,13 @@ let mutable MSBuildDefaults =
ToolsVersion = None
Verbosity = None
NoConsoleLogger = false
FileLoggers = None }
FileLoggers = None
DistributedLoggers = None }

/// [omit]
let getAllParameters targets maxcpu nodeReuse tools verbosity noconsolelogger fileLoggers properties =
if isUnix then [ targets; tools; verbosity; noconsolelogger ] @ fileLoggers @ properties
else [ targets; maxcpu; nodeReuse; tools; verbosity; noconsolelogger ] @ fileLoggers @ properties
let getAllParameters targets maxcpu nodeReuse tools verbosity noconsolelogger fileLoggers distributedFileLoggers properties =
if isUnix then [ targets; tools; verbosity; noconsolelogger ] @ fileLoggers @ distributedFileLoggers @ properties
else [ targets; maxcpu; nodeReuse; tools; verbosity; noconsolelogger ] @ fileLoggers @ distributedFileLoggers @ properties

let private serializeArgs args =
args
Expand All @@ -150,14 +156,16 @@ let private serializeArgs args =
|> separated " "

/// [omit]
let serializeMSBuildParams (p : MSBuildParams) =
let serializeMSBuildParams (p : MSBuildParams) =
let verbosityName v =
match v with
| Quiet -> "q"
| Minimal -> "m"
| Normal -> "n"
| Detailed -> "d"
| Diagnostic -> "diag"



let targets =
match p.Targets with
Expand Down Expand Up @@ -194,45 +202,68 @@ let serializeMSBuildParams (p : MSBuildParams) =
else None

let fileLoggers =
let logParams param =
match param with
| Append -> "Append"
| PerformanceSummary -> "PerformanceSummary"
| Summary -> "Summary"
| NoSummary -> "NoSummary"
| ErrorsOnly -> "ErrorsOnly"
| WarningsOnly -> "WarningsOnly"
| NoItemAndPropertyList -> "NoItemAndPropertyList"
| ShowCommandLine -> "ShowCommandLine"
| ShowTimestamp -> "ShowTimestamp"
| ShowEventId -> "ShowEventId"
| ForceNoAlign -> "ForceNoAlign"
| DisableConsoleColor -> "DisableConsoleColor"
| DisableMPLogging -> "DisableMPLogging"
| EnableMPLogging -> "EnableMPLogging"
let serializeLogger fl =
let logParams param =
match param with
| Append -> "Append"
| PerformanceSummary -> "PerformanceSummary"
| Summary -> "Summary"
| NoSummary -> "NoSummary"
| ErrorsOnly -> "ErrorsOnly"
| WarningsOnly -> "WarningsOnly"
| NoItemAndPropertyList -> "NoItemAndPropertyList"
| ShowCommandLine -> "ShowCommandLine"
| ShowTimestamp -> "ShowTimestamp"
| ShowEventId -> "ShowEventId"
| ForceNoAlign -> "ForceNoAlign"
| DisableConsoleColor -> "DisableConsoleColor"
| DisableMPLogging -> "DisableMPLogging"
| EnableMPLogging -> "EnableMPLogging"

sprintf "%s%s%s"
(match fl.Filename with
| None -> ""
| Some f -> sprintf "logfile=%s;" f)
(match fl.Verbosity with
| None -> ""
| Some v -> sprintf "Verbosity=%s;" (verbosityName v))
(match fl.Parameters with
| None -> ""
| Some ps ->
ps
|> List.map (fun p -> sprintf "%s;" (logParams p))
|> String.concat "")

match p.FileLoggers with
| None -> []
| Some fls ->
fls
|> List.map
(fun fl ->
Some
("flp" + (string fl.Number),
sprintf "%s%s%s"
(match fl.Filename with
| None -> ""
| Some f -> sprintf "logfile=%s;" f)
(match fl.Verbosity with
| None -> ""
| Some v -> sprintf "Verbosity=%s;" (verbosityName v))
(match fl.Parameters with
| None -> ""
| Some ps ->
ps
|> List.map (fun p -> sprintf "%s;" (logParams p))
|> String.concat "")))

getAllParameters targets maxcpu nodeReuse tools verbosity noconsolelogger fileLoggers properties
|> List.map (fun fl -> Some ("flp" + (string fl.Number), serializeLogger fl) )

let distributedFileLoggers =
let serializeDLogger (dlogger : MSBuildDistributedLoggerConfig) =
sprintf "%s%s%s"
(match dlogger.ClassName with | None -> "" | Some name -> sprintf "%s," name)
(sprintf "\"%s\"" dlogger.AssemblyPath)
(match dlogger.Parameters with
| None -> ""
| Some vars -> vars
|> List.fold (fun acc (k,v) -> sprintf "%s%s=%s;" acc k v) ""
|> sprintf ";\"%s\""
)

let createLoggerString cl fl =
match fl with
| None -> serializeDLogger cl
| Some l -> sprintf "%s*%s" (serializeDLogger cl) (serializeDLogger l)

match p.DistributedLoggers with
| None -> []
| Some dfls ->
dfls
|> List.map(fun (cl, fl) -> Some("dl", createLoggerString cl fl))

getAllParameters targets maxcpu nodeReuse tools verbosity noconsolelogger fileLoggers distributedFileLoggers properties
|> serializeArgs

/// [omit]
Expand All @@ -252,7 +283,7 @@ let mutable MSBuildLoggers =
match buildServer with
| BuildServer.AppVeyor ->
MSBuildLoggers <- @"""C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll""" :: MSBuildLoggers
| BuildServer.TeamCity -> MSBuildLoggers <- sprintf "%s,\"%s\"" TeamCityLoggerName pathToLogger :: MSBuildLoggers
| BuildServer.TeamCity -> MSBuildLoggers <- sprintf "%s,\"%s\"" TeamCityLoggerName pathToLogger :: MSBuildLoggers
| _ -> ()

/// Runs a MSBuild project
Expand Down Expand Up @@ -395,8 +426,8 @@ let BuildWebsite outputPath projectFile =
let projectDir = (fileInfo projectFile).Directory.FullName
let mutable prefix = ""
let diff = slashes projectDir - slashes currentDir
for i in 1..diff do
prefix <- prefix + "../"
prefix <- prefix + (String.replicate diff "../")

MSBuildDebug "" "Rebuild" [ projectFile ] |> ignore
MSBuild "" "_CopyWebApplication;_BuiltWebOutputGroupOutput"
[ "OutDir", prefix + outputPath
Expand Down
60 changes: 52 additions & 8 deletions src/test/testscripts/test1.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,55 @@

open Fake

#if MONO
failwith "mono was set"
#else
failwith "mono was not set"
#endif

if hasBuildParam "test" |> not then
failwith "test param is missing"
Target "blah" (fun _ ->
let simpleConfig = {
ClassName = None
AssemblyPath = "test.dll"
Parameters = None
}

let nameConfig = {simpleConfig with ClassName = Some "simpleClass"}
let simpleWithParams = {simpleConfig with Parameters = Some [("Verbosity", "High"); ("dupe2", "wat");]}
let fullConfig = {simpleConfig with
ClassName = nameConfig.ClassName
Parameters = simpleWithParams.Parameters}

let wcl = Some [
{
ClassName = Some "WorkflowCentralLogger"
AssemblyPath = "C:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll"
Parameters =
Some [
"Verbosity", "Normal"
"BuildUri", "vstfs:///Build/Build/364"
"IgnoreDuplicateProjects", "False"
"InformationNodeId", sprintf "%d" 8
"TargetsNotLogged", "GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath"
"TFSUrl", "https://ctaggart.visualstudio.com/DefaultCollection"
]
},
Some {
ClassName = Some "WorkflowForwardingLogger"
AssemblyPath = "C:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll"
Parameters =
Some [
"Verbosity", "Normal"
]
}
]

let simpleRun =
[simpleConfig; nameConfig; simpleWithParams; fullConfig]
|> List.map (fun x -> (x, None))
let complexRun =
[simpleConfig; nameConfig; simpleWithParams; fullConfig]
|> List.map (fun x -> (x, Some fullConfig))

[wcl]
|> List.map (fun x -> {MSBuildDefaults with DistributedLoggers = x})
|> List.map MSBuildHelper.serializeMSBuildParams
|> List.iter (logfn "%s")
)

RunTargetOrDefault "blah"