forked from fsprojects/FAKE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
378 lines (318 loc) · 13.8 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#I @"packages/build/FAKE/tools/"
#r @"FakeLib.dll"
#r @"packages/Mono.Cecil/lib/net45/Mono.Cecil.dll"
#I "packages/build/SourceLink.Fake/tools/"
#load "packages/build/SourceLink.Fake/tools/SourceLink.fsx"
open Fake
open Fake.Git
open Fake.FSharpFormatting
open System.IO
open SourceLink
open Fake.ReleaseNotesHelper
// properties
let projectName = "FAKE"
let projectSummary = "FAKE - F# Make - Get rid of the noise in your build scripts."
let projectDescription = "FAKE - F# Make - is a build automation tool for .NET. Tasks and dependencies are specified in a DSL which is integrated in F#."
let authors = ["Steffen Forkmann"; "Mauricio Scheffer"; "Colin Bull"]
let gitRaw = environVarOrDefault "gitRaw" "https://raw.github.com/fsharp"
let release = LoadReleaseNotes "RELEASE_NOTES.md"
let packages =
["FAKE.Core",projectDescription
"FAKE.Gallio",projectDescription + " Extensions for Gallio"
"FAKE.IIS",projectDescription + " Extensions for IIS"
"FAKE.FluentMigrator",projectDescription + " Extensions for FluentMigrator"
"FAKE.SQL",projectDescription + " Extensions for SQL Server"
"FAKE.Experimental",projectDescription + " Experimental Extensions"
"FAKE.Deploy.Lib",projectDescription + " Extensions for FAKE Deploy"
projectName,projectDescription + " This package bundles all extensions."
"FAKE.Lib",projectDescription + " FAKE helper functions as library"]
let buildDir = "./build"
let testDir = "./test"
let docsDir = "./docs"
let apidocsDir = "./docs/apidocs/"
let nugetDir = "./nuget"
let reportDir = "./report"
let packagesDir = "./packages"
let buildMergedDir = buildDir </> "merged"
let additionalFiles = [
"License.txt"
"README.markdown"
"RELEASE_NOTES.md"
"./packages/FSharp.Core/lib/net40/FSharp.Core.sigdata"
"./packages/FSharp.Core/lib/net40/FSharp.Core.optdata"]
// Targets
Target "Clean" (fun _ -> CleanDirs [buildDir; testDir; docsDir; apidocsDir; nugetDir; reportDir])
open Fake.AssemblyInfoFile
Target "RenameFSharpCompilerService" (fun _ ->
for framework in ["net40"; "net45"] do
let dir = __SOURCE_DIRECTORY__ </> "packages/FSharp.Compiler.Service/lib" </> framework
let targetFile = dir </> "FAKE.FSharp.Compiler.Service.dll"
DeleteFile targetFile
let reader = new Mono.Cecil.DefaultAssemblyResolver()
reader.AddSearchDirectory(dir)
reader.AddSearchDirectory(__SOURCE_DIRECTORY__ </> "packages/FSharp.Core/lib/net40")
let readerParams = new Mono.Cecil.ReaderParameters(AssemblyResolver = reader)
let asem = Mono.Cecil.AssemblyDefinition.ReadAssembly(dir </> "FSharp.Compiler.Service.dll", readerParams)
asem.Name <- new Mono.Cecil.AssemblyNameDefinition("FAKE.FSharp.Compiler.Service", new System.Version(1,0,0,0))
asem.Write(dir </> "FAKE.FSharp.Compiler.Service.dll")
)
Target "SetAssemblyInfo" (fun _ ->
let common = [
Attribute.Product "FAKE - F# Make"
Attribute.Version release.AssemblyVersion
Attribute.InformationalVersion release.AssemblyVersion
Attribute.FileVersion release.AssemblyVersion]
[Attribute.Title "FAKE - F# Make Command line tool"
Attribute.Guid "fb2b540f-d97a-4660-972f-5eeff8120fba"] @ common
|> CreateFSharpAssemblyInfo "./src/app/FAKE/AssemblyInfo.fs"
[Attribute.Title "FAKE - F# Make Deploy tool"
Attribute.Guid "413E2050-BECC-4FA6-87AA-5A74ACE9B8E1"] @ common
|> CreateFSharpAssemblyInfo "./src/app/Fake.Deploy/AssemblyInfo.fs"
[Attribute.Title "FAKE - F# Make Deploy Web"
Attribute.Guid "27BA7705-3F57-47BE-B607-8A46B27AE876"] @ common
|> CreateFSharpAssemblyInfo "./src/deploy.web/Fake.Deploy.Web/AssemblyInfo.fs"
[Attribute.Title "FAKE - F# Make Deploy Lib"
Attribute.Guid "AA284C42-1396-42CB-BCAC-D27F18D14AC7"] @ common
|> CreateFSharpAssemblyInfo "./src/app/Fake.Deploy.Lib/AssemblyInfo.fs"
[Attribute.Title "FAKE - F# Make Lib"
Attribute.InternalsVisibleTo "Test.FAKECore"
Attribute.Guid "d6dd5aec-636d-4354-88d6-d66e094dadb5"] @ common
|> CreateFSharpAssemblyInfo "./src/app/FakeLib/AssemblyInfo.fs"
[Attribute.Title "FAKE - F# Make SQL Lib"
Attribute.Guid "A161EAAF-EFDA-4EF2-BD5A-4AD97439F1BE"] @ common
|> CreateFSharpAssemblyInfo "./src/app/Fake.SQL/AssemblyInfo.fs"
[Attribute.Title "FAKE - F# Make Experimental Lib"
Attribute.Guid "5AA28AED-B9D8-4158-A594-32FE5ABC5713"] @ common
|> CreateFSharpAssemblyInfo "./src/app/Fake.Experimental/AssemblyInfo.fs"
[Attribute.Title "FAKE - F# Make FluentMigrator Lib"
Attribute.Guid "E18BDD6F-1AF8-42BB-AEB6-31CD1AC7E56D"] @ common
|> CreateFSharpAssemblyInfo "./src/app/Fake.FluentMigrator/AssemblyInfo.fs"
)
Target "BuildSolution" (fun _ ->
MSBuildWithDefaults "Build" ["./FAKE.sln"; "./FAKE.Deploy.Web.sln"]
|> Log "AppBuild-Output: "
)
Target "GenerateDocs" (fun _ ->
let source = "./help"
let template = "./help/literate/templates/template-project.html"
let templatesDir = "./help/templates/reference/"
let githubLink = "https://github.com/fsharp/FAKE"
let projInfo =
[ "page-description", "FAKE - F# Make"
"page-author", separated ", " authors
"project-author", separated ", " authors
"github-link", githubLink
"project-github", "http://github.com/fsharp/fake"
"project-nuget", "https://www.nuget.org/packages/FAKE"
"root", "http://fsharp.github.io/FAKE"
"project-name", "FAKE - F# Make" ]
Copy source ["RELEASE_NOTES.md"]
CreateDocs source docsDir template projInfo
let dllFiles =
!! "./build/**/Fake.*.dll"
++ "./build/FakeLib.dll"
-- "./build/**/Fake.Experimental.dll"
-- "./build/**/FSharp.Compiler.Service.dll"
-- "./build/**/FAKE.FSharp.Compiler.Service.dll"
-- "./build/**/Fake.IIS.dll"
-- "./build/**/Fake.Deploy.Lib.dll"
CreateDocsForDlls apidocsDir templatesDir (projInfo @ ["--libDirs", "./build"]) (githubLink + "/blob/master") dllFiles
WriteStringToFile false "./docs/.nojekyll" ""
CopyDir (docsDir @@ "content") "help/content" allFiles
CopyDir (docsDir @@ "pics") "help/pics" allFiles
)
Target "CopyLicense" (fun _ ->
CopyTo buildDir additionalFiles
)
Target "Test" (fun _ ->
!! (testDir @@ "Test.*.dll")
|> Seq.filter (fun fileName -> if isMono then fileName.ToLower().Contains "deploy" |> not else true)
|> MSpec (fun p ->
{p with
ToolPath = findToolInSubPath "mspec-x86-clr4.exe" (currentDirectory @@ "tools" @@ "MSpec")
ExcludeTags = ["HTTP"]
HtmlOutputDir = reportDir})
!! (testDir @@ "Test.*.dll")
++ (testDir @@ "FsCheck.Fake.dll")
|> 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"
// Replace the include line to use the newly build FakeLib, otherwise things will be weird.
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 ->
let proj = VsProj.LoadRelease f
let url = sprintf "%s/%s/{0}/%%var2%%" gitRaw projectName
SourceLink.Index proj.CompilesNotLinked proj.OutputFilePdb __SOURCE_DIRECTORY__ url )
let pdbFakeLib = "./build/FakeLib.pdb"
CopyFile "./build/FAKE.Deploy" pdbFakeLib
CopyFile "./build/FAKE.Deploy.Lib" pdbFakeLib
)
Target "ILRepack" (fun _ ->
CreateDir buildMergedDir
let internalizeIn filename =
let toPack =
[filename; "FSharp.Compiler.Service.dll"]
|> List.map (fun l -> buildDir </> l)
|> separated " "
let targetFile = buildMergedDir </> filename
let result =
ExecProcess (fun info ->
info.FileName <- currentDirectory </> "packages" </> "build" </> "ILRepack" </> "tools" </> "ILRepack.exe"
info.Arguments <- sprintf "/verbose /lib:%s /ver:%s /out:%s %s" buildDir release.AssemblyVersion targetFile toPack) (System.TimeSpan.FromMinutes 5.)
if result <> 0 then failwithf "Error during ILRepack execution."
CopyFile (buildDir </> filename) targetFile
internalizeIn "FAKE.exe"
!! (buildDir </> "FSharp.Compiler.Service.**")
|> Seq.iter DeleteFile
DeleteDir buildMergedDir
)
Target "CreateNuGet" (fun _ ->
let set64BitCorFlags files =
files
|> Seq.iter (fun file ->
let args =
{ Program = "lib" @@ "corflags.exe"
WorkingDirectory = directory file
CommandLine = "/32BIT- /32BITPREF- " + quoteIfNeeded file
Args = [] }
printfn "%A" args
shellExec args |> ignore)
let x64ify package =
{ package with
Dependencies = package.Dependencies |> List.map (fun (pkg, ver) -> pkg + ".x64", ver)
Project = package.Project + ".x64" }
for package,description in packages do
let nugetDocsDir = nugetDir @@ "docs"
let nugetToolsDir = nugetDir @@ "tools"
let nugetLibDir = nugetDir @@ "lib"
let nugetLib451Dir = nugetLibDir @@ "net451"
CleanDir nugetDocsDir
CleanDir nugetToolsDir
CleanDir nugetLibDir
DeleteDir nugetLibDir
DeleteFile "./build/FAKE.Gallio/Gallio.dll"
let deleteFCS dir =
//!! (dir </> "FSharp.Compiler.Service.**")
//|> Seq.iter DeleteFile
()
match package with
| p when p = projectName ->
!! (buildDir @@ "**/*.*") |> Copy nugetToolsDir
CopyDir nugetDocsDir docsDir allFiles
deleteFCS nugetToolsDir
| p when p = "FAKE.Core" ->
!! (buildDir @@ "*.*") |> Copy nugetToolsDir
CopyDir nugetDocsDir docsDir allFiles
deleteFCS nugetToolsDir
| p when p = "FAKE.Lib" ->
CleanDir nugetLib451Dir
!! (buildDir @@ "FakeLib.dll") |> Copy nugetLib451Dir
deleteFCS nugetLib451Dir
| _ ->
CopyDir nugetToolsDir (buildDir @@ package) allFiles
CopyTo nugetToolsDir additionalFiles
!! (nugetToolsDir @@ "*.srcsv") |> DeleteFiles
let setParams p =
{p with
Authors = authors
Project = package
Description = description
Version = release.NugetVersion
OutputPath = nugetDir
Summary = projectSummary
ReleaseNotes = release.Notes |> toLines
Dependencies =
(if package <> "FAKE.Core" && package <> projectName && package <> "FAKE.Lib" then
["FAKE.Core", RequireExactly (NormalizeVersion release.AssemblyVersion)]
else p.Dependencies )
Publish = false }
NuGet setParams "fake.nuspec"
!! (nugetToolsDir @@ "FAKE.exe") |> set64BitCorFlags
NuGet (setParams >> x64ify) "fake.nuspec"
)
Target "PublishNuget" (fun _ ->
Paket.Push(fun p ->
{ p with
DegreeOfParallelism = 2
WorkingDir = nugetDir })
)
Target "ReleaseDocs" (fun _ ->
CleanDir "gh-pages"
cloneSingleBranch "" "https://github.com/fsharp/FAKE.git" "gh-pages" "gh-pages"
fullclean "gh-pages"
CopyRecursive "docs" "gh-pages" true |> printfn "%A"
CopyFile "gh-pages" "./Samples/FAKE-Calculator.zip"
StageAll "gh-pages"
Commit "gh-pages" (sprintf "Update generated documentation %s" release.NugetVersion)
Branches.push "gh-pages"
)
Target "Release" (fun _ ->
StageAll ""
Commit "" (sprintf "Bump version to %s" release.NugetVersion)
Branches.push ""
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
"Clean"
==> "RenameFSharpCompilerService"
==> "SetAssemblyInfo"
==> "BuildSolution"
//==> "ILRepack"
==> "Test"
==> "Bootstrap"
==> "Default"
==> "CopyLicense"
=?> ("GenerateDocs", isLocalBuild && not isLinux)
=?> ("SourceLink", isLocalBuild && not isLinux)
=?> ("CreateNuGet", not isLinux)
=?> ("ReleaseDocs", isLocalBuild && not isLinux)
==> "PublishNuget"
==> "Release"
// start build
RunTargetOrDefault "Default"