forked from fslaborg/RProvider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.fsx
326 lines (267 loc) · 11 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
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------
#if FAKE
#r "paket:
nuget FAKE.Core.Target
nuget FAKE.Core.ReleaseNotes
nuget FAKE.DotNet.Cli
nuget FAKE.DotNet.Fsi
nuget FAKE.DotNet.AssemblyInfoFile
nuget FAKE.Tools.Git
nuget FAKE.DotNet.Testing.XUnit2"
#load "./.fake/build.fsx/intellisense.fsx"
#else
#r "nuget: FAKE.Core.Target"
#r "nuget: FAKE.Core.ReleaseNotes"
#r "nuget: FAKE.DotNet.Cli"
#r "nuget: FAKE.DotNet.Fsi"
#r "nuget: FAKE.DotNet.AssemblyInfoFile"
#r "nuget: FAKE.Tools.Git"
#r "nuget: FAKE.DotNet.Testing.XUnit2"
let execContext =
Fake.Core.Context.FakeExecutionContext.Create false "build.fsx" []
Fake.Core.Context.setExecutionContext (Fake.Core.Context.RuntimeContext.Fake execContext)
#endif
open Fake.Core
open Fake.Core.TargetOperators
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing.Operators
open Fake.DotNet
// --------------------------------------------------------------------------------------
// Information about the project to be used at NuGet and in AssemblyInfo files
// --------------------------------------------------------------------------------------
let projectName = "RProvider"
let projectSummary =
"An F# Type Provider providing strongly typed access to the R statistical package."
let projectDescription =
"""
An F# Type Provider providing strongly typed access to the R statistical package.
The type provider automatically discovers available R packages and makes them
easily accessible from F#, so you can easily call powerful packages and
visualization libraries from code running on the .NET platform."""
let authors = "BlueMountain Capital;FsLab"
let companyName = "BlueMountain Capital, FsLab"
let tags =
"F# fsharp R TypeProvider visualization statistics"
let license = "BSD-2-Clause"
let iconUrl =
"https://raw.githubusercontent.com/fslaborg/RProvider/master/docs/files/misc/logo.png"
let copyright = "(C) 2014 BlueMountain Capital"
let packageProjectUrl = "https://fslab.org/RProvider/"
let repositoryType = "git"
let repositoryUrl = "https://github.com/fslaborg/RProvider"
let repositoryContentUrl =
"https://raw.githubusercontent.com/fslaborg/RProvider"
let serverRuntimes =
[ "win-x64"
"osx-x64"
"osx-arm64"
"linux-x64" ]
// --------------------------------------------------------------------------------------
// The rest of the code is standard F# build script
// --------------------------------------------------------------------------------------
// Read release notes & version info from RELEASE_NOTES.md
System.Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let binDir = __SOURCE_DIRECTORY__ @@ "bin"
let release =
System.IO.File.ReadLines "RELEASE_NOTES.md"
|> Fake.Core.ReleaseNotes.parse
// Generate assembly info files with the right version & up-to-date information
Target.create
"AssemblyInfo"
(fun _ ->
let fileName = "src/Common/AssemblyInfo.fs"
AssemblyInfoFile.createFSharpWithConfig
fileName
[ Fake.DotNet.AssemblyInfo.Title projectName
Fake.DotNet.AssemblyInfo.Company companyName
Fake.DotNet.AssemblyInfo.Product projectName
Fake.DotNet.AssemblyInfo.Description projectSummary
Fake.DotNet.AssemblyInfo.Version release.AssemblyVersion
Fake.DotNet.AssemblyInfo.FileVersion release.AssemblyVersion ]
(AssemblyInfoFileConfig(false)))
// --------------------------------------------------------------------------------------
// Check code formatting
let sourceFiles = !! "*.fs"
Target.create
"CheckFormat"
(fun _ ->
let result =
sourceFiles
|> Seq.map (sprintf "\"%s\"")
|> String.concat " "
|> sprintf "%s --check"
|> DotNet.exec id "fantomas"
if result.ExitCode = 0 then
Trace.log "No files need formatting"
elif result.ExitCode = 99 then
failwith "Some files need formatting, check output for more info"
else
Trace.logf "Errors while formatting: %A" result.Errors)
Target.create
"Format"
(fun _ ->
let result =
sourceFiles
|> Seq.map (sprintf "\"%s\"")
|> String.concat " "
|> DotNet.exec id "fantomas"
if not result.OK then
printfn "Errors while formatting all files: %A" result.Messages)
// --------------------------------------------------------------------------------------
// Clean build results & restore NuGet packages
Target.create
"Clean"
(fun _ ->
Fake.IO.Shell.cleanDirs [ "bin"
"temp" ]
Fake.IO.Shell.cleanDirs [ "tests/Test.RProvider/bin"
"tests/Test.RProvider/obj" ])
Target.create "CleanDocs" (fun _ -> Fake.IO.Shell.cleanDirs [ ".fsdocs" ])
// --------------------------------------------------------------------------------------
// Build library & test project
Target.create
"Build"
(fun _ ->
Trace.log " --- Building the app --- "
Fake.DotNet.DotNet.build
(fun args ->
{ args with
Configuration = DotNet.BuildConfiguration.Release })
(projectName + ".sln"))
Target.create
"MakeServerExes"
(fun _ ->
Trace.log " --- Publishing the RProvider.Server executables --- "
serverRuntimes
|> List.iter
(fun runtime ->
Trace.logf " --- Publishing RProvider.Server for %s --- " runtime
DotNet.publish
(fun args ->
{ args with
Runtime = Some runtime
SelfContained = Some false
Configuration = DotNet.BuildConfiguration.Release
OutputPath = Some(sprintf "src/RProvider/bin/Release/net5.0/server/%s/" runtime) })
"src/RProvider.Server"))
Target.create
"BuildTests"
(fun _ ->
Trace.log " --- Building tests --- "
DotNet.build
(fun args ->
{ args with
Configuration = DotNet.BuildConfiguration.Release })
"tests/Test.RProvider/Test.RProvider.fsproj")
// --------------------------------------------------------------------------------------
// Run the unit tests using test runner & kill test runner when complete
Target.create
"RunTests"
(fun _ ->
let rHome = Environment.environVarOrFail "R_HOME"
Trace.logf "R_HOME is set as %s" rHome
let result =
DotNet.exec
(fun args ->
{ args with
Verbosity = Some Fake.DotNet.DotNet.Verbosity.Normal
CustomParams = Some "-c Release" })
"test"
"tests/Test.RProvider/Test.RProvider.fsproj"
if result.ExitCode <> 0 then
failwith "Tests failed")
// --------------------------------------------------------------------------------------
// Build a NuGet package
Target.create
"NuGet"
(fun _ ->
// Format the description to fit on a single line (remove \r\n and double-spaces)
let projectDescription =
projectDescription
.Replace("\r", "")
.Replace("\n", "")
.Replace(" ", " ")
// Format the release notes
let releaseNotes = release.Notes |> String.concat "\n"
let properties =
[ ("Version", release.NugetVersion)
("Authors", authors)
("PackageProjectUrl", packageProjectUrl)
("PackageTags", tags)
("RepositoryType", repositoryType)
("RepositoryUrl", repositoryUrl)
("PackageLicenseExpression", license)
("PackageRequireLicenseAcceptance", "false")
("PackageReleaseNotes", releaseNotes)
("Summary", projectSummary)
("PackageDescription", projectDescription)
("PackageIcon", "logo.png")
("PackageIconUrl", iconUrl)
("EnableSourceLink", "true")
("PublishRepositoryUrl", "true")
("EmbedUntrackedSources", "true")
("IncludeSymbols", "true")
("IncludeSymbols", "false")
("SymbolPackageFormat", "snupkg")
("Copyright", copyright) ]
DotNet.pack
(fun p ->
{ p with
Configuration = DotNet.BuildConfiguration.Release
OutputPath = Some "bin"
MSBuildParams =
{ p.MSBuildParams with
Properties = properties } })
"src/RProvider/RProvider.fsproj")
//--------------------------------------------------------------------------------------
//Generate the documentation
Target.create
"DocsMeta"
(fun _ ->
[ "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"
"<PropertyGroup>"
sprintf "<Copyright>%s</Copyright>" copyright
sprintf "<Authors>%s</Authors>" authors
sprintf "<PackageProjectUrl>%s</PackageProjectUrl>" packageProjectUrl
sprintf "<RepositoryUrl>%s</RepositoryUrl>" repositoryUrl
sprintf "<PackageLicense>%s</PackageLicense>" license
sprintf "<PackageReleaseNotes>%s</PackageReleaseNotes>" (List.head release.Notes)
sprintf "<PackageIconUrl>%s/master/docs/content/logo.png</PackageIconUrl>" repositoryContentUrl
sprintf "<PackageTags>%s</PackageTags>" tags
sprintf "<Version>%s</Version>" release.NugetVersion
sprintf "<FsDocsLogoSource>%s/master/docs/img/logo.png</FsDocsLogoSource>" repositoryContentUrl
sprintf "<FsDocsLicenseLink>%s/blob/master/LICENSE.md</FsDocsLicenseLink>" repositoryUrl
sprintf "<FsDocsReleaseNotesLink>%s/blob/master/RELEASE_NOTES.md</FsDocsReleaseNotesLink>" repositoryUrl
"<FsDocsWarnOnMissingDocs>true</FsDocsWarnOnMissingDocs>"
"<FsDocsTheme>default</FsDocsTheme>"
"</PropertyGroup>"
"</Project>" ]
|> Fake.IO.File.write false "Directory.Build.props")
Target.create
"GenerateDocs"
(fun _ ->
Fake.IO.Shell.cleanDir ".fsdocs"
DotNet.exec
id
"fsdocs"
("build --clean --properties Configuration=Release --parameters fsdocs-package-version "
+ release.NugetVersion)
|> ignore)
// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override
Target.create "All" ignore
"Clean"
==> "AssemblyInfo"
==> "MakeServerExes"
==> "Build"
"Build"
==> "CleanDocs"
==> "DocsMeta"
==> "GenerateDocs"
==> "All"
"Build" ==> "NuGet" ==> "All"
"Build" ==> "All"
"Build" ==> "BuildTests" ==> "RunTests" ==> "All"
Target.runOrDefault "All"