-
Notifications
You must be signed in to change notification settings - Fork 42
/
build.fsx
443 lines (361 loc) · 17.6 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#I "packages/FAKE/tools"
#r "packages/FAKE/tools/FakeLib.dll"
#r "packages/DotNetZip/lib/net20/DotNetZip.dll"
#r "System.Xml.Linq"
open System.IO
open System.Xml.Linq
open System.Linq
open Fake
open Fake.ReleaseNotesHelper
// --------------------------------------------------------------------------------------
// FsLab packages and configuration
// --------------------------------------------------------------------------------------
let buildDir = "bin"
let project = "FsLab"
let projectRunner = "FSharp.Literate.Scripts"
let authors = ["FsLab Contributors"]
let summary = "F# packages for data science"
let summaryRunner = "FsLab report generator"
let description = """
FsLab is a combination package that supports doing data science with
F#. FsLab includes literate scripting converted to HTML and PDF, and
by default references Deedle (a data frame library), FSharp.Data (for
data access) and XPlot (for visualization). You can optionally add any
other nuget packages."""
let descriptionRunner = """
This package contains a library for turning FsLab experiments written as script files
into HTML and LaTeX reports."""
let tags = "F# fsharp deedle series statistics data science r type provider mathnet machine learning ML"
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
/// List of packages included in FsLab
/// (Version information is generated automatically based on 'FsLab.nuspec')
let packages =
[ "Deedle"
//"Deedle.RPlugin"
//"FSharp.Charting"
"FSharp.Data"
"MathNet.Numerics"
"MathNet.Numerics.FSharp"
//"DynamicInterop"
//"R.NET.Community"
//"R.NET.Community.FSharp"
//"RProvider"
"Suave"
// XPlot + dependencies
"XPlot.Plotly"
"XPlot.GoogleCharts"
"XPlot.GoogleCharts.Deedle"
"Google.DataTable.Net.Wrapper"
"Newtonsoft.Json" ]
|> List.map (fun p -> p, GetPackageVersion "packages" p)
/// Returns the subfolder where the DLLs are located
let getNetSubfolder package =
match package with
| "Google.DataTable.Net.Wrapper" -> "lib"
| "FSharp.Data" -> "lib/net45"
| _ when package.StartsWith("XPlot") -> "lib/net45"
| _ -> "lib/net40"
/// Returns assemblies that should be referenced for each package
let getAssemblies package =
match package with
| "Deedle.RPlugin" -> ["Deedle.RProvider.Plugin.dll"]
| "FSharp.Charting" -> ["System.Windows.Forms.DataVisualization.dll"; "FSharp.Charting.dll"]
| "RProvider" -> ["RProvider.Runtime.dll"; "RProvider.dll"]
| "R.NET.Community" -> ["RDotNet.dll"; "RDotNet.NativeLibrary.dll"]
| "R.NET.Community.FSharp" -> ["RDotNet.FSharp.dll"]
| package -> [package + ".dll"]
let exec exe args workingDir =
printfn "%s %s (in %s)" exe args workingDir
let code = Shell.Exec(exe, args, workingDir)
if code <> 0 then failwithf "%s %s failed, error code %d" exe args code
// --------------------------------------------------------------------------------------
// FAKE targets for building FsLab and FSharp.Literate.Scripts NuGet packages
// --------------------------------------------------------------------------------------
// Read release notes & version info from RELEASE_NOTES.md
let release = LoadReleaseNotes "RELEASE_NOTES.md"
let packageVersions = dict (packages @ ["FSharp.Literate.Scripts", release.NugetVersion])
Target "Clean" (fun _ ->
CleanDirs ["temp"; "nuget"; buildDir ]
)
Target "UpdateFsLabScript" (fun _ ->
// Get directory with binaries for a given package
let getLibDir package = package + "/" + (getNetSubfolder package)
let getLibDirVer package = package + "." + packageVersions.[package] + "/" + (getNetSubfolder package)
// Additional lines to be included in FsLab.fsx
let nowarn = ["#nowarn \"211\""; "#I __SOURCE_DIRECTORY__"]
let extraInitAll = File.ReadLines(__SOURCE_DIRECTORY__ + "/src/FsLab.fsx") |> Array.ofSeq
let extraInit = extraInitAll |> Array.skipWhile (fun s -> not (s.Contains "***FsLab.fsx***")) |> List.ofArray
// Generate #I for all library, for all possible folder
let includes =
[ for package, _ in packages do
yield sprintf "#I \"../packages/%s\"" (getLibDir package)
yield sprintf "#I \"../%s\"" (getLibDir package)
yield sprintf "#I \"../packages/%s\"" (getLibDirVer package)
yield sprintf "#I \"../%s\"" (getLibDirVer package) ]
// Generate #r for all libraries
let references =
packages
|> List.collect (fst >> getAssemblies)
|> List.map (sprintf "#r \"%s\"")
// Generate #load commands to load AddHtmlPrinter and AddPrinter calls
let loads =
[ yield ""
for f in Directory.GetFiles("src/Shared") do
yield sprintf "#load \"Shared/%s\"" (Path.GetFileName f)
yield "#if !NO_FSI_ADDPRINTER"
yield "#if HAS_FSI_ADDHTMLPRINTER"
for f in Directory.GetFiles("src/Html") do
yield sprintf "#load \"Html/%s\"" (Path.GetFileName f)
yield "#else"
for f in Directory.GetFiles("src/Text") do
yield sprintf "#load \"Text/%s\"" (Path.GetFileName f)
yield "#endif"
yield "#endif\n" ]
// Write everything to the 'temp/FsLab.fsx' file
let lines = nowarn @ includes @ references @ loads @ extraInit
let oldLines = File.ReadAllLines(__SOURCE_DIRECTORY__ + "/src/FsLab.fsx")
if Array.ofList lines <> oldLines then
File.WriteAllLines(__SOURCE_DIRECTORY__ + "/src/FsLab.fsx", lines)
// Check that FsLab.fsx now compiles in FSI.EXE mode
exec "fsc" "src/FsLab.fsx -r:FSharp.Compiler.Interactive.Settings.dll --nowarn:988 --nocopyfsharpcore --out:bin/test-compile-FsLab.exe" "."
// Check that FsLab.fsx now compiles in HAS_FSI_ADDHTMLPRINTER (fsx2html, iFSharp) ) mode
exec "fsc" "src/Mock/Mock.fsx src/FsLab.fsx -r:FSharp.Compiler.Interactive.Settings.dll --nowarn:988 --define:HAS_FSI_ADDHTMLPRINTER --nocopyfsharpcore --out:bin/test-compile-FsLab-HtmlPrinters.exe" "."
)
Target "BuildProjects" (fun _ ->
MSBuildRelease "" "Restore" [ "FsLab.sln" ] |> ignore
MSBuildRelease "" "Rebuild" [ "FsLab.sln" ] |> ignore
)
Target "UpdateNuSpec" (fun _ ->
// Update included files in FsLab.nuspec to include formatting scripts
let (!) n = XName.Get(n)
let path = "src/FsLab.nuspec"
let doc = XDocument.Load(path)
let files = doc.Descendants(XName.Get "files").First()
files.RemoveAll()
files.Add(XElement(!"file", XAttribute(!"src", "../src/FsLab.fsx"), XAttribute(!"target", ".")))
let includes =
[ "src/Shared"; "src/Text"; "src/Html"; "src/Themes" ]
|> Seq.collect Directory.GetFiles
for f in includes do
let subdir = Path.GetDirectoryName(f).Substring(4)
files.Add(XElement(!"file", XAttribute(!"src", "../" + f.Replace("\\", "/")), XAttribute(!"target", subdir)))
doc.Save(path + ".updated")
DeleteFile path
Rename path (path + ".updated")
)
Target "BuildNuGets" (fun _ ->
let specificVersion (name, version) = name, sprintf "[%s]" version
NuGet (fun p ->
{ p with
Dependencies = packages |> List.map specificVersion
Authors = authors
Project = project
Summary = summary
Description = description
Version = release.NugetVersion
ReleaseNotes = release.Notes |> toLines
Tags = tags
OutputPath = buildDir
WorkingDir = "nuget"
AccessKey = getBuildParamOrDefault "nugetkey" ""
Publish = hasBuildParam "nugetkey" })
("src/" + project + ".nuspec")
NuGet (fun p ->
{ p with
Dependencies = packages |> List.map specificVersion
Authors = authors
Project = projectRunner
Summary = summaryRunner
Description = descriptionRunner
Version = release.NugetVersion
ReleaseNotes = release.Notes |> toLines
Tags = tags
OutputPath = buildDir
WorkingDir = "nuget"
AccessKey = getBuildParamOrDefault "nugetkey" ""
Publish = hasBuildParam "nugetkey" })
("src/fsx2html/FSharp.Literate.Scripts.nuspec")
)
// Update some files in the template directories and check the templates build and run
Target "UpdateAndCheckTemplates" (fun _ ->
// Place the paket support in the templates
ensureDirectory "src/journal/.paket"
!! ".paket/paket.bootstrapper.exe" |> CopyFiles "src/journal/.paket"
!! ".paket/Paket.Restore.targets" |> CopyFiles "src/journal/.paket"
// Copy the paket.dependencies to the various templates
let paketDepLines = File.ReadAllLines("paket.dependencies") |> Seq.takeWhile (fun s -> not (s.Contains("--CUT--")))
File.WriteAllLines("src/journal/paket.dependencies", paketDepLines)
File.AppendAllLines("src/journal/paket.dependencies", [sprintf "source ../../bin"])
File.AppendAllLines("src/journal/paket.dependencies", [sprintf "nuget FsLab %s" release.NugetVersion])
File.AppendAllLines("src/journal/paket.dependencies", [sprintf "nuget FSharp.Literate.Scripts %s" release.NugetVersion])
// Create/update the paket.lock and do a local install of packages
exec ".paket/paket.exe" "update" "src/journal"
// Check that journal/build.fsx compiles in FSI.EXE mode
exec "fsc" "build.fsx -r:FSharp.Compiler.Interactive.Settings.dll --nowarn:988 --nocopyfsharpcore --out:../../bin/test-compile-journal-build.fsx" "src/journal"
// Check that journal/build.fsx runs in FAKE mode
exec "packages/FAKE/tools/FAKE.exe" "build.fsx html" "src/journal"
exec "packages/FAKE/tools/FAKE.exe" "build.fsx latex" "src/journal"
// Replace the reference to the local source with the place where it will be when published
File.WriteAllText("src/journal/paket.dependencies", File.ReadAllText("src/journal/paket.dependencies").Replace("source ../../bin", "source https://api.nuget.org/v3/index.json"))
File.WriteAllText("src/journal/paket.lock", File.ReadAllText("src/journal/paket.lock").Replace("remote: ../../bin", "remote: https://api.nuget.org/v3/index.json"))
)
// --------------------------------------------------------------------------------------
// FAKE targets for building the FsLab templates
// --------------------------------------------------------------------------------------
Target "PlaceTempFiles" (fun _ ->
// Generate ZIPs with item templates
ensureDirectory "temp/experiments"
for experiment in [(*"walkthrough-with-r";*) "walkthrough"; "experiment"] do
ensureDirectory ("temp/experiments/" + experiment)
CopyRecursive ("src/experiments/" + experiment) ("temp/experiments/" + experiment) true |> ignore
"misc/item.png" |> CopyFile ("temp/experiments/" + experiment + "/__TemplateIcon.png")
"misc/preview.png" |> CopyFile ("temp/experiments/" + experiment + "/__PreviewImage.png")
!! ("temp/experiments/" + experiment + "/**")
|> Zip ("temp/experiments/" + experiment) ("temp/experiments/" + experiment + ".zip")
// Generate ZIP with project template
ensureDirectory "temp/journal"
ensureDirectory "temp/journal/styles"
!! "src/journal/build.*"
++ "src/journal/paket.dependencies"
++ "src/journal/paket.references"
++ "src/journal/paket.lock"
++ "src/journal/*.fs*"
|> CopyFiles "temp/journal"
CopyRecursive "src/styles" "temp/journal/styles" true |> ignore
ensureDirectory "temp/journal/.paket"
".paket/paket.bootstrapper.exe" |> CopyFile "temp/journal/.paket/paket.exe"
".paket/paket.bootstrapper.exe" |> CopyFile "temp/journal/.paket/paket.bootstrapper.exe"
".paket/Paket.Restore.targets" |> CopyFile "temp/journal/.paket/Paket.Restore.targets"
)
// Build Zip templates
Target "BuildZipTemplates" (fun _ ->
!! "temp/journal/**" |> Zip "temp/journal" "temp/journal.zip"
)
Target "UpdateVSIXManifest" (fun _ ->
/// Update version number in the VSIX manifest file of the template
let (!) n = XName.Get(n, "http://schemas.microsoft.com/developer/vsx-schema/2011")
let path = "src/vs-templates/source.extension.vsixmanifest"
let vsix = XDocument.Load(path)
let ident = vsix.Descendants(!"Identity").First()
ident.Attribute(XName.Get "Version").Value <- release.AssemblyVersion
vsix.Save(path + ".updated")
DeleteFile path
Rename path (path + ".updated")
)
Target "BuildVsTemplates" (fun _ ->
// Create directory for the Template project
CopyRecursive "temp/journal" "temp/vsjournal/" true |> ignore
CopyRecursive "src/vs-templates/journal" "temp/vsjournal/" true |> ignore
!! "temp/vsjournal/**" |> Zip "temp/vsjournal" "temp/vsjournal.zip"
"misc/item.png" |> CopyFile "temp/vsjournal/__TemplateIcon.png"
"misc/preview.png" |> CopyFile "temp/vsjournal/__PreviewImage.png"
// Zip it up
CopyRecursive "src/vs-templates" "temp/vs-templates/" true |> ignore
// Copy ItemTemplates
ensureDirectory "temp/vs-templates/ItemTemplates"
!! "temp/experiments/*.zip"
|> CopyFiles "temp/vs-templates/ItemTemplates"
// Copy ProjectTemplates
ensureDirectory "temp/vs-templates/ProjectTemplates"
"temp/vsjournal.zip" |> CopyFile "temp/vs-templates/FsLab Journal.zip"
"temp/vsjournal.zip" |> CopyFile "temp/vs-templates/ProjectTemplates/FsLab Journal.zip"
// Copy other files
"misc/logo.png" |> CopyFile "temp/vs-templates/logo.png"
"misc/preview.png" |> CopyFile "temp/vs-templates/preview.png"
!! "temp/vs-templates/FsLab.VsTemplates.sln"
|> MSBuildDebug "" "Rebuild"
|> ignore
"temp/vs-templates/bin/Debug/FsLab.VsTemplates.vsix" |> CopyFile (buildDir + "/FsLab.VsTemplates.vsix")
)
// Build a BuildNuGets package containing "Dotnet new" templates
Target "BuildDotnetTemplates" (fun _ ->
// Create directory for the Template project
CopyRecursive "src/dotnet-templates" "temp/dotnet-templates/" true |> ignore
// Copy ItemTemplates
//ensureDirectory "temp/dotnet-templates/ItemTemplates"
//!! "temp/experiments/*.zip"
//|> CopyFiles "temp/vs-templates/ItemTemplates"
// Copy ProjectTemplates
//ensureDirectory "temp/vs-templates/ProjectTemplates"
CopyRecursive "temp/journal" "temp/dotnet-templates/journal/" true |> ignore
// Copy other files
"misc/logo.png" |> CopyFile "temp/dotnet-templates/logo.png"
"misc/preview.png" |> CopyFile "temp/dotnet-templates/preview.png"
NuGetHelper.NuGetPack (fun p ->
{ p with
WorkingDir = "temp/dotnet-templates"
OutputPath = "./" + buildDir + "/"
Version = release.NugetVersion
ReleaseNotes = toLines release.Notes}) @"temp/dotnet-templates/FsLab.Templates.nuspec"
)
Target "TestDotnetTemplatesNuGet" (fun _ ->
// Globally install the templates from the template nuget package we just built
DotNetCli.RunCommand id ("new -i " + buildDir + "/FsLab.Templates." + release.NugetVersion + ".nupkg")
let testAppName = "testapp2" + string (abs (hash System.DateTime.Now.Ticks) % 100)
// Instantiate the template. TODO: additional parameters and variations
CleanDir testAppName
DotNetCli.RunCommand id (sprintf "new fslab-journal -n %s -lang F#" testAppName)
// Enable the local package source in paket.dependencies and paket.lock. A total hack.
let paketDepFile = sprintf "%s/paket.dependencies" testAppName
File.WriteAllText(paketDepFile, File.ReadAllText(paketDepFile).Replace("source https://api.nuget.org/v3/index.json","source ../bin"))
let paketLockFile = sprintf "%s/paket.lock" testAppName
File.WriteAllText(paketLockFile, File.ReadAllText(paketLockFile).Replace("remote: https://api.nuget.org/v3/index.json","remote: ../bin"))
let pkgs = Path.GetFullPath(buildDir)
// When restoring, using the bin as a package source to pick up the package we just compiled
DotNetCli.RunCommand id (sprintf "restore %s/%s.fsproj --source https://api.nuget.org/v3/index.json --source %s" testAppName testAppName pkgs)
let slash = if isUnix then "\\" else ""
for c in ["Debug"; "Release"] do
for p in ["Any CPU"] do
exec "msbuild" (sprintf "%s/%s.fsproj /p:Platform=\"%s\" /p:Configuration=%s /p:PackageSources=%s\"https://api.nuget.org/v3/index.json%s;%s%s\"" testAppName testAppName p c slash slash pkgs slash) "."
let slash = if isUnix then "\\" else ""
exec "fsc" (sprintf "%s/%s.fsx -r:FSharp.Compiler.Interactive.Settings.dll --nocopyfsharpcore" testAppName testAppName) "."
// Check the processing of the scripts to HTML and LaTeX works
exec "packages/FAKE/tools/FAKE.exe" "build.fsx html" testAppName
exec "packages/FAKE/tools/FAKE.exe" "build.fsx latex" testAppName
(* Manual steps without building nupkg
.\build BuildDotnetTemplates
dotnet new -i bin/journal.*.nupkg
rmdir /s /q testapp2
dotnet new fslab-journal -n testapp2 -lang F#
dotnet restore testapp2/testapp2.fsproj -s bin/
dotnet restore testapp2/testapp2.fsproj -s bin/
msbuild testapp2/testapp2.fsproj
fsc testapp2\journal.fsx -r:FSharp.Compiler.Interactive.Settings.dll
fsi -r:FSharp.Compiler.Interactive.Settings.dll testapp2/Tutorial.fsx
fsi -r:FSharp.Compiler.Interactive.Settings.dll --use:testapp2/Tutorial.fsx
*)
)
Target "Publish" DoNothing
Target "All" DoNothing
//"Clean"
// ==> "TestInDirectoryBuildOfTemplates"
// ==> "BuildNuGets"
"Clean"
==> "BuildProjects"
==> "UpdateFsLabScript"
==> "UpdateNuSpec"
==> "BuildNuGets"
==> "All"
"Clean"
==> "UpdateFsLabScript"
==> "BuildNuGets"
==> "UpdateAndCheckTemplates"
==> "PlaceTempFiles"
"PlaceTempFiles"
==> "BuildZipTemplates"
==> "All"
"PlaceTempFiles"
==> "UpdateVSIXManifest"
==> "BuildVsTemplates"
==> "All"
"PlaceTempFiles"
==> "BuildZipTemplates"
==> "All"
"PlaceTempFiles"
==> "BuildDotnetTemplates"
==> "TestDotnetTemplatesNuGet"
==> "All"
RunTargetOrDefault "All"