forked from fsprojects/FSharpx.Extras
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.fsx
264 lines (219 loc) · 9.93 KB
/
build.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#r "./packages/FAKE.1.64.5/tools/FakeLib.dll"
open Fake
open System.IO
// properties
let currentDate = System.DateTime.UtcNow
let projectName = "FSharpx"
let version = if isLocalBuild then "1.5.28" else buildVersion
let coreSummary = "FSharpx is a library for the .NET platform implementing general functional constructs on top of the F# core library."
let projectSummary = "FSharpx is a library for the .NET platform implementing general functional constructs on top of the F# core library."
let authors = ["Steffen Forkmann"; "Daniel Mohl"; "Tomas Petricek"; "Ryan Riley"; "Mauricio Scheffer"; "Phil Trelford" ]
let mail = "[email protected]"
let homepage = "http://github.com/fsharp/fsharpx"
// .NET Frameworks
let net35 = "v3.5"
let net40 = "v4.0"
let net45 = "v4.5"
// directories
let buildDir = "./build/"
let packagesDir = "./packages/"
let testDir = "./test/"
let deployDir = "./deploy/"
let docsDir = "./docs/"
let targetPlatformDir = getTargetPlatformDir "4.0.30319"
let nugetDir package = sprintf "./nuget/%s/" package
let nugetLibDir package = nugetDir package @@ "lib"
let nugetDocsDir package = nugetDir package @@ "docs"
let packages = ["Core"; "Http"; "Observable"; "TypeProviders"]
let nugetDirHttp = "./nuget/Http/"
let nugetLibDirHttp = nugetDirHttp @@ "lib"
let nugetDocsDirHttp = nugetDirHttp @@ "docs"
let projectDesc = "FSharpx is a library for the .NET platform implementing general functional constructs on top of the F# core library. Its main target is F# but it aims to be compatible with all .NET languages wherever possible."
let rec getPackageDesc = function
| "Http" -> projectDesc + "\r\n\r\nThis library provides common features for working with HTTP applications."
| "Observable" -> projectDesc + "\r\n\r\nThis library implements a mini-Reactive Extensions (MiniRx) and was authored by Phil Trelford."
| "TypeProviders" -> projectDesc + "\r\n\r\nThis library is for the .NET platform implementing common type providers on top of the FSharpx.Core."
| _ -> projectDesc + "\r\n\r\nIt currently implements:\r\n\r\n* Several standard monads: State, Reader, Writer, Either, Continuation, Distribution\r\n* Iteratee\r\n* Validation applicative functor\r\n* General functions like flip\r\n* Additional functions around collections\r\n* Functions to make C# - F# interop easier."
// params
let target = getBuildParamOrDefault "target" "All"
let buildSpecific = hasBuildParam "v35" || hasBuildParam "v40" || hasBuildParam "v45"
let normalizeFrameworkVersion frameworkVersion =
let v = ("[^\\d]" >=> "") frameworkVersion
v.Substring(0,2)
let frameworkParams frameworkVersion = ["TargetFrameworkVersion", frameworkVersion; "DefineConstants", "NET" + normalizeFrameworkVersion frameworkVersion]
// tools
let fakeVersion = GetPackageVersion packagesDir "FAKE"
let fakePath = sprintf "%sFAKE.%s/tools" packagesDir fakeVersion
let nugetPath = "./lib/Nuget/nuget.exe"
let nunitVersion = GetPackageVersion packagesDir "NUnit.Runners"
let nunitPath = sprintf "%sNUnit.Runners.%s/Tools" packagesDir nunitVersion
// files
let appReferences frameworkVersion =
{ (!+ "./src/**/*.*proj") with
Excludes =
[yield "./src/**/*.Silverlight.*proj"
if frameworkVersion <> net45 then yield "./src/**/*.TypeProviders.*proj"
if frameworkVersion = net35 then
yield "./src/**/*.Async.fsproj"
yield "./src/**/*.Http.fsproj" // TODO: why is that?
yield "./src/**/*.Observable.fsproj" // TODO: why is that?
] }
|> Scan
let testReferences frameworkVersion =
{ (!+ "./tests/**/*.*proj") with
Excludes = [if frameworkVersion <> net45 then yield "./tests/**/*.TypeProviders.*proj"] }
|> Scan
// targets
Target "Clean" (fun _ ->
CleanDirs [buildDir; testDir; deployDir; docsDir]
packages
|> Seq.iter (fun x -> CleanDirs [nugetDir x; nugetLibDir x; nugetDocsDir x])
)
Target "AssemblyInfo" (fun _ ->
AssemblyInfo (fun p ->
{p with
CodeLanguage = FSharp
AssemblyVersion = version
AssemblyTitle = projectName
AssemblyDescription = getPackageDesc "Core"
Guid = "1e95a279-c2a9-498b-bc72-6e7a0d6854ce"
OutputFileName = "./src/FSharpx.Core/AssemblyInfo.fs" })
AssemblyInfo (fun p ->
{p with
CodeLanguage = FSharp
AssemblyVersion = version
AssemblyTitle = "FSharpx.Http"
AssemblyDescription = getPackageDesc "Http"
Guid = "60F3BB81-5449-45DD-A217-B6045327680C"
OutputFileName = "./src/FSharpx.Http/AssemblyInfo.fs" })
AssemblyInfo (fun p ->
{p with
CodeLanguage = FSharp
AssemblyVersion = version
AssemblyTitle = "FSharpx.Observable"
AssemblyDescription = getPackageDesc "Observable"
Guid = "2E802F54-9CD0-4B0A-B834-5C5979403B50"
OutputFileName = "./src/FSharpx.Observable/AssemblyInfo.fs" })
AssemblyInfo (fun p ->
{p with
CodeLanguage = FSharp
AssemblyVersion = version
AssemblyTitle = "FSharpx.TypeProviders"
AssemblyDescription = getPackageDesc "TypeProviders"
Guid = "89B6AF94-507D-4BE0-98FA-A5124884DBA8"
OutputFileName = "./src/FSharpx.TypeProviders/AssemblyInfo.fs" })
)
let buildAppTarget = TargetTemplate (fun frameworkVersion ->
CleanDir buildDir
appReferences frameworkVersion
|> MSBuild buildDir "Build" (["Configuration","Release"] @ frameworkParams frameworkVersion)
|> Log "AppBuild-Output: "
)
let buildTestTarget = TargetTemplate (fun frameworkVersion ->
CleanDir testDir
testReferences frameworkVersion
|> MSBuild testDir "Build" ["Configuration","Debug"]
|> Log "TestBuild-Output: "
)
let testTarget = TargetTemplate (fun frameworkVersion ->
ActivateFinalTarget "CloseTestRunner"
!! (testDir + "/*.Tests.dll")
|> NUnit (fun p ->
{p with
ToolPath = nunitPath
DisableShadowCopy = true
OutputFile = testDir + sprintf "TestResults.%s.xml" frameworkVersion })
)
Target "GenerateDocumentation" (fun _ ->
!! (buildDir + "*.dll")
|> Docu (fun p ->
{p with
ToolPath = fakePath + "/docu.exe"
TemplatesPath = "./lib/templates"
OutputPath = docsDir })
)
Target "ZipDocumentation" (fun _ ->
!! (docsDir + "/**/*.*")
|> Zip docsDir (deployDir + sprintf "Documentation-%s.zip" version)
)
let prepareNugetTarget = TargetTemplate (fun frameworkVersion ->
packages
|> Seq.iter (fun package ->
let frameworkSubDir = nugetLibDir package @@ normalizeFrameworkVersion frameworkVersion
CleanDir frameworkSubDir
[for ending in ["dll";"pdb";"xml"] ->
sprintf "%sFsharpx.%s.%s" buildDir package ending]
|> Seq.filter (fun f -> File.Exists f)
|> CopyTo frameworkSubDir)
)
let buildFrameworkVersionTarget = TargetTemplate (fun frameworkVersion -> ())
let generateTargets() =
[if hasBuildParam "v35" then yield net35
if (hasBuildParam "v40") || (not buildSpecific) then yield net40
if hasBuildParam "v45" then yield net45]
|> Seq.fold
(fun dependency frameworkVersion ->
tracefn "Generating targets for .NET %s" frameworkVersion
let v = normalizeFrameworkVersion frameworkVersion
let buildApp = sprintf "BuildApp_%s" v
let buildTest = sprintf "BuildTest_%s" v
let test = sprintf "Test_%s" v
let prepareNuget = sprintf "PrepareNuget_%s" v
let buildFrameworkVersion = sprintf "Build_%s" v
buildAppTarget buildApp frameworkVersion
buildTestTarget buildTest frameworkVersion
testTarget test frameworkVersion
prepareNugetTarget prepareNuget frameworkVersion
buildFrameworkVersionTarget buildFrameworkVersion frameworkVersion
dependency ==> buildApp ==> buildTest ==> test ==> prepareNuget ==> buildFrameworkVersion)
"AssemblyInfo"
let nugetTarget = TargetTemplate (fun package ->
XCopy (docsDir |> FullName) (nugetDocsDir package)
[ "LICENSE.md" ] |> CopyTo (nugetDir package)
NuGet (fun p ->
{p with
Authors = authors
Project = projectName + "." + package
Description = getPackageDesc package
Version = version
OutputPath = nugetDir package
ToolPath = nugetPath
AccessKey = getBuildParamOrDefault "nugetkey" ""
Dependencies =
if package = "Core" || package = "TypeProviders" then p.Dependencies else
[projectName + ".Core", RequireExactly (NormalizeVersion version)]
Publish = hasBuildParam "nugetkey" })
"FSharpx.Core.nuspec"
!! (nugetDir package + sprintf "FSharpx.%s.*.nupkg" package)
|> CopyTo deployDir
)
let generateNugetTargets() =
packages
|> Seq.fold
(fun dependency package ->
tracefn "Generating nuget target for package %s" package
let buildPackage = sprintf "Nuget_%s" package
nugetTarget buildPackage package
dependency ==> buildPackage)
"ZipDocumentation"
Target "DeployZip" (fun _ ->
!! (buildDir + "/**/*.*")
|> Zip buildDir (deployDir + sprintf "%s-%s.zip" projectName version)
)
FinalTarget "CloseTestRunner" (fun _ ->
ProcessHelper.killProcess "nunit-agent.exe"
)
Target "Deploy" DoNothing
Target "All" DoNothing
// Build order
"Clean"
==> "AssemblyInfo"
==> (generateTargets())
==> "GenerateDocumentation"
==> "ZipDocumentation"
==> (generateNugetTargets())
==> "DeployZip"
==> "Deploy"
"All" <== ["Deploy"]
// Start build
Run target