Skip to content

Commit

Permalink
Merge pull request #519 from sergey-tihon/master
Browse files Browse the repository at this point in the history
FAKE.Deploy switched to FCS
  • Loading branch information
forki committed Aug 25, 2014
2 parents 48f5712 + 93a60c7 commit f5b0532
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/app/Fake.Deploy/DeploymentHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let doDeployment packageName scriptFileName scriptArgs =
try
let workingDirectory = DirectoryName scriptFileName
let (result, messages) =
FSIHelper.executeFSIWithScriptArgsAndReturnMessages workingDirectory (FullName scriptFileName) scriptArgs
FSIHelper.executeBuildScriptWithArgsAndReturnMessages workingDirectory (FullName scriptFileName) scriptArgs
if result then
Success { Messages = messages
IsError = false
Expand All @@ -86,6 +86,7 @@ let doDeployment packageName scriptFileName scriptArgs =
IsError = true
Exception = (Exception "Deployment script didn't run successfully") }
with e ->
traceException e
Failure { Messages = Seq.empty
IsError = true
Exception = e }
Expand Down
63 changes: 45 additions & 18 deletions src/app/FakeLib/FSIHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ let executeFSIWithArgs workingDirectory script extraFsiArgs args =
Thread.Sleep 1000
result = 0

open Microsoft.FSharp.Compiler.Interactive.Shell

/// Run the given build script with fsi.exe and allows for extra arguments to the script. Returns output.
let executeFSIWithScriptArgsAndReturnMessages workingDirectory script (scriptArgs: string[]) =
let (result, messages) =
Expand All @@ -88,8 +86,10 @@ let executeFSIWithScriptArgsAndReturnMessages workingDirectory script (scriptArg
Thread.Sleep 1000
(result, messages)

/// Run the given buildscript with fsi.exe at the given working directory. Provides full access to Fsi options and args.
let runBuildScriptWithFsiArgsAt workingDirectory printDetails (FsiArgs(fsiOptions, script, scriptArgs)) args =
open Microsoft.FSharp.Compiler.Interactive.Shell

/// Run the given FAKE script with fsi.exe at the given working directory. Provides full access to Fsi options and args. Redirect output and error messages.
let internal runFAKEScriptWithFsiArgsAndRedirectMessages workingDirectory printDetails (FsiArgs(fsiOptions, script, scriptArgs)) args onErrMsg onOutMsg =
if printDetails then traceFAKE "Running Buildscript: %s" script

// Add arguments to the Environment
Expand All @@ -101,33 +101,60 @@ let runBuildScriptWithFsiArgsAt workingDirectory printDetails (FsiArgs(fsiOption

let fsiConfig = FsiEvaluationSession.GetDefaultConfiguration()

let commonOptions =
let commonOptions =
[ "fsi.exe"; "--noninteractive" ] @ fsiOptions
|> List.toArray

let sbOut = new Text.StringBuilder()
let sbErr = new Text.StringBuilder()
let outStream = new StringWriter(sbOut)
let errStream = new StringWriter(sbErr)
let sbOut = Text.StringBuilder()
let sbErr = Text.StringBuilder()
let handleMessages() =
let handleMessagesFrom (sb:Text.StringBuilder) onMsg =
let s = sb.ToString()
if not <| String.IsNullOrEmpty s
then onMsg s
handleMessagesFrom sbOut onOutMsg
handleMessagesFrom sbErr onErrMsg

use outStream = new StringWriter(sbOut)
use errStream = new StringWriter(sbErr)
use stdin = new StreamReader(Stream.Null)

let stdin = new StreamReader(Stream.Null)

try
let session = FsiEvaluationSession.Create(fsiConfig, commonOptions, stdin, outStream, errStream)

try
try
session.EvalScript script
handleMessages()
true
with
| _ ->
traceError <| sbErr.ToString()
false
with
with
| _ ->
handleMessages()
false
with
| exn ->
traceError "FsiEvaluationSession could not be created."
traceError <| sbErr.ToString()
raise exn


/// Run the given buildscript with fsi.exe and allows for extra arguments to the script. Returns output.
let executeBuildScriptWithArgsAndReturnMessages workingDirectory script (scriptArgs: string[]) =
let messages = ref []
let appendMessage isError msg =
messages := { IsError = isError
Message = msg
Timestamp = DateTimeOffset.UtcNow } :: !messages
let result =
runFAKEScriptWithFsiArgsAndRedirectMessages
workingDirectory true (FsiArgs([], script, scriptArgs |> List.ofArray)) []
(appendMessage true) (appendMessage false)
(result, !messages)

/// Run the given buildscript with fsi.exe at the given working directory. Provides full access to Fsi options and args.
let runBuildScriptWithFsiArgsAt workingDirectory printDetails (FsiArgs(fsiOptions, script, scriptArgs)) args =
runFAKEScriptWithFsiArgsAndRedirectMessages
workingDirectory printDetails (FsiArgs(fsiOptions, script, scriptArgs)) args
traceError (fun s-> traceFAKE "%s" s)

/// Run the given buildscript with fsi.exe at the given working directory.
let runBuildScriptAt workingDirectory printDetails script extraFsiArgs args =
runBuildScriptWithFsiArgsAt workingDirectory printDetails (FsiArgs(extraFsiArgs, script, [])) args
Expand Down
2 changes: 1 addition & 1 deletion src/app/FakeLib/FakeLib.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Compiler.Service">
<HintPath>..\..\..\packages\FSharp.Compiler.Service.0.0.58\lib\net40\FSharp.Compiler.Service.dll</HintPath>
<HintPath>..\..\..\packages\FSharp.Compiler.Service.0.0.59\lib\net40\FSharp.Compiler.Service.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FSharp.Core, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Expand Down
36 changes: 36 additions & 0 deletions src/app/FakeLib/TraceHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,42 @@ let traceFAKE fmt = Printf.ksprintf (fun text -> postMessage (ImportantMessage t
/// Traces an error (in red)
let traceError error = postMessage (ErrorMessage error)

open Microsoft.FSharp.Core.Printf
/// Traces an exception details (in red)
let traceException (ex:Exception) =
let sb = Text.StringBuilder()
let delimeter = String.replicate 50 "*"
let nl = Environment.NewLine
let rec printException (e:Exception) count =
if (e :? TargetException && e.InnerException <> null)
then printException (e.InnerException) count
else
if (count = 1) then bprintf sb "Exception Message:%s%s%s" e.Message nl delimeter
else bprintf sb "%s%s%d)Exception Message:%s%s%s" nl nl count e.Message nl delimeter
bprintf sb "%sType: %s" nl (e.GetType().FullName)
// Loop through the public properties of the exception object
// and record their values.
e.GetType().GetProperties()
|> Array.iter (fun p ->
// Do not log information for the InnerException or StackTrace.
// This information is captured later in the process.
if (p.Name <> "InnerException" && p.Name <> "StackTrace" &&
p.Name <> "Message" && p.Name <> "Data") then
try
let value = p.GetValue(e, null)
if (value <> null)
then bprintf sb "%s%s: %s" nl p.Name (value.ToString())
with
| e2 -> bprintf sb "%s%s: %s" nl p.Name e2.Message
)
if (e.StackTrace <> null) then
bprintf sb "%s%sStackTrace%s%s%s" nl nl nl delimeter nl
bprintf sb "%s%s" nl e.StackTrace
if (e.InnerException <> null)
then printException e.InnerException (count+1)
printException ex 1
sb.ToString() |> traceError

/// Traces the EnvironmentVariables
let TraceEnvironmentVariables() =
[ EnvironTarget.Machine; EnvironTarget.Process; EnvironTarget.User ]
Expand Down
2 changes: 1 addition & 1 deletion src/app/FakeLib/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FSharp.Compiler.Service" version="0.0.58" targetFramework="net40" />
<package id="FSharp.Compiler.Service" version="0.0.59" targetFramework="net40" />
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net40" />
<package id="Mono.Cecil" version="0.9.5.4" targetFramework="net40" />
<package id="Nuget.Core" version="2.8.2" targetFramework="net40" />
Expand Down

0 comments on commit f5b0532

Please sign in to comment.