Skip to content

Commit e582464

Browse files
Merge pull request #300 from smoothdeveloper/fake5
migrate to FAKE 5
2 parents 15f77e8 + cad6954 commit e582464

File tree

6 files changed

+190
-49
lines changed

6 files changed

+190
-49
lines changed

build.cmd

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@ if errorlevel 1 (
1010
exit /b %errorlevel%
1111
)
1212

13-
IF NOT EXIST build.fsx (
14-
.paket\paket.exe update
15-
packages\build\FAKE\tools\FAKE.exe init.fsx
16-
)
17-
packages\build\FAKE\tools\FAKE.exe build.fsx %*
13+
packages\build\FAKE\tools\FAKE.exe --removeLegacyFakeWarning build.fsx %*

build.fsx

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
// FAKE build script
33
// --------------------------------------------------------------------------------------
44

5-
#I @"packages/build/FAKE/tools"
65
#r @"packages/build/FAKE/tools/FakeLib.dll"
6+
#load "tools/fakexunithelper.fsx" // helper for xunit 1 is gone, work around by having our own copy for now
77

88
open System
99
open System.IO
10-
open Fake
11-
open Fake.AssemblyInfoFile
10+
open Fake.Core
1211
open Fake.Git
12+
open Fake.IO
13+
open Fake.IO.FileSystemOperators
14+
open Fake.IO.Globbing
15+
open Fake.IO.Globbing.Operators
16+
open Fake.DotNet
1317

1418
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
1519

@@ -31,7 +35,7 @@ let gitName = "FSharp.Data.SqlClient"
3135
// Read release notes & version info from RELEASE_NOTES.md
3236
let release =
3337
File.ReadLines "RELEASE_NOTES.md"
34-
|> ReleaseNotesHelper.parseReleaseNotes
38+
|> Fake.Core.ReleaseNotes.parse
3539

3640
let version = release.AssemblyVersion
3741
let releaseNotes = release.Notes |> String.concat "\n"
@@ -40,33 +44,33 @@ let testDir = "bin"
4044
// --------------------------------------------------------------------------------------
4145
// Generate assembly info files with the right version & up-to-date information
4246

43-
Target "AssemblyInfo" (fun _ ->
47+
Target.create "AssemblyInfo" (fun _ ->
4448
[ "src/SqlClient/AssemblyInfo.fs", "SqlClient", project, summary ]
4549
|> Seq.iter (fun (fileName, title, project, summary) ->
46-
CreateFSharpAssemblyInfo fileName
47-
[ Attribute.Title title
48-
Attribute.Product project
49-
Attribute.Description summary
50-
Attribute.Version version
51-
Attribute.FileVersion version
52-
Attribute.InternalsVisibleTo "SqlClient.Tests" ] )
50+
AssemblyInfoFile.createFSharp fileName
51+
[ AssemblyInfo.Title title
52+
AssemblyInfo.Product project
53+
AssemblyInfo.Description summary
54+
AssemblyInfo.Version version
55+
AssemblyInfo.FileVersion version
56+
AssemblyInfo.InternalsVisibleTo "SqlClient.Tests" ] )
5357
)
5458

55-
Target "Clean" (fun _ ->
56-
CleanDirs ["bin"; "temp"]
59+
Target.create "Clean" (fun _ ->
60+
Shell.cleanDirs ["bin"; "temp"]
5761
)
5862

59-
Target "CleanDocs" (fun _ ->
60-
CleanDirs ["docs/output"]
63+
Target.create "CleanDocs" (fun _ ->
64+
Shell.cleanDirs ["docs/output"]
6165
)
6266

6367
// --------------------------------------------------------------------------------------
6468
// Build library (builds Visual Studio solution, which builds multiple versions
6569
// of the runtime library & desktop + Silverlight version of design time library)
6670

67-
Target "Build" (fun _ ->
71+
Target.create "Build" (fun _ ->
6872
files (["SqlClient.sln"])
69-
|> MSBuildRelease "" "Rebuild"
73+
|> MSBuild.runRelease id "" "Rebuild"
7074
|> ignore
7175
)
7276

@@ -80,7 +84,7 @@ open System.Data.SqlClient
8084
open System.Configuration
8185
open System.IO.Compression
8286

83-
Target "DeployTestDB" (fun() ->
87+
Target.create "DeployTestDB" (fun _ ->
8488
let testsSourceRoot = Path.GetFullPath(@"src\SqlClient.Tests")
8589
let map = ExeConfigurationFileMap()
8690
map.ExeConfigFilename <- testsSourceRoot @@ "app.config"
@@ -135,34 +139,35 @@ Target "DeployTestDB" (fun() ->
135139
cmd.ExecuteNonQuery() |> ignore
136140
)
137141

138-
Target "BuildTests" (fun _ ->
142+
Target.create "BuildTests" (fun _ ->
139143
files ["Tests.sln"]
140-
|> MSBuildReleaseExt "" ([]) "Rebuild"
144+
|> MSBuild.runReleaseExt id "" ([]) "Rebuild"
141145
|> ignore
142146
)
143147

144148
// --------------------------------------------------------------------------------------
145149
// Run the unit tests
146-
Target "RunTests" (fun _ ->
150+
Target.create "RunTests" (fun _ ->
147151
!! (testDir + "/*.Tests.dll")
148-
|> xUnit (fun p ->
152+
|> Fake.XUnitHelper.xUnit (fun p ->
149153
{p with
150-
ShadowCopy = false;
151-
HtmlOutput = true;
152-
XmlOutput = true;
153-
OutputDir = testDir})
154+
ShadowCopy = false
155+
HtmlOutput = true
156+
XmlOutput = true
157+
WorkingDir = testDir
158+
})
154159
)
155160

156161
// --------------------------------------------------------------------------------------
157162
// Build a NuGet package
158163

159-
Target "NuGet" (fun _ ->
164+
Target.create "NuGet" (fun _ ->
160165

161166
// Format the description to fit on a single line (remove \r\n and double-spaces)
162167
let description = description.Replace("\r", "").Replace("\n", "").Replace(" ", " ")
163168
let nugetPath = "packages/build/NuGet.CommandLine/tools/NuGet.exe"
164-
165-
NuGet (fun p ->
169+
170+
Fake.DotNet.NuGet.NuGet.NuGet (fun p ->
166171
{ p with
167172
Authors = authors
168173
Project = project
@@ -173,35 +178,37 @@ Target "NuGet" (fun _ ->
173178
Tags = tags
174179
OutputPath = "nuget"
175180
ToolPath = nugetPath
176-
AccessKey = getBuildParamOrDefault "nugetkey" ""
177-
Publish = hasBuildParam "nugetkey"
181+
AccessKey = Fake.Core.Environment.environVarOrDefault "nugetkey" ""
182+
Publish = Fake.Core.Environment.hasEnvironVar "nugetkey"
178183
Dependencies = [] })
179184
"nuget/SqlClient.nuspec"
180185
)
181186

182187
// --------------------------------------------------------------------------------------
183188
// Generate the documentation
184189

185-
Target "GenerateDocs" (fun _ ->
186-
executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore
190+
Target.create "GenerateDocs" (fun _ ->
191+
Fake.FSIHelper.executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore
187192
)
188193

189-
Target "ReleaseDocs" (fun _ ->
194+
Target.create "ReleaseDocs" (fun _ ->
190195
Repository.clone "" (gitHome + "/" + gitName + ".git") "temp/gh-pages"
191196
Branches.checkoutBranch "temp/gh-pages" "gh-pages"
192-
CopyRecursive "docs/output" "temp/gh-pages" true |> printfn "%A"
197+
Shell.copyRecursive "docs/output" "temp/gh-pages" true |> printfn "%A"
193198
CommandHelper.runSimpleGitCommand "temp/gh-pages" "add ." |> printfn "%s"
194199
let cmd = sprintf """commit -a -m "Update generated documentation for version %s""" release.NugetVersion
195200
CommandHelper.runSimpleGitCommand "temp/gh-pages" cmd |> printfn "%s"
196201
Branches.push "temp/gh-pages"
197202
)
198203

199-
Target "Release" DoNothing
204+
Target.create "Release" Target.DoNothing
200205

201206
// --------------------------------------------------------------------------------------
202207
// Run all targets by default. Invoke 'build <Target>' to override
203208

204-
Target "All" DoNothing
209+
Target.create "All" Target.DoNothing
210+
211+
open Fake.Core.TargetOperators // for ==>
205212

206213
"Clean"
207214
==> "AssemblyInfo"
@@ -220,5 +227,5 @@ Target "All" DoNothing
220227
==> "GenerateDocs"
221228
==> "ReleaseDocs"
222229

223-
RunTargetOrDefault "All"
230+
Target.runOrDefault "All"
224231

build.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,5 @@ fi
3131

3232
run .paket/paket.exe restore
3333

34-
[ ! -e build.fsx ] && run .paket/paket.exe update
35-
[ ! -e build.fsx ] && run packages/build/FAKE/tools/FAKE.exe init.fsx
36-
run packages/build/FAKE/tools/FAKE.exe "$@" $FSIARGS build.fsx
34+
run packages/build/FAKE/tools/FAKE.exe --removeLegacyFakeWarning "$@" $FSIARGS build.fsx
3735

paket.dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ group Build
1515
redirects: force
1616

1717
nuget NuGet.CommandLine
18-
nuget FAKE = 4.1.2
18+
nuget FAKE = 5.0.0-rc014.167
1919

2020
group Test
2121
source https://www.nuget.org/api/v2/

paket.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ REDIRECTS: FORCE
102102
RESTRICTION: >= net40
103103
NUGET
104104
remote: https://www.nuget.org/api/v2
105-
FAKE (4.1.2)
105+
FAKE (5.0.0-rc014.167)
106106
NuGet.CommandLine (4.6.2)
107107

108108
GROUP Samples

tools/fakexunithelper.fsx

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// taken from https://github.com/fsharp/FAKE/blob/4.64.13/src/app/FakeLib/UnitTest/XUnit/XUnitHelper.fs
2+
// this is not in FAKE 5
3+
open Fake
4+
#nowarn "44"
5+
6+
open System
7+
open System.IO
8+
open System.Text
9+
10+
/// DEPRECATED.
11+
/// Option which allows to specify if an xUnit error should break the build.
12+
[<Obsolete("This type alias will be removed in a future version.")>]
13+
type XUnitErrorLevel = TestRunnerErrorLevel // a type alias to keep backwards compatibility
14+
15+
/// DEPRECATED.
16+
/// The xUnit parameter type
17+
[<Obsolete("This type will be removed in a future version. See Fake.Testing.XUnit.XUnitParams")>]
18+
[<CLIMutable>]
19+
type XUnitParams =
20+
{ /// The path to the xunit.console.clr4.exe - FAKE will scan all subfolders to find it automatically.
21+
ToolPath : string
22+
/// The file name of the config file (optional).
23+
ConfigFile : string
24+
/// If set to true a HTML output file will be generated.
25+
HtmlOutput : bool
26+
/// If set to true a HTML output file will be generated in NUnit format.
27+
NUnitXmlOutput : bool
28+
/// If set to true XML output will be generated.
29+
XmlOutput : bool
30+
/// The working directory (optional).
31+
WorkingDir : string
32+
/// If set to true xUnit will run in ShadowCopy mode.
33+
ShadowCopy : bool
34+
/// If set to true xUnit will generate verbose output.
35+
Verbose : bool
36+
/// If the timeout is reached the xUnit task will be killed. Default is 5 minutes.
37+
TimeOut : TimeSpan
38+
/// The output directory. It's the current directoy if nothing else is specified.
39+
OutputDir : string
40+
/// Test runner error level. Option which allows to specify if an xUnit error should break the build.
41+
ErrorLevel : XUnitErrorLevel
42+
/// Include named traits with comma separated values
43+
IncludeTraits : (string * string) option
44+
/// Exclude named traits with comma separated values
45+
ExcludeTraits : (string * string) option }
46+
47+
/// DEPRECATED.
48+
/// The xUnit default parameters
49+
[<Obsolete("This value will be removed in a future version.")>]
50+
let emptyTrait : (string * string) option = None
51+
52+
/// DEPRECATED.
53+
[<Obsolete("This value will be removed in a future version. See Fake.Testing.XUnit.XUnitDefaults")>]
54+
let XUnitDefaults =
55+
{ ToolPath = findToolInSubPath "xunit.console.clr4.exe" (currentDirectory @@ "tools" @@ "xUnit")
56+
ConfigFile = null
57+
HtmlOutput = false
58+
NUnitXmlOutput = false
59+
WorkingDir = null
60+
ShadowCopy = true
61+
Verbose = true
62+
XmlOutput = false
63+
TimeOut = TimeSpan.FromMinutes 5.
64+
OutputDir = null
65+
ErrorLevel = Error
66+
IncludeTraits = emptyTrait
67+
ExcludeTraits = emptyTrait }
68+
69+
/// DEPRECATED.
70+
/// Builds the command line arguments from the given parameter record and the given assemblies.
71+
/// [omit]
72+
[<Obsolete("This function will be removed in a future version.")>]
73+
let buildXUnitArgs parameters assembly =
74+
let fi = fileInfo assembly
75+
let name = fi.Name
76+
77+
let dir =
78+
if isNullOrEmpty parameters.OutputDir then String.Empty
79+
else Path.GetFullPath parameters.OutputDir
80+
81+
let traits includeExclude (name, values : string) =
82+
values.Split([| ',' |], System.StringSplitOptions.RemoveEmptyEntries)
83+
|> Seq.collect (fun value ->
84+
[| includeExclude
85+
sprintf "\"%s=%s\"" name value |])
86+
|> String.concat " "
87+
88+
new StringBuilder()
89+
|> appendFileNamesIfNotNull [ assembly ]
90+
|> appendIfFalse parameters.ShadowCopy "/noshadow"
91+
|> appendIfTrue (buildServer = TeamCity) "/teamcity"
92+
|> appendIfFalse parameters.Verbose "/silent"
93+
|> appendIfTrue parameters.XmlOutput (sprintf "/xml\" \"%s" (dir @@ (name + ".xml")))
94+
|> appendIfTrue parameters.HtmlOutput (sprintf "/html\" \"%s" (dir @@ (name + ".html")))
95+
|> appendIfTrue parameters.NUnitXmlOutput (sprintf "/nunit\" \"%s" (dir @@ (name + ".xml")))
96+
|> appendIfSome parameters.IncludeTraits (traits "/trait")
97+
|> appendIfSome parameters.ExcludeTraits (traits "/-trait")
98+
|> toText
99+
100+
/// DEPRECATED. See [`Fake.Testing.XUnit.xUnit`](fake-testing-xunit.html).
101+
///
102+
/// Runs xUnit unit tests in the given assemblies via the given xUnit runner.
103+
/// Will fail if the runner terminates with non-zero exit code for any of the assemblies.
104+
/// Offending assemblies will be listed in the error message.
105+
///
106+
/// The xUnit runner terminates with a non-zero exit code if any of the tests
107+
/// in the given assembly fail.
108+
/// ## Parameters
109+
///
110+
/// - `setParams` - Function used to manipulate the default XUnitParams value.
111+
/// - `assemblies` - Sequence of one or more assemblies containing xUnit unit tests.
112+
///
113+
/// ## Sample usage
114+
///
115+
/// Target "Test" (fun _ ->
116+
/// !! (testDir + @"\xUnit.Test.*.dll")
117+
/// |> xUnit (fun p -> {p with OutputDir = testDir })
118+
/// )
119+
[<Obsolete("Deprecated. This task will be removed in a future version. Open Fake.Testing to use the latest xUnit task.")>]
120+
let xUnit setParams assemblies =
121+
let details = separated ", " assemblies
122+
use __ = traceStartTaskUsing "xUnit" details
123+
let parameters = setParams XUnitDefaults
124+
125+
let runTests assembly =
126+
let args = buildXUnitArgs parameters assembly
127+
0 = ExecProcess (fun info ->
128+
info.FileName <- parameters.ToolPath
129+
info.WorkingDirectory <- parameters.WorkingDir
130+
info.Arguments <- args) parameters.TimeOut
131+
132+
let failedTests =
133+
[ for asm in List.ofSeq assemblies do
134+
if runTests asm |> not then yield asm ]
135+
136+
if not (List.isEmpty failedTests) then
137+
sprintf "xUnit failed for the following assemblies: %s" (separated ", " failedTests)
138+
|> match parameters.ErrorLevel with
139+
| Error | FailOnFirstError -> failwith
140+
| DontFailBuild -> traceImportant

0 commit comments

Comments
 (0)