11// --------------------------------------------------------------------------------------
22// FAKE build script
33// --------------------------------------------------------------------------------------
4+ #r " paket: groupref Main //"
5+ #load " ./.fake/build.fsx/intellisense.fsx"
46
5- #I " packages/FAKE/tools"
6- #r " packages/FAKE/tools/FakeLib.dll"
77open System
88open System.IO
9- open Fake
10- open Fake.AppVeyor
11- open Fake.ReleaseNotesHelper
12-
13- #if MONO
14- // prevent incorrect output encoding (e.g. https://github.com/fsharp/FAKE/issues/1196)
15- System.Console.OutputEncoding <- System.Text.Encoding.UTF8
16- CleanDir (__ SOURCE_ DIRECTORY__ + " /../artifacts/TestResults" )
17- File.WriteAllText(__ SOURCE_ DIRECTORY__ + " /../artifacts/TestResults/notestsyet.txt" , " No tests yet" )
18- let isMono = true
19- #else
20- let isMono = false
21- #endif
22-
23-
24- let dotnetExePath =
9+ open Fake.BuildServer
10+ open Fake.Core
11+ open Fake.DotNet
12+ open Fake.IO
13+
14+ BuildServer.install [ AppVeyor.Installer ]
15+ // --------------------------------------------------------------------------------------
16+ // Utilities
17+ // --------------------------------------------------------------------------------------
18+
19+ let withDotnetExe =
2520 // Build.cmd normally downloads a dotnet cli to: <repo-root>\artifacts\toolset\dotnet
2621 // check if there is one there to avoid downloading an additional one here
2722 let pathToCli = Path.Combine(__ SOURCE_ DIRECTORY__, @" ..\artifacts\toolset\dotnet\dotnet.exe" )
2823 if File.Exists( pathToCli) then
29- pathToCli
24+ ( fun opts -> { opts with DotNet.Options.DotNetCliPath = pathToCli })
3025 else
31- DotNetCli.InstallDotNetSDK " 3.0.100"
32-
33- let runDotnet workingDir args =
34- let result =
35- ExecProcess ( fun info ->
36- info.FileName <- dotnetExePath
37- info.WorkingDirectory <- workingDir
38- info.Arguments <- args) TimeSpan.MaxValue
39-
40- if result <> 0 then failwithf " dotnet %s failed" args
41-
42- let assertExitCodeZero x = if x = 0 then () else failwithf " Command failed with exit code %i " x
43-
44- let runCmdIn workDir ( exe : string ) = Printf.ksprintf ( fun ( args : string ) ->
45- #if MONO
46- let exe = exe.Replace( " \\ " , " /" )
47- let args = args.Replace( " \\ " , " /" )
48- printfn " [%s ] mono %s %s " workDir exe args
49- Shell.Exec( " mono" , sprintf " %s %s " exe args, workDir)
50- #else
51- printfn " [%s ] %s %s " workDir exe args
52- Shell.Exec( exe, args, workDir)
53- #endif
54- |> assertExitCodeZero
55- )
26+ DotNet.install ( fun cliOpts -> { cliOpts with Version = DotNet.CliVersion.GlobalJson })
27+
28+ let runDotnet workingDir command args =
29+ let result = DotNet.exec ( DotNet.Options.withWorkingDirectory workingDir >> withDotnetExe) command args
30+
31+ if result.ExitCode <> 0 then failwithf " dotnet %s failed with errors: %s " args ( result.Errors |> String.concat " \n " )
5632
5733// --------------------------------------------------------------------------------------
5834// The rest of the code is standard F# build script
@@ -61,77 +37,68 @@ let runCmdIn workDir (exe:string) = Printf.ksprintf (fun (args:string) ->
6137let releaseDir = Path.Combine(__ SOURCE_ DIRECTORY__, " ../artifacts/bin/fcs/Release" )
6238
6339// Read release notes & version info from RELEASE_NOTES.md
64- let release = LoadReleaseNotes (__ SOURCE_ DIRECTORY__ + " /RELEASE_NOTES.md" )
65- let isAppVeyorBuild = buildServer = BuildServer.AppVeyor
66- let isJenkinsBuild = buildServer = BuildServer.Jenkins
40+ let release = ReleaseNotes.load (__ SOURCE_ DIRECTORY__ + " /RELEASE_NOTES.md" )
41+ let isAppVeyorBuild = AppVeyor.detect()
6742let isVersionTag ( tag : string ) = Version.TryParse tag |> fst
68- let hasRepoVersionTag = isAppVeyorBuild && AppVeyorEnvironment. RepoTag && isVersionTag AppVeyorEnvironment .RepoTagName
69- let assemblyVersion = if hasRepoVersionTag then AppVeyorEnvironment .RepoTagName else release.NugetVersion
43+ let hasRepoVersionTag = isAppVeyorBuild && AppVeyor.Environment. RepoTag && isVersionTag AppVeyor.Environment .RepoTagName
44+ let assemblyVersion = if hasRepoVersionTag then AppVeyor.Environment .RepoTagName else release.NugetVersion
7045
7146let buildVersion =
7247 if hasRepoVersionTag then assemblyVersion
73- else if isAppVeyorBuild then sprintf " %s -b%s " assemblyVersion AppVeyorEnvironment .BuildNumber
48+ else if isAppVeyorBuild then sprintf " %s -b%s " assemblyVersion AppVeyor.Environment .BuildNumber
7449 else assemblyVersion
7550
76- Target " Clean" ( fun _ ->
77- CleanDir releaseDir
51+ Target.create " Clean" ( fun _ ->
52+ Shell.cleanDir releaseDir
7853)
7954
80- Target " Restore" ( fun _ ->
55+ Target.create " Restore" ( fun _ ->
8156 // We assume a paket restore has already been run
82- runDotnet __ SOURCE_ DIRECTORY__ " restore ../src/buildtools/buildtools.proj -v n"
83- runDotnet __ SOURCE_ DIRECTORY__ " restore FSharp.Compiler.Service.sln -v n"
57+ runDotnet __ SOURCE_ DIRECTORY__ " restore" " ../src/buildtools/buildtools.proj -v n"
58+ runDotnet __ SOURCE_ DIRECTORY__ " restore" " FSharp.Compiler.Service.sln -v n"
8459)
8560
86- Target " BuildVersion" ( fun _ ->
61+ Target.create " BuildVersion" ( fun _ ->
8762 Shell.Exec( " appveyor" , sprintf " UpdateBuild -Version \" %s \" " buildVersion) |> ignore
8863)
8964
90- Target " Build" ( fun _ ->
91- runDotnet __ SOURCE_ DIRECTORY__ " build ../src/buildtools/buildtools.proj -v n -c Proto"
65+ Target.create " Build" ( fun _ ->
66+ runDotnet __ SOURCE_ DIRECTORY__ " build" " ../src/buildtools/buildtools.proj -v n -c Proto"
9267 let fslexPath = __ SOURCE_ DIRECTORY__ + " /../artifacts/bin/fslex/Proto/netcoreapp2.1/fslex.dll"
9368 let fsyaccPath = __ SOURCE_ DIRECTORY__ + " /../artifacts/bin/fsyacc/Proto/netcoreapp2.1/fsyacc.dll"
94- runDotnet __ SOURCE_ DIRECTORY__ ( sprintf " build FSharp.Compiler.Service.sln -v n -c Release /p:FsLexPath=%s /p:FsYaccPath=%s /p:VersionPrefix= %s " fslexPath fsyaccPath assemblyVersion )
69+ runDotnet __ SOURCE_ DIRECTORY__ " build " ( sprintf " FSharp.Compiler.Service.sln -v n -c Release /p:FsLexPath=%s /p:FsYaccPath=%s " fslexPath fsyaccPath)
9570)
9671
97- Target " Test" ( fun _ ->
72+ Target.create " Test" ( fun _ ->
9873 // This project file is used for the netcoreapp2.0 tests to work out reference sets
99- runDotnet __ SOURCE_ DIRECTORY__ " build ../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard2_0/Sample_NETCoreSDK_FSharp_Library_netstandard2_0.fsproj -v n /restore /p:DisableCompilerRedirection=true"
74+ runDotnet __ SOURCE_ DIRECTORY__ " build" " ../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard2_0/Sample_NETCoreSDK_FSharp_Library_netstandard2_0.fsproj -v n /restore /p:DisableCompilerRedirection=true"
10075
10176 // Now run the tests
10277 let logFilePath = Path.Combine(__ SOURCE_ DIRECTORY__, " .." , " artifacts" , " TestResults" , " Release" , " FSharp.Compiler.Service.Test.xml" )
103- runDotnet __ SOURCE_ DIRECTORY__ ( sprintf " test FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj --no-restore --no-build -v n -c Release --test-adapter-path . --logger \" nunit;LogFilePath=%s \" " logFilePath)
78+ runDotnet __ SOURCE_ DIRECTORY__ " test " ( sprintf " FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj --no-restore --no-build -v n -c Release --test-adapter-path . --logger \" nunit;LogFilePath=%s \" " logFilePath)
10479)
10580
106- // escape a string's content so that it can be passed on the command line
107- let escapeString ( s : string ) =
108- let replaced = s.Replace( " \" " , " \\\" " )
109- sprintf " \" %s \" " replaced
110-
111- Target " NuGet" ( fun _ ->
112- let props =
113- [ " VersionPrefix" , release.NugetVersion
114- " PackageReleaseNotes" , release.Notes |> String.concat " \n " ]
115- |> Seq.map ( fun ( prop , value ) -> sprintf " -p:%s =%s " prop ( escapeString value))
116- |> String.concat " "
117-
118- runDotnet __ SOURCE_ DIRECTORY__ ( sprintf " pack FSharp.Compiler.Service.sln --no-build -v n -c Release %s " props)
81+ Target.create " NuGet" ( fun _ ->
82+ DotNet.pack ( fun packOpts ->
83+ { packOpts with
84+ Configuration = DotNet.BuildConfiguration.Release
85+ Common = packOpts.Common |> withDotnetExe |> DotNet.Options.withVerbosity ( Some DotNet.Verbosity.Normal)
86+ MSBuildParams = { packOpts.MSBuildParams with
87+ Properties = packOpts.MSBuildParams.Properties @ [ " Version" , assemblyVersion; " PackageReleaseNotes" , release.Notes |> String.concat " \n " ] }
88+ }) " FSharp.Compiler.Service.sln"
11989)
12090
121- Target " GenerateDocsEn" ( fun _ ->
122- executeFSIWithArgs " docsrc/tools" " generate.fsx" [] [] |> ignore
91+ Target.create " GenerateDocsEn" ( fun _ ->
92+ runDotnet " docsrc/tools" " fake " " run generate.fsx"
12393)
12494
125- Target " GenerateDocsJa" ( fun _ ->
126- executeFSIWithArgs " docsrc/tools" " generate.ja.fsx" [] [] |> ignore
95+ Target.create " GenerateDocsJa" ( fun _ ->
96+ runDotnet " docsrc/tools" " fake " " run generate.ja.fsx"
12797)
12898
129- Target " PublishNuGet" ( fun _ ->
130- Paket.Push ( fun p ->
131- let apikey =
132- match getBuildParam " nuget-apikey" with
133- | s when not ( String.IsNullOrWhiteSpace s) -> s
134- | _ -> getUserInput " Nuget API Key: "
99+ Target.create " PublishNuGet" ( fun _ ->
100+ let apikey = Environment.environVarOrDefault " nuget-apikey" ( UserInput.getUserPassword " Nuget API Key: " )
101+ Paket.push ( fun p ->
135102 { p with
136103 ApiKey = apikey
137104 WorkingDir = releaseDir })
@@ -140,10 +107,12 @@ Target "PublishNuGet" (fun _ ->
140107// --------------------------------------------------------------------------------------
141108// Run all targets by default. Invoke 'build <Target>' to override
142109
143- Target " Start" DoNothing
144- Target " Release" DoNothing
145- Target " GenerateDocs" DoNothing
146- Target " TestAndNuGet" DoNothing
110+ Target.create " Start" ignore
111+ Target.create " Release" ignore
112+ Target.create " GenerateDocs" ignore
113+ Target.create " TestAndNuGet" ignore
114+
115+ open Fake.Core .TargetOperators
147116
148117" Start"
149118 =?> ( " BuildVersion" , isAppVeyorBuild)
@@ -161,21 +130,21 @@ Target "TestAndNuGet" DoNothing
161130
162131" NuGet"
163132 ==> " TestAndNuGet"
164-
133+
165134" Build"
166135 ==> " NuGet"
167136 ==> " PublishNuGet"
168137 ==> " Release"
169138
170139" Build"
171- ==> " GenerateDocsEn"
140+ // ==> "GenerateDocsEn"
172141 ==> " GenerateDocs"
173142
174143" Build"
175- ==> " GenerateDocsJa"
144+ // ==> "GenerateDocsJa"
176145 ==> " GenerateDocs"
177146
178147" GenerateDocs"
179148 ==> " Release"
180149
181- RunTargetOrDefault " Build"
150+ Target.runOrDefaultWithArguments " Build"
0 commit comments