-
Notifications
You must be signed in to change notification settings - Fork 18
/
targets.fsx
7250 lines (5924 loc) · 261 KB
/
targets.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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Downloads/docker-machine-Windows-x86_64 create --driver virtualbox <name>
open System
open System.Diagnostics.Tracing
open System.IO
open System.Reflection
open System.Text
open System.Xml
open System.Xml.Linq
open Actions
open AltCode.Fake.DotNet
open AltCoverFake.DotNet.DotNet
open AltCoverFake.DotNet.Testing
open Fake.Core
open Fake.Core.TargetOperators
open Fake.DotNet
open Fake.DotNet.NuGet.NuGet
open Fake.DotNet.Testing.NUnit3
open Fake.Testing
open Fake.DotNet.Testing
open Fake.IO
open Fake.IO.FileSystemOperators
open Fake.IO.Globbing
open Fake.IO.Globbing.Operators
open Fake.Tools.Git
//open FSharpLint.Application
//open FSharpLint.Framework
open NUnit.Framework
open Swensen.Unquote
let Copyright = ref String.Empty
let Version = ref String.Empty
let consoleBefore =
(Console.ForegroundColor, Console.BackgroundColor)
let AltCoverFilter (p: Primitive.PrepareOptions) =
{ p with
MethodFilter =
"WaitForExitCustom"
:: (p.MethodFilter |> Seq.toList)
AssemblyFilter =
[ @"\.DataCollector"; "Sample" ]
@ (p.AssemblyFilter |> Seq.toList)
AttributeFilter =
"TestSDKAutoGeneratedCode"
:: (p.AttributeFilter |> Seq.toList)
LocalSource = true
TypeFilter =
[ @"System\."
@"Sample3\.Class2"
"Microsoft"
"ICSharpCode"
"UnitTestStub" ]
@ (p.TypeFilter |> Seq.toList) }
let AltCoverFilterTypeSafe (p: TypeSafe.PrepareOptions) =
{ p with
MethodFilter =
[ TypeSafe.Raw "WaitForExitCustom" ]
|> p.MethodFilter.Join
AssemblyFilter =
[ @"\.DataCollector"; "Sample" ]
|> Seq.map TypeSafe.Raw
|> p.AssemblyFilter.Join
LocalSource = TypeSafe.Set
TypeFilter =
[ @"System\."
@"Sample3\.Class2"
"Microsoft"
"ICSharpCode"
"UnitTestStub"
"SolutionRoot" ]
|> Seq.map TypeSafe.Raw
|> p.TypeFilter.Join }
let AltCoverApiFilter (p: Primitive.PrepareOptions) =
{ p with
AssemblyExcludeFilter = "Tests" :: (p.AssemblyExcludeFilter |> Seq.toList)
AssemblyFilter =
[ "?^AltCover\." ]
@ (p.AssemblyFilter |> Seq.toList)
LocalSource = true
TypeFilter =
[ @"System\."
@"Sample3\.Class2"
"Microsoft"
"ICSharpCode"
"<Start"
"UnitTestStub" ]
@ (p.TypeFilter |> Seq.toList) }
let AltCoverFilterX (p: Primitive.PrepareOptions) =
{ p with
MethodFilter =
"WaitForExitCustom"
:: (p.MethodFilter |> Seq.toList)
AssemblyFilter =
[ @"\.DataCollector"; "Sample" ]
@ (p.AssemblyFilter |> Seq.toList)
LocalSource = true
TypeFilter =
[ @"System\."
@"Sample3\.Class2"
"Microsoft"
"ICSharpCode"
"<Start"
"UnitTestStub" ]
@ (p.TypeFilter |> Seq.toList) }
let AltCoverFilterXTypeSafe (p: TypeSafe.PrepareOptions) =
{ p with
MethodFilter =
[ TypeSafe.Raw "WaitForExitCustom" ]
|> p.MethodFilter.Join
AssemblyFilter =
[ @"\.DataCollector"; "Sample" ]
|> Seq.map TypeSafe.Raw
|> p.AssemblyFilter.Join
LocalSource = TypeSafe.Set
TypeFilter =
[ @"System\."
@"Sample3\.Class2"
"Microsoft"
"ICSharpCode"
"UnitTestStub"
"SolutionRoot" ]
|> Seq.map TypeSafe.Raw
|> p.TypeFilter.Join }
let AltCoverFilterG (p: Primitive.PrepareOptions) =
{ p with
MethodFilter =
"WaitForExitCustom"
:: (p.MethodFilter |> Seq.toList)
AssemblyExcludeFilter = "Tests" :: (p.AssemblyExcludeFilter |> Seq.toList)
AssemblyFilter =
[ @"\.Recorder\.g"; "Sample" ]
@ (p.AssemblyFilter |> Seq.toList)
LocalSource = true
TypeFilter =
[ @"System\."
@"Sample3\.Class2"
"Microsoft" ]
@ (p.TypeFilter |> Seq.toList) }
let programFiles = Environment.environVar "ProgramFiles"
let programFiles86 =
Environment.environVar "ProgramFiles(x86)"
let dotnetPath =
"dotnet"
|> Fake.Core.ProcessUtils.tryFindFileOnPath
let dotnetOptions (o: DotNet.Options) =
match dotnetPath with
| Some f -> { o with DotNetCliPath = f }
| None -> o
let dotnetVersion =
DotNet.getVersion (fun o -> o.WithCommon dotnetOptions)
printfn "Using dotnet version %s" dotnetVersion
let dotnetInfo =
DotNet.exec (fun o -> dotnetOptions (o.WithRedirectOutput true)) "" "--info"
let MSBuildPath =
dotnetInfo.Results
|> Seq.filter (fun x -> x.IsError |> not)
|> Seq.map (fun x -> x.Message)
|> Seq.tryFind (fun x -> x.Contains "Base Path:")
|> Option.map (fun x -> Path.Combine(x.Replace("Base Path:", "").TrimStart(), "MSBuild.dll"))
printfn "MSBuildPath = %A" MSBuildPath
let dotnetOptionsWithRollForwards (o: DotNet.Options) =
let env =
o.Environment.Add("DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX", "2")
o.WithEnvironment env
let fxcop =
if Environment.isWindows then
let expect =
"./packages/fxcop/FxCopCmd.exe"
|> Path.getFullName
if File.Exists expect then
Some expect
else
None
else
None
let monoOnWindows =
if Environment.isWindows then
[ programFiles; programFiles86 ]
|> List.filter (String.IsNullOrWhiteSpace >> not)
|> List.map (fun s -> s @@ "Mono/bin/mono.exe")
|> List.tryFind File.Exists
else
None
let dotnetPath86 =
if Environment.isWindows then
let perhaps =
[ programFiles86 ]
|> List.filter (String.IsNullOrWhiteSpace >> not)
|> List.map (fun s -> s @@ "dotnet\dotnet.EXE")
|> List.tryFind File.Exists
match perhaps with
| Some path ->
try // detect if we have the SDK
DotNet.info
(fun opt ->
{ opt with
Common =
{ dotnetOptions opt.Common with
DotNetCliPath = path } })
|> ignore
perhaps
with _ -> None
| _ -> None
else
None
let dotnetOptions86 (o: DotNet.Options) =
match dotnetPath86 with
| Some f -> { o with DotNetCliPath = f }
| None -> o
let nugetCache =
Path.Combine(Environment.GetFolderPath Environment.SpecialFolder.UserProfile, ".nuget/packages")
let pwsh =
match "pwsh" |> Fake.Core.ProcessUtils.tryFindFileOnPath with
| Some path -> path
| _ -> "pwsh"
let toolPackages =
let xml =
"./Build/NuGet.csproj"
|> Path.getFullName
|> XDocument.Load
xml.Descendants(XName.Get("PackageReference"))
|> Seq.map (fun x -> (x.Attribute(XName.Get("Include")).Value, x.Attribute(XName.Get("version")).Value))
|> Map.ofSeq
let packageVersion (p: string) =
p.ToLowerInvariant() + "/" + (toolPackages.Item p)
// MCS packages.config
let openCoverConsole =
("./packages/"
+ (packageVersion "OpenCover")
+ "/tools/OpenCover.Console.exe")
|> Path.getFullName
let nunitConsole =
("./packages/"
+ (packageVersion "NUnit.ConsoleRunner")
+ "/tools/nunit3-console.exe")
|> Path.getFullName
let xmldoc2cmdletdoc =
("./packages/"
+ (packageVersion "XmlDoc2CmdletDoc")
+ "/tools/netcoreapp2.1/XmlDoc2CmdletDoc.dll")
|> Path.getFullName
let coverletcollector =
("./packages/"
+ (packageVersion "coverlet.collector")
+ "/build/netstandard1.0/coverlet.collector.dll")
|> Path.getFullName
let cliArguments =
{ MSBuild.CliArguments.Create() with
ConsoleLogParameters = []
DistributedLoggers = None
Properties = [ ("CheckEolTargetFramework", "false") ]
DisableInternalBinLog = true }
let withWorkingDirectoryVM dir o =
{ dotnetOptions o with
WorkingDirectory = Path.getFullName dir
Verbosity = Some DotNet.Verbosity.Minimal }
let withWorkingDirectoryVN dir o =
{ dotnetOptions o with
WorkingDirectory = Path.getFullName dir
Verbosity = Some DotNet.Verbosity.Normal }
let withWorkingDirectoryOnly dir o =
{ dotnetOptions o with
WorkingDirectory = Path.getFullName dir }
let testWithCLIArguments (o: Fake.DotNet.DotNet.TestOptions) = { o with MSBuildParams = cliArguments }
let buildWithCLIArguments (o: Fake.DotNet.DotNet.BuildOptions) = { o with MSBuildParams = cliArguments }
let NuGetAltCover =
toolPackages
|> Seq.filter (fun kv -> kv.Key = "altcover")
|> Seq.map
(fun _ ->
("./packages/"
+ (packageVersion "altcover")
+ "/tools/net472/AltCover.exe")
|> Path.getFullName)
|> Seq.filter File.Exists
|> Seq.tryHead
let ForceTrueOnly = DotNet.CLIOptions.Force true
let FailTrue = DotNet.CLIOptions.Fail true
let GreenSummary = DotNet.CLIOptions.Summary "Green"
let ForceTrue =
DotNet.CLIOptions.Many [ ForceTrueOnly
GreenSummary ]
let ForceTrueFast =
DotNet.CLIOptions.Many [ FailTrue
ForceTrueOnly
GreenSummary ]
let dotnetAltcover =
Fake.DotNet.ToolType.CreateFrameworkDependentDeployment dotnetOptions
let dotnetAltcover86 =
Fake.DotNet.ToolType.CreateFrameworkDependentDeployment dotnetOptions86
let frameworkAltcover =
Fake.DotNet.ToolType.CreateFullFramework()
let defaultTestOptions fwk common (o: DotNet.TestOptions) =
{ o.WithCommon(
(fun o2 ->
{ o2 with
Verbosity = Some DotNet.Verbosity.Normal })
>> common
) with
NoBuild = true
Framework = fwk // Some "net5.0"
Configuration = DotNet.BuildConfiguration.Debug }
let defaultDotNetTestCommandLine fwk project =
AltCoverCommand.buildDotNetTestCommandLine (defaultTestOptions fwk dotnetOptions) project
let defaultDotNetTestCommandLine86 fwk project =
AltCoverCommand.buildDotNetTestCommandLine (defaultTestOptions fwk dotnetOptions86) project
let coverletOptions (o: DotNet.Options) =
{ dotnetOptions o with
CustomParams = Some "--collect:\"XPlat Code Coverage\"" }
let coverletTestOptions (o: DotNet.TestOptions) =
{ o.WithCommon dotnetOptions with
Configuration = DotNet.BuildConfiguration.Debug
NoBuild = true
Framework = Some "net5.0"
Settings = Some "./_Generated/coverletArgs.runsettings"
Collect = Some "XPlat Code Coverage" }
|> testWithCLIArguments
let coverletTestOptionsSample (o: DotNet.TestOptions) =
{ coverletTestOptions o with
Settings = Some "./Build/coverletArgs.sample.runsettings"
Collect = Some "XPlat Code Coverage" }
let misses = ref 0
let uncovered (path: string) =
misses := 0
!!path
|> Seq.collect
(fun f ->
let xml = XDocument.Load f
xml.Descendants(XName.Get("Uncoveredlines"))
|> Seq.filter
(fun x ->
match String.IsNullOrWhiteSpace x.Value with
| false -> true
| _ ->
sprintf "No coverage from '%s'" f
|> Trace.traceImportant
misses := 1 + misses.Value
false)
|> Seq.map
(fun e ->
let coverage = e.Value
match Int32.TryParse coverage with
| (false, _) ->
printfn "%A" xml
Assert.Fail(
"Could not parse uncovered line value '"
+ coverage
+ "'"
)
(0, f)
| (_, numeric) ->
printfn "%s : %A" (f |> Path.GetDirectoryName |> Path.GetFileName) numeric
// if numeric > 0 then
// printfn "%A" xml
(numeric, f)))
|> Seq.toList
let coverageSummary _ =
let numbers = uncovered "_Reports/_Unit*/Summary.xml"
if numbers
|> List.tryFind
(fun (n, f) ->
if (f |> Path.GetDirectoryName |> Path.GetFileName) = "_UnitTestWithCoverlet" then
n > 0 && n < 100 // don't expect to get that high
// w/o flakeout or other ones failing too
else
n > 0)
|> Option.isSome
|| misses.Value > 0 then
Assert.Fail("Coverage is too low")
let msbuildCommon (p: MSBuildParams) =
{ p with
Verbosity = Some MSBuildVerbosity.Normal
ConsoleLogParameters = []
DistributedLoggers = None
DisableInternalBinLog = true
Properties =
[ "CheckEolTargetFramework", "false"
"DebugSymbols", "True" ] }
let withDebug (p: MSBuildParams) =
{ p with
Properties = ("Configuration", "Debug") :: p.Properties }
let withRelease (p: MSBuildParams) =
{ p with
Properties = ("Configuration", "Release") :: p.Properties }
let splitCommandLine line =
line
|> if Environment.isWindows then
BlackFox.CommandLine.MsvcrCommandLine.parse
else
BlackFox.CommandLine.MonoUnixCommandLine.parse
|> Seq.toList
let doMSBuild config overrider proj =
let f = msbuildCommon >> config
match overrider with
| None -> MSBuild.build f proj
| Some dll ->
let (_, args) = MSBuild.buildArgs f
let arglist = (splitCommandLine args) @ [ proj ]
CreateProcess.fromRawCommand dll arglist
|> DotNet.prefixProcess dotnetOptions [ dll ]
|> Proc.run
|> fun p -> Assert.That(p.ExitCode, Is.EqualTo 0)
let msbuildRelease = doMSBuild withRelease
let msbuildDebug = doMSBuild withDebug
let dotnetBuildRelease proj =
DotNet.build
(fun p ->
{ p.WithCommon dotnetOptions with
Configuration = DotNet.BuildConfiguration.Release }
|> buildWithCLIArguments)
(Path.GetFullPath proj)
let dotnetBuildDebug proj =
DotNet.build
(fun p ->
{ p.WithCommon dotnetOptions with
Configuration = DotNet.BuildConfiguration.Debug }
|> buildWithCLIArguments)
(Path.GetFullPath proj)
// Information.getCurrentHash()
let commitHash = Information.getCurrentSHA1 (".")
let infoV = Information.showName "." commitHash
printfn "Build at %A" infoV
// let hash = System.Security.Cryptography.SHA256.Create()
// let formatSecret (s : string) =
// if s |> isNull
// then "(null)"
// else if String.IsNullOrEmpty s
// then "(empty)"
// else if String.IsNullOrWhiteSpace s
// then "(whitespace)"
// else s
// |> System.Text.Encoding.UTF8.GetBytes
// |> hash.ComputeHash
// |> Convert.ToBase64String
//----------------------------------------------------------------
let _Target s f =
Target.description s
Target.create s f
let s2 = "Replay" + s
Target.description s2
Target.create s2 f
// Preparation
_Target "RebuildPaketLock" ignore
_Target "Preparation" ignore
_Target
"PreClean"
(fun _ ->
// dir -Recurse *ssemblyAttributes.cs | % { del -Force $_.FullName }
!! "**/*ssemblyAttributes.cs"
|> Seq.map Path.GetFullPath
|> Seq.toList
|> List.iter File.delete)
_Target
"Clean"
(fun _ ->
printfn "Cleaning the build and deploy folders"
Actions.Clean())
_Target
"SetVersion"
(fun _ ->
// patch gendarme
let configjson =
File.ReadAllText("./.config/dotnet-tools.json")
let json = Manatee.Json.JsonValue.Parse configjson
let gendarmeVersion =
json.Object.["tools"].Object.["altcode.gendarme-tool"]
.Object.["version"]
.String
let project1 = XDocument.Load("./Build/NuGet.csproj")
let pr =
project1.Descendants(XName.Get "PackageReference")
|> Seq.find (fun pr -> pr.Attribute(XName.Get "Include").Value = "altcode.gendarme")
pr.Attribute(XName.Get "version").Value <- gendarmeVersion
project1.Save("./Build/NuGet.csproj")
let project2 =
XDocument.Load("./AltCover.ValidateGendarmeEmulation/AltCover.ValidateGendarmeEmulation.fsproj")
let gv =
project2.Descendants(XName.Get "GendarmeVersion")
|> Seq.head
gv.Value <- gendarmeVersion
project2.Save("./AltCover.ValidateGendarmeEmulation/AltCover.ValidateGendarmeEmulation.fsproj")
// patch coveralls.io for github actions
let coverallsdll =
("./packages/"
+ (packageVersion "coveralls.io")
+ "/tools/Coveralls.dll")
|> Path.getFullName
Shell.copyFile coverallsdll "./ThirdParty/Coveralls.dll"
let coverallspdb =
("./packages/"
+ (packageVersion "coveralls.io")
+ "/tools/Coveralls.pdb")
|> Path.getFullName
Shell.copyFile coverallspdb "./ThirdParty/Coveralls.pdb"
let appveyor =
Environment.environVar "APPVEYOR_BUILD_VERSION"
let github =
Environment.environVar "GITHUB_RUN_NUMBER"
let version = Actions.GetVersionFromYaml()
let ci =
if String.IsNullOrWhiteSpace appveyor then
if String.IsNullOrWhiteSpace github then
String.Empty
else
version.Replace("{build}", github + "-github")
else
appveyor
let (v, majmin, y) = Actions.LocalVersion ci version
Version := v
let copy =
sprintf "© 2010-%d by Steve Gilham <[email protected]>" y
Copyright := "Copyright " + copy
Directory.ensure "./_Generated"
Shell.copyFile "./AltCover.Engine/Abstract.fsi" "./AltCover.Engine/Abstract.fs"
Actions.InternalsVisibleTo(Version.Value)
[ "./_Generated/AssemblyVersion.fs"
"./_Generated/AssemblyVersion.cs" ]
|> List.iter
(fun f ->
let from =
("./Build" @@ (Path.GetFileName f)) + ".txt"
let text = File.ReadAllText from
let newtext =
String.Format(
text,
majmin,
Version.Value.Split([| '-' |]).[0],
commitHash,
Information.getBranchName ("."),
y
)
File.WriteAllText(f, newtext))
//let v' = Version.Value
//let assemblyAttributes =
// [ AssemblyInfo.Product "AltCover"
// AssemblyInfo.Version(majmin + ".0.0")
// AssemblyInfo.FileVersion v'
// AssemblyInfo.Company "Steve Gilham"
// AssemblyInfo.Trademark ""
// AssemblyInfo.InformationalVersion(infoV)
// AssemblyInfo.Copyright copy
// // Not available in net20 for recorder
// // .fs would need post-processing
// AssemblyInfo.Metadata("RepositoryUrl", "https://github.com/SteveGilham/altcover")
// AssemblyInfo.Metadata("CommitHash", commitHash)
// AssemblyInfo.Metadata("Branch", Information.getBranchName("."))
// ]
//assemblyAttributes
//|> List.map (fun a -> a.GetType().FullName)
//|> List.iter (printfn "%A")
//[ "./_Generated/AssemblyVersion.fs"; "./_Generated/AssemblyVersion.cs" ]
//|> List.iter (fun file ->
// AssemblyInfoFile.create file assemblyAttributes (Some AssemblyInfoFileConfig.Default))
//printfn "%A" AssemblyInfoFileConfig.Default
//let lite = AssemblyInfoFileConfig(false)
//[ "./_Generated/AssemblyVersionLite.fs"; "./_Generated/AssemblyVersionLite.cs" ]
//|> List.iter (fun file ->
// AssemblyInfoFile.create file assemblyAttributes (Some lite))
let hack =
"""namespace AltCover
module SolutionRoot =
let location = """
+ "\"\"\""
+ (Path.getFullName ".")
+ "\"\"\""
let path = "_Generated/SolutionRoot.fs"
// Update the file only if it would change
let old =
if File.Exists(path) then
File.ReadAllText(path)
else
String.Empty
if not (old.Equals(hack)) then
File.WriteAllText(path, hack)
[ "./AltCover.Recorder/AltCover.Recorder.fsproj" // net20 resgen ?? https://docs.microsoft.com/en-us/visualstudio/msbuild/generateresource-task?view=vs-2019
"./AltCover.Recorder.Tests/AltCover.Recorder.Tests.fsproj"
"./AltCover.Recorder2.Tests/AltCover.Recorder2.Tests.fsproj" ]
|> Seq.iter
(fun f ->
let dir = Path.GetDirectoryName f
let proj = Path.GetFileName f
DotNet.restore
(fun o ->
let tmp = o.WithCommon(withWorkingDirectoryVM dir)
let mparams =
{ tmp.MSBuildParams with
Properties =
("CheckEolTargetFramework", "false")
:: tmp.MSBuildParams.Properties }
{ tmp with MSBuildParams = mparams })
proj)
do
let xml =
XDocument.Load("./AltCover.Recorder/Strings.resx")
use resw =
new System.Resources.ResourceWriter("./AltCover.Recorder/Strings.resources")
xml.Descendants(XName.Get "data")
|> Seq.iter
(fun d ->
let key = d.Attribute(XName.Get "name").Value
let value =
d.Descendants(XName.Get "value") |> Seq.head
resw.AddResource(key, value.Value))
resw.Close()
let text =
File.ReadAllText "./Build/coverletArgs.runsettings"
let name =
System.Reflection.AssemblyName.GetAssemblyName coverletcollector
let newtext =
String.Format(text, name.Version, name.FullName, coverletcollector)
File.WriteAllText("./_Generated/coverletArgs.runsettings", newtext))
// Basic compilation
_Target "Compilation" ignore
_Target
"BuildRelease"
(fun _ ->
try
[ "./AltCover.sln"
"./AltCover.Visualizer.sln"
"MCS.sln" ]
|> Seq.iter dotnetBuildRelease
// document cmdlets ahead of packaging
let packages =
let xml =
"./AltCover.PowerShell/AltCover.PowerShell.fsproj"
|> Path.getFullName
|> XDocument.Load
xml.Descendants(XName.Get("PackageReference"))
|> Seq.map
(fun x ->
let incl = x.Attribute(XName.Get("Include"))
let update = x.Attribute(XName.Get("Update"))
let version = x.Attribute(XName.Get("Version")).Value
if incl |> isNull then
(update.Value, version)
else
(incl.Value, version))
|> Map.ofSeq
let packageVersionPart (p: string) =
nugetCache
+ "/"
+ p.ToLowerInvariant()
+ "/"
+ (packages.Item p)
+ "/lib/netstandard2.0/"
Shell.copyFile
("./_Binaries/AltCover.PowerShell/Release+AnyCPU/netstandard2.0/FSharp.Core.dll")
((packageVersionPart "FSharp.Core")
+ "FSharp.Core.dll")
Shell.copyFile
("./_Binaries/AltCover.PowerShell/Release+AnyCPU/netstandard2.0/System.Management.Automation.dll")
((packageVersionPart "PowerShellStandard.Library")
+ "System.Management.Automation.dll")
let cmdlets =
"./_Binaries/AltCover.PowerShell/Release+AnyCPU/netstandard2.0/AltCover.PowerShell.dll"
|> Path.getFullName
if Environment.isWindows then // the Jolt comment reader library is sadly windows/fullframework bound
Actions.RunDotnet
dotnetOptions
""
("--roll-forward Major "
+ xmldoc2cmdletdoc
+ " -strict "
+ cmdlets)
"documenting cmdlets"
with x ->
printfn "%A" x
reraise ())
_Target
"BuildDebug"
(fun _ ->
Directory.ensure "./_SourceLink"
Shell.copyFile "./_SourceLink/Class2.cs" "./Samples/Sample14/Sample14/Class2.txt"
(if Environment.isWindows then
let temp = Environment.environVar "TEMP"
Shell.copyFile (temp @@ "/Sample14.SourceLink.Class3.cs")
else
Directory.ensure "/tmp/.AltCover_SourceLink"
Shell.copyFile "/tmp/.AltCover_SourceLink/Sample14.SourceLink.Class3.cs")
"./Samples/Sample14/Sample14/Class3.txt"
[ "./AltCover.Recorder.sln" ]
|> Seq.iter (msbuildDebug MSBuildPath) // net20
[ "./AltCover.Recorder.sln" ]
|> Seq.iter (msbuildRelease MSBuildPath) // net20
[ "./AltCover.sln"
"./AltCover.Visualizer.sln"
"./Samples/Sample14/Sample14.sln"
"MCS.sln" ]
|> Seq.iter dotnetBuildDebug
Shell.copy "./_SourceLink" (!! "./Samples/Sample14/Sample14/bin/Debug/netcoreapp2.1/*"))
_Target
"BuildMonoSamples"
(fun _ ->
[ "./Samples/Sample8/Sample8.csproj" ]
|> Seq.iter dotnetBuildDebug // build to embed on non-Windows
let mcs = "_Binaries/MCS/Release+AnyCPU/net472/MCS.exe"
[ ("./_Mono/Sample1",
[ "-debug"
"-out:./_Mono/Sample1/Sample1.exe"
"./Samples/Sample1/Program.cs" ])
("./_Mono/Sample3",
[ "-target:library"
"-debug"
"-out:./_Mono/Sample3/Sample3.dll"
"-lib:./packages/Mono.Cecil.0.11.1/lib/net40"
"-r:Mono.Cecil.dll"
"./Samples/Sample3/Class1.cs" ]) ]
|> Seq.iter
(fun (dir, cmd) ->
Directory.ensure dir
("Mono compilation of '"
+ String.Join(" ", cmd)
+ "' failed")
|> Actions.Run(mcs, ".", cmd))
Actions.FixMVId [ "./_Mono/Sample1/Sample1.exe"
"./_Mono/Sample3/Sample3.dll" ])
// Code Analysis
_Target "Analysis" ignore
_Target
"Lint"
(fun _ ->
let cfg = Path.getFullName "./fsharplint.json"
let doLint f =
CreateProcess.fromRawCommand "dotnet" ["fsharplint"; "lint"; "-l"; cfg ; f]
|> CreateProcess.ensureExitCodeWithMessage "Lint issues were found"
|> Proc.run
let doLintAsync f = async { return (doLint f).ExitCode }
let throttle x = Async.Parallel (x, System.Environment.ProcessorCount)
let demo = Path.getFullName "./Demo"
let regress = Path.getFullName "./RegressionTesting"
let sample = Path.getFullName "./Samples"
let failOnIssuesFound (issuesFound: bool) =
Assert.That(issuesFound, Is.False, "Lint issues were found")
[ !! "./**/*.fsproj"
|> Seq.sortBy (Path.GetFileName)
|> Seq.filter (fun f -> ((f.Contains demo) ||
(f.Contains regress) ||
(f.Contains sample)) |> not)
!! "./Build/*.fsx" |> Seq.map Path.GetFullPath ]
|> Seq.concat
|> Seq.map doLintAsync
|> throttle
|> Async.RunSynchronously
|> Seq.exists (fun x -> x <> 0)
|> failOnIssuesFound
)
//(fun _ ->
// let failOnIssuesFound (issuesFound: bool) =
// Assert.That(issuesFound, Is.False, "Lint issues were found")
// try
// let options =
// { Lint.OptionalLintParameters.Default with
// Configuration = FromFile(Path.getFullName "./fsharplint.json") }
// [ !! "**/*.fsproj"
// |> Seq.collect (fun n -> !!(Path.GetDirectoryName n @@ "*.fs"))
// |> Seq.distinct
// !! "./Build/*.fsx" |> Seq.map Path.GetFullPath ]
// |> Seq.concat
// |> Seq.collect
// (fun f ->
// match Lint.lintFile options f with
// | Lint.LintResult.Failure x -> failwithf "%A" x
// | Lint.LintResult.Success w ->
// w
// |> Seq.filter (fun x -> x.Details.SuggestedFix |> Option.isSome))
// |> Seq.fold
// (fun _ x ->
// printfn
// "Info: %A\r\n Range: %A\r\n Fix: %A\r\n===="
// x.Details.Message
// x.Details.Range
// x.Details.SuggestedFix
// true)
// false
// |> failOnIssuesFound
// with ex ->
// printfn "%A" ex
// reraise ())
_Target
"Gendarme"
(fun _ -> // Needs debug because release is compiled --standalone which contaminates everything
Directory.ensure "./_Reports"
[ ("./Build/common-rules.xml",
[ "_Binaries/AltCover.Engine/Debug+AnyCPU/netstandard2.0/AltCover.Engine.dll"
"_Binaries/AltCover/Debug+AnyCPU/netcoreapp2.0/AltCover.dll"
"_Binaries/AltCover.Recorder/Debug+AnyCPU/net20/AltCover.Recorder.dll"
"_Binaries/AltCover.PowerShell/Debug+AnyCPU/netstandard2.0/AltCover.PowerShell.dll"
"_Binaries/AltCover.Fake/Debug+AnyCPU/netstandard2.0/AltCover.Fake.dll"
"_Binaries/AltCover.DotNet/Debug+AnyCPU/netstandard2.0/AltCover.DotNet.dll"
"_Binaries/AltCover.Toolkit/Debug+AnyCPU/netstandard2.0/AltCover.Toolkit.dll"
"_Binaries/AltCover.UICommon/Debug+AnyCPU/netstandard2.0/AltCover.UICommon.dll"
"_Binaries/AltCover.Visualizer/Debug+AnyCPU/netcoreapp2.1/AltCover.Visualizer.dll" // GTK3 (obsolete)
"_Binaries/AltCover.Fake.DotNet.Testing.AltCover/Debug+AnyCPU/netstandard2.0/AltCover.Fake.DotNet.Testing.AltCover.dll" ])
("./Build/common-rules.xml",
[ "_Binaries/AltCover/Debug+AnyCPU/netcoreapp2.1/AltCover.dll" // global tool build
"_Binaries/AltCover.Visualizer/Debug+AnyCPU/net472/AltCover.Visualizer.exe" ])
("./Build/csharp-rules.xml",
[ "_Binaries/AltCover.DataCollector/Debug+AnyCPU/netstandard2.0/AltCover.DataCollector.dll"
"_Binaries/AltCover.Monitor/Debug+AnyCPU/net20/AltCover.Monitor.dll"
"_Binaries/AltCover.FontSupport/Debug+AnyCPU/netstandard2.0/AltCover.FontSupport.dll"
"_Binaries/AltCover.Cake/Debug+AnyCPU/netstandard2.0/AltCover.Cake.dll" ]) ]
|> Seq.iter
(fun (ruleset, files) ->
Gendarme.run
{ Gendarme.Params.Create() with
WorkingDirectory = "."
Severity = Gendarme.Severity.All
Confidence = Gendarme.Confidence.All
Configuration = ruleset
Console = true
Log = "./_Reports/gendarme.html"
LogKind = Gendarme.LogKind.Html
Targets = files
ToolType = ToolType.CreateLocalTool()
FailBuildOnDefect = true }))
_Target
"FxCop"
(fun _ ->
Directory.ensure "./_Reports"
let dumpSuppressions (report: String) =
let x = XDocument.Load report
let messages = x.Descendants(XName.Get "Message")
messages
|> Seq.iter
(fun m ->