Skip to content

Commit 358ce98

Browse files
committed
Merge branch 'dev'
2 parents 11cde58 + 721b40d commit 358ce98

File tree

4 files changed

+75
-18
lines changed

4 files changed

+75
-18
lines changed

core/CommonTasks.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ module internal impl =
4242
return proc.ExitCode
4343
}
4444

45-
type SystemOptionsType = {LogPrefix:string; StdOutLevel: Level; ErrOutLevel: Level; EnvVars: (string * string) list}
46-
let SystemOptions = {LogPrefix = ""; StdOutLevel = Level.Info; ErrOutLevel = Level.Error; EnvVars = []}
45+
type SystemOptions = {LogPrefix:string; StdOutLevel: string -> Level; ErrOutLevel: string -> Level; EnvVars: (string * string) list}
46+
with static member Default = {LogPrefix = ""; StdOutLevel = (fun _ -> Level.Info); ErrOutLevel = (fun _ -> Level.Error); EnvVars = []}
4747

4848
/// <summary>
4949
/// Executes system command. E.g. '_system SystemOptions "dir" []'
@@ -59,8 +59,8 @@ module internal impl =
5959
do! trace Level.Debug "[system] envvars: '%A'" settings.EnvVars
6060
do! trace Level.Debug "[system] args: '%A'" args
6161

62-
let handleErr = log settings.ErrOutLevel "%s %s" settings.LogPrefix
63-
let handleStd = log settings.StdOutLevel "%s %s" settings.LogPrefix
62+
let handleErr s = log (settings.ErrOutLevel s) "%s %s" settings.LogPrefix s
63+
let handleStd s = log (settings.StdOutLevel s) "%s %s" settings.LogPrefix s
6464

6565
return
6666
if isWindows && not <| isExt cmd ".exe" then
@@ -79,7 +79,7 @@ open impl
7979
let system cmd args =
8080
action {
8181
do! trace Info "[system] starting '%s'" cmd
82-
let! exitCode = _system SystemOptions cmd (args |> String.concat " ")
82+
let! exitCode = _system SystemOptions.Default cmd (args |> String.concat " ")
8383
do! trace Info "[system] сompleted '%s' exitcode: %d" cmd exitCode
8484

8585
return exitCode

core/DotnetTasks.fs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ module DotnetTasks =
228228
let platformStr = function
229229
|AnyCpu -> "anycpu" |AnyCpu32Preferred -> "anycpu32preferred" |ARM -> "arm" | X64 -> "x64" | X86 -> "x86" |Itanium -> "itanium"
230230

231+
/// Parses the compiler output and returns messageLevel
232+
let levelFromString defaultLevel (text:string) :Level =
233+
if text.IndexOf "): warning " > 0 then Level.Warning
234+
else if text.IndexOf "): error " > 0 then Level.Error
235+
else defaultLevel
236+
231237
end // end of Impl module
232238

233239
/// C# compiler task
@@ -321,9 +327,10 @@ module DotnetTasks =
321327
do! trace Debug "Command line: '%s %s'" fwkInfo.CscTool (args |> Seq.map Impl.escapeArgument |> String.concat "\r\n\t")
322328

323329
let options = {
324-
SystemOptions with
330+
SystemOptions.Default with
325331
LogPrefix = "[CSC] "
326-
StdOutLevel = Level.Verbose // consider standard compiler output too noisy
332+
StdOutLevel = fun _ -> Level.Verbose
333+
ErrOutLevel = Impl.levelFromString Level.Verbose
327334
EnvVars = fwkInfo.EnvVars
328335
}
329336
let! exitCode = _system options fwkInfo.CscTool commandLine
@@ -470,9 +477,10 @@ module DotnetTasks =
470477
do! trace Debug "Command line: '%s'" args
471478

472479
let options = {
473-
SystemOptions with
480+
SystemOptions.Default with
474481
LogPrefix = pfx
475-
StdOutLevel = Level.Info // consider standard compiler output too noisy
482+
StdOutLevel = fun _ -> Level.Info
483+
ErrOutLevel = Impl.levelFromString Level.Verbose
476484
}
477485
let! exitCode = args |> _system options fwkInfo.MsbuildTool
478486

@@ -587,9 +595,10 @@ module DotnetTasks =
587595
do! trace Debug "Command line: '%s %s'" fsc (args |> Seq.map Impl.escapeArgument |> String.concat "\r\n\t")
588596

589597
let options = {
590-
SystemOptions with
598+
SystemOptions.Default with
591599
LogPrefix = "[FSC] "
592-
StdOutLevel = Level.Verbose // consider standard compiler output too noisy
600+
StdOutLevel = fun _ -> Level.Verbose
601+
ErrOutLevel = Impl.levelFromString Level.Verbose
593602
EnvVars = fwkInfo.EnvVars
594603
}
595604
let! exitCode = _system options fsc (args |> String.concat " ")

core/Logging.fs

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,70 @@ let FileLogger name maxLevel =
9494
| false -> ignore
9595
Printf.kprintf write format }
9696

97+
module private ConsoleSink =
98+
99+
open System
100+
101+
type Message = Message of Level * string
102+
103+
let defaultColor = Console.ForegroundColor
104+
105+
let levelToColor = function
106+
| Level.Message -> ConsoleColor.White, ConsoleColor.White
107+
| Error -> ConsoleColor.Red, ConsoleColor.DarkRed
108+
| Command -> ConsoleColor.Green, ConsoleColor.DarkGreen
109+
| Warning -> ConsoleColor.Yellow, ConsoleColor.DarkYellow
110+
| Info -> ConsoleColor.DarkGreen, defaultColor
111+
| Debug -> ConsoleColor.DarkGray, ConsoleColor.DarkGray
112+
| Verbose -> ConsoleColor.Gray, ConsoleColor.Gray
113+
| _ -> defaultColor, defaultColor
114+
115+
116+
let po = MailboxProcessor.Start(fun mbox ->
117+
let rec loop () =
118+
async {
119+
let! (Message(level, text)) = mbox.Receive()
120+
121+
let color, text_color = level |> levelToColor
122+
123+
Console.ForegroundColor <- defaultColor
124+
Console.Write "["
125+
Console.ForegroundColor <- color
126+
Console.Write (LevelToString level)
127+
Console.ForegroundColor <- defaultColor
128+
Console.Write "] "
129+
130+
Console.ForegroundColor <- text_color
131+
text |> System.Console.WriteLine
132+
Console.ForegroundColor <- defaultColor
133+
134+
return! loop ()
135+
}
136+
loop ())
137+
138+
97139
/// <summary>
98140
/// Console logger.
99141
/// </summary>
100142
/// <param name="maxLevel"></param>
101-
let ConsoleLogger maxLevel =
143+
let private ConsoleLoggerBase (write: Level -> string -> unit) maxLevel =
102144
let filterLevels = logFilter maxLevel
103145
{ new ILogger with
104146
member __.Log level format =
105147
let write =
106-
match Set.contains level filterLevels with
107-
| true ->
108-
sprintf "[%s] %s" (LevelToString level)
109-
>> System.Console.WriteLine
148+
match filterLevels |> Set.contains level with
149+
| true -> write level
110150
| false -> ignore
111151
Printf.kprintf write format }
112152

153+
let DumbConsoleLogger =
154+
ConsoleLoggerBase (
155+
fun level -> (LevelToString level) |> sprintf "[%s] %s" >> System.Console.WriteLine
156+
)
157+
158+
let ConsoleLogger =
159+
ConsoleLoggerBase (fun level s -> ConsoleSink.Message(level,s) |> ConsoleSink.po.Post)
160+
113161
/// <summary>
114162
/// Creates a logger that is combination of two loggers.
115163
/// </summary>

samples/csc/hw-net2-net4.fsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ do xake {ExecOptions.Default with Vars = ["NETFX", "4.0"]; FileLogLevel = Verbos
1212

1313
"check_deps" => action {
1414
let! ctx = getCtx()
15-
let tgt = FileTarget (Artifact (ctx.Options.ProjectRoot </> "hw2.exe"))
16-
let reasons = getDirtyState ctx tgt
15+
let tgt = FileTarget (File.make (ctx.Options.ProjectRoot </> "hw2.exe"))
16+
let reasons = getPlainDeps ctx tgt
1717

1818
printfn "need: %A" reasons
1919
}

0 commit comments

Comments
 (0)