build.fsx 5.6 KB
Newer Older
1 2 3 4 5 6 7
// --------------------------------------------------------------------------------------
// FAKE build script
// --------------------------------------------------------------------------------------

#I "packages/FAKE/tools"
#r "packages/FAKE/tools/FakeLib.dll"
open System
D
Don Syme 已提交
8
open System.IO
9
open Fake
D
Don Syme 已提交
10
open Fake.AppVeyor
11 12 13 14 15
open Fake.ReleaseNotesHelper

#if MONO
// prevent incorrect output encoding (e.g. https://github.com/fsharp/FAKE/issues/1196)
System.Console.OutputEncoding <- System.Text.Encoding.UTF8
16 17
CleanDir (__SOURCE_DIRECTORY__ + "/../tests/TestResults") 
File.WriteAllText(__SOURCE_DIRECTORY__ + "/../tests/TestResults/notestsyet.txt","No tests yet")
18 19 20
let isMono = true
#else
let isMono = false
21 22
#endif

23 24 25 26
// --------------------------------------------------------------------------------------
// Utilities
// --------------------------------------------------------------------------------------

D
Don Syme 已提交
27
let dotnetExePath = DotNetCli.InstallDotNetSDK "2.1.403"
28 29 30 31 32 33 34 35 36 37

let runDotnet workingDir args =
    let result =
        ExecProcess (fun info ->
            info.FileName <- dotnetExePath
            info.WorkingDirectory <- workingDir
            info.Arguments <- args) TimeSpan.MaxValue

    if result <> 0 then failwithf "dotnet %s failed" args

38
let assertExitCodeZero x = if x = 0 then () else failwithf "Command failed with exit code %i" x
39

D
Don Syme 已提交
40 41 42 43 44
let runCmdIn workDir (exe:string) = Printf.ksprintf (fun (args:string) ->
#if MONO
        let exe = exe.Replace("\\","/")
        let args = args.Replace("\\","/")
        printfn "[%s] mono %s %s" workDir exe args
45
        Shell.Exec("mono", sprintf "%s %s" exe args, workDir)
D
Don Syme 已提交
46 47
#else
        printfn "[%s] %s %s" workDir exe args
48
        Shell.Exec(exe, args, workDir)
D
Don Syme 已提交
49
#endif
50 51 52 53 54 55 56
        |> assertExitCodeZero
)

// --------------------------------------------------------------------------------------
// The rest of the code is standard F# build script
// --------------------------------------------------------------------------------------

57
let releaseDir = Path.Combine(__SOURCE_DIRECTORY__, "../release/fcs")
58 59 60 61

// Read release notes & version info from RELEASE_NOTES.md
let release = LoadReleaseNotes (__SOURCE_DIRECTORY__ + "/RELEASE_NOTES.md")
let isAppVeyorBuild = buildServer = BuildServer.AppVeyor
62
let isJenkinsBuild = buildServer = BuildServer.Jenkins
63 64 65
let isVersionTag tag = Version.TryParse tag |> fst
let hasRepoVersionTag = isAppVeyorBuild && AppVeyorEnvironment.RepoTag && isVersionTag AppVeyorEnvironment.RepoTagName
let assemblyVersion = if hasRepoVersionTag then AppVeyorEnvironment.RepoTagName else release.NugetVersion
66

67 68 69 70 71
let buildVersion =
    if hasRepoVersionTag then assemblyVersion
    else if isAppVeyorBuild then sprintf "%s-b%s" assemblyVersion AppVeyorEnvironment.BuildNumber
    else assemblyVersion

72 73 74 75 76
Target "Clean" (fun _ ->
    CleanDir releaseDir
)

Target "Restore" (fun _ ->
77 78 79
    // We assume a paket restore has already been run
    runDotnet __SOURCE_DIRECTORY__ "restore FSharp.Compiler.Service.sln -v n"
    for p in [ "../packages.config" ] do
K
Kevin Ransom (msft) 已提交
80 81 82 83 84 85 86
        let rec executeProcess count =
            let result = ExecProcess (fun info ->
                info.FileName <- FullName @"./../.nuget/NuGet.exe"
                info.WorkingDirectory <- FullName @"./.."
                info.Arguments <- sprintf "restore %s -PackagesDirectory \"%s\" -ConfigFile \"%s\""   (FullName p) (FullName "./../packages") (FullName "./../NuGet.Config")) TimeSpan.MaxValue
            if result <> 0 && count > 1 then  executeProcess (count - 1) else result
        (executeProcess 5) |> assertExitCodeZero
87 88
)

89 90 91 92
Target "BuildVersion" (fun _ ->
    Shell.Exec("appveyor", sprintf "UpdateBuild -Version \"%s\"" buildVersion) |> ignore
)

93
Target "Build" (fun _ ->
94
    runDotnet __SOURCE_DIRECTORY__ "build FSharp.Compiler.Service.sln -v n -c Release"
95 96
)

97
Target "Test" (fun _ ->
98
    // This project file is used for the netcoreapp2.0 tests to work out reference sets
99 100
    runDotnet __SOURCE_DIRECTORY__ "restore ../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard2_0/Sample_NETCoreSDK_FSharp_Library_netstandard2_0.fsproj -v n"
    runDotnet __SOURCE_DIRECTORY__ "build ../tests/projects/Sample_NETCoreSDK_FSharp_Library_netstandard2_0/Sample_NETCoreSDK_FSharp_Library_netstandard2_0.fsproj -v n"
101

102 103 104
    // Now run the tests
    runDotnet __SOURCE_DIRECTORY__ "test FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj -v n -c Release"
)
105

106
Target "NuGet" (fun _ ->
107
    runDotnet __SOURCE_DIRECTORY__ "pack FSharp.Compiler.Service.sln -v n -c Release"
108 109
)

D
Don Syme 已提交
110
Target "GenerateDocsEn" (fun _ ->
D
Don Syme 已提交
111
    executeFSIWithArgs "docsrc/tools" "generate.fsx" [] [] |> ignore
112 113 114
)

Target "GenerateDocsJa" (fun _ ->
D
Don Syme 已提交
115
    executeFSIWithArgs "docsrc/tools" "generate.ja.fsx" [] [] |> ignore
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
)

Target "PublishNuGet" (fun _ ->
    Paket.Push (fun p ->
        let apikey =
            match getBuildParam "nuget-apikey" with
            | s when not (String.IsNullOrWhiteSpace s) -> s
            | _ -> getUserInput "Nuget API Key: "
        { p with
            ApiKey = apikey
            WorkingDir = releaseDir })
)

// --------------------------------------------------------------------------------------
// Run all targets by default. Invoke 'build <Target>' to override

132
Target "Start" DoNothing
133
Target "Release" DoNothing
D
Don Syme 已提交
134 135
Target "GenerateDocs" DoNothing
Target "TestAndNuGet" DoNothing
136

137
"Start"
138
  =?> ("BuildVersion", isAppVeyorBuild)
139
  ==> "Restore"
140 141
  ==> "Build"

142 143
"Build"
  ==> "Test"
144

145
"Build"
146 147
  ==> "NuGet"

148
"Test"
D
Don Syme 已提交
149 150 151 152
  ==> "TestAndNuGet"

"NuGet"
  ==> "TestAndNuGet"
153
  
154 155 156 157 158
"Build"
  ==> "NuGet"
  ==> "PublishNuGet"
  ==> "Release"

D
Don Syme 已提交
159 160
"Build"
  ==> "GenerateDocsEn"
161
  ==> "GenerateDocs"
D
Don Syme 已提交
162 163

"Build"
164
  ==> "GenerateDocsJa"
D
Don Syme 已提交
165 166 167
  ==> "GenerateDocs"

"GenerateDocs"
168 169 170
  ==> "Release"

RunTargetOrDefault "Build"