From 8432a6cbfb7d581128662329bd01cf4c8f6b6a3c Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Sun, 17 Jan 2016 11:40:00 +0100 Subject: [PATCH 01/13] add bootstrap step to FAKE in order to check the newly produced FAKE.exe --- build.fsx | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/build.fsx b/build.fsx index bf35c08ce0b..9c15b27ce0f 100644 --- a/build.fsx +++ b/build.fsx @@ -149,6 +149,43 @@ Target "Test" (fun _ -> |> xUnit id ) +Target "Bootstrap" (fun _ -> + let buildScript = "build.fsx" + let testScript = "testbuild.fsx" + // Check if we can build ourself with the new binaries. + let test clearCache script = + let clear () = + // Will make sure the test call actually compiles the script. + // Note: We cannot just clean .fake here as it might be locked by the currently executing code :) + if Directory.Exists ".fake" then + Directory.EnumerateFiles(".fake") + |> Seq.filter (fun s -> (Path.GetFileName s).StartsWith script) + |> Seq.iter File.Delete + let executeTarget target = + if clearCache then clear () + ExecProcess (fun info -> + info.FileName <- "build/FAKE.exe" + info.WorkingDirectory <- "." + info.Arguments <- sprintf "%s %s -pd" script target) (System.TimeSpan.FromMinutes 3.0) + + let result = executeTarget "PrintColors" + if result <> 0 then failwith "Bootstrapping failed" + + let result = executeTarget "FailFast" + if result = 0 then failwith "Bootstrapping failed" + + File.ReadAllText buildScript + |> fun s -> s.Replace("#I @\"packages/build/FAKE/tools/\"", "#I @\"build/\"") + |> fun text -> File.WriteAllText(testScript, text) + + try + // Will compile the script. + test true testScript + // Will use the compiled/cached version. + test false testScript + finally File.Delete(testScript) +) + Target "SourceLink" (fun _ -> !! "src/app/**/*.fsproj" |> Seq.iter (fun f -> @@ -287,7 +324,18 @@ Target "Release" (fun _ -> Branches.tag "" release.NugetVersion Branches.pushTag "" "origin" release.NugetVersion ) - +open System +Target "PrintColors" (fun s -> + let color (color: ConsoleColor) (code : unit -> _) = + let before = Console.ForegroundColor + try + Console.ForegroundColor <- color + code () + finally + Console.ForegroundColor <- before + color ConsoleColor.Magenta (fun _ -> printfn "TestMagenta") +) +Target "FailFast" (fun _ -> failwith "fail fast") Target "Default" DoNothing // Dependencies @@ -296,6 +344,7 @@ Target "Default" DoNothing ==> "BuildSolution" //==> "ILRepack" ==> "Test" + ==> "Bootstrap" ==> "Default" ==> "CopyLicense" =?> ("GenerateDocs", isLocalBuild && not isLinux) From 1497dd7e62c55ce84c0db12a0d71abcbf47d9ea0 Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Sun, 17 Jan 2016 11:42:29 +0100 Subject: [PATCH 02/13] add yaaf.fsharp.scripting to fakelib (infrastructure only). --- .gitignore | 1 + paket.dependencies | 2 ++ paket.lock | 5 ++++- src/app/FakeLib/FakeLib.fsproj | 8 ++++++-- src/app/FakeLib/paket.references | 1 + 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5faae9b128d..e8b537fc9ca 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ release.cmd Samples/typescript/out/ help/RELEASE_NOTES.md paket.exe +paket-files/ # Ignore the Vagrant local directories .vagrant/* diff --git a/paket.dependencies b/paket.dependencies index c4220e83584..497d4b52e1d 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -38,6 +38,8 @@ nuget FluentMigrator.Runner nuget HashLib nuget FSharp.Compiler.Service +github matthid/Yaaf.FSharp.Scripting src/source/Yaaf.FSharp.Scripting/YaafFSharpScripting.fs + group Build content: none source http://nuget.org/api/v2 diff --git a/paket.lock b/paket.lock index 430dbf72bcb..92013a0b832 100644 --- a/paket.lock +++ b/paket.lock @@ -81,7 +81,10 @@ NUGET xunit.extensions (1.9.2) xunit (1.9.2) xunit.runners (1.9.2) - +GITHUB + remote: matthid/Yaaf.FSharp.Scripting + specs: + src/source/Yaaf.FSharp.Scripting/YaafFSharpScripting.fs (8295ec5cacc78c7b1eb369d7cd72fcd81f9c8ff7) GROUP Build CONTENT: NONE NUGET diff --git a/src/app/FakeLib/FakeLib.fsproj b/src/app/FakeLib/FakeLib.fsproj index 19e5c8f7c02..2d2f93b9197 100644 --- a/src/app/FakeLib/FakeLib.fsproj +++ b/src/app/FakeLib/FakeLib.fsproj @@ -16,7 +16,7 @@ full false bin\Debug - TRACE;DEBUG + TRACE;DEBUG;NET40 prompt 3 @@ -30,12 +30,16 @@ pdbonly true ..\..\..\build\ - TRACE + TRACE;NET40 prompt 3 ..\..\..\build\FakeLib.XML + + True + paket-files/YaafFSharpScripting.fs + diff --git a/src/app/FakeLib/paket.references b/src/app/FakeLib/paket.references index 5bb6c8e93a7..d34763987b0 100644 --- a/src/app/FakeLib/paket.references +++ b/src/app/FakeLib/paket.references @@ -1,3 +1,4 @@ +File: YaafFSharpScripting.fs FSharp.Core FSharp.Compiler.Service Mono.Web.Xdt From e419f24c414bae52e38657e5cf75c8ed4ccb4f22 Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Sun, 17 Jan 2016 11:44:50 +0100 Subject: [PATCH 03/13] add traceUnknown to log a message without modifying the console color. --- src/app/FakeLib/TraceHelper.fs | 3 +++ src/app/FakeLib/TraceListener.fs | 23 +++++++++++++++-------- src/app/FakeLib/UserInputHelper.fs | 9 +++++---- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/app/FakeLib/TraceHelper.fs b/src/app/FakeLib/TraceHelper.fs index 03cca56d547..be252d7c689 100644 --- a/src/app/FakeLib/TraceHelper.fs +++ b/src/app/FakeLib/TraceHelper.fs @@ -32,6 +32,9 @@ let logVerbosefn fmt = /// Writes a trace to the command line (in green) let trace message = postMessage (TraceMessage(message, true)) +/// Writes a trace to the command line (in the current console color) +let traceUnknown message = postMessage (UnknownMessage(message, false)) + /// Writes a message to the command line (in green) let tracefn fmt = Printf.ksprintf trace fmt diff --git a/src/app/FakeLib/TraceListener.fs b/src/app/FakeLib/TraceListener.fs index a0385c3492c..edeab26143c 100644 --- a/src/app/FakeLib/TraceListener.fs +++ b/src/app/FakeLib/TraceListener.fs @@ -11,6 +11,7 @@ type TraceData = | ErrorMessage of string | LogMessage of string * bool | TraceMessage of string * bool + | UnknownMessage of string * bool | FinishedMessage | OpenTag of string * string | CloseTag of string @@ -26,6 +27,7 @@ let colorMap traceData = | ErrorMessage _ -> ConsoleColor.Red | LogMessage _ -> ConsoleColor.Gray | TraceMessage _ -> ConsoleColor.Green + | UnknownMessage _ -> Console.ForegroundColor | FinishedMessage -> ConsoleColor.White | _ -> ConsoleColor.Gray @@ -37,13 +39,17 @@ type ConsoleTraceListener(importantMessagesToStdErr, colorMap) = let writeText toStdErr color newLine text = let curColor = Console.ForegroundColor - if curColor <> color then Console.ForegroundColor <- color - if toStdErr then - if newLine then eprintfn "%s" text - else eprintf "%s" text - else if newLine then printfn "%s" text - else printf "%s" text - if curColor <> color then Console.ForegroundColor <- curColor + try + if curColor <> color then Console.ForegroundColor <- color + let printer = + match toStdErr, newLine with + | true, true -> eprintfn + | true, false -> eprintf + | false, true -> printfn + | false, false -> printf + printer "%s" text + finally + if curColor <> color then Console.ForegroundColor <- curColor interface ITraceListener with /// Writes the given message to the Console. @@ -54,7 +60,8 @@ type ConsoleTraceListener(importantMessagesToStdErr, colorMap) = | OpenTag _ -> () | CloseTag _ -> () | ImportantMessage text | ErrorMessage text -> writeText importantMessagesToStdErr color true text - | LogMessage(text, newLine) | TraceMessage(text, newLine) -> writeText false color newLine text + | UnknownMessage(text, newLine) | LogMessage(text, newLine) | TraceMessage(text, newLine) -> + writeText false color newLine text | FinishedMessage -> () /// The default TraceListener for Console. diff --git a/src/app/FakeLib/UserInputHelper.fs b/src/app/FakeLib/UserInputHelper.fs index 235c4388dc5..64034699e0f 100644 --- a/src/app/FakeLib/UserInputHelper.fs +++ b/src/app/FakeLib/UserInputHelper.fs @@ -38,10 +38,11 @@ let internal readString (echo: bool) : string = let internal color (color: ConsoleColor) (code : unit -> _) = let before = Console.ForegroundColor - Console.ForegroundColor <- color - let result = code () - Console.ForegroundColor <- before - result + try + Console.ForegroundColor <- color + code () + finally + Console.ForegroundColor <- before /// Return a string entered by the user followed by enter. The input is echoed to the screen. let getUserInput prompt = From 986d66cbccae7d98e820ad2fac987ffd32601c35 Mon Sep 17 00:00:00 2001 From: Matthias Dittrich Date: Sun, 17 Jan 2016 11:48:34 +0100 Subject: [PATCH 04/13] use Yaaf.FSharp.Scripting to display code-warnings in the build script (at the end). --- src/app/FakeLib/FSIHelper.fs | 299 ++++++++++++++++++++--------------- 1 file changed, 168 insertions(+), 131 deletions(-) diff --git a/src/app/FakeLib/FSIHelper.fs b/src/app/FakeLib/FSIHelper.fs index 9886f532f3a..2f7f7ae00ad 100644 --- a/src/app/FakeLib/FSIHelper.fs +++ b/src/app/FakeLib/FSIHelper.fs @@ -9,6 +9,7 @@ open System.Diagnostics open System.Threading open System.Text.RegularExpressions open System.Xml.Linq +open Yaaf.FSharp.Scripting let private FSIPath = @".\tools\FSharp\;.\lib\FSharp\;[ProgramFilesX86]\Microsoft SDKs\F#\4.0\Framework\v4.0;[ProgramFilesX86]\Microsoft SDKs\F#\3.1\Framework\v4.0;[ProgramFilesX86]\Microsoft SDKs\F#\3.0\Framework\v4.0;[ProgramFiles]\Microsoft F#\v4.0\;[ProgramFilesX86]\Microsoft F#\v4.0\;[ProgramFiles]\FSharp-2.0.0.0\bin\;[ProgramFilesX86]\FSharp-2.0.0.0\bin\;[ProgramFiles]\FSharp-1.9.9.9\bin\;[ProgramFilesX86]\FSharp-1.9.9.9\bin\" @@ -203,59 +204,33 @@ type private AssemblySource = | Disk let hashRegex = Text.RegularExpressions.Regex("(?