build.fsx 5.9 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__ + "/../artifacts/TestResults") 
File.WriteAllText(__SOURCE_DIRECTORY__ + "/../artifacts/TestResults/notestsyet.txt","No tests yet")
18 19 20
let isMono = true
#else
let isMono = false
21 22
#endif

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

27 28 29 30 31 32 33
let dotnetExePath =
    // Build.cmd normally downloads a dotnet cli to: <repo-root>\artifacts\toolset\dotnet
    // check if there is one there to avoid downloading an additional one here
    let pathToCli = Path.Combine(__SOURCE_DIRECTORY__, @"..\artifacts\toolset\dotnet\dotnet.exe")
    if File.Exists(pathToCli) then
        pathToCli
    else
34
        DotNetCli.InstallDotNetSDK "2.1.504"
35 36 37 38 39 40 41 42 43 44

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

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

D
Don Syme 已提交
47 48 49 50 51
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
52
        Shell.Exec("mono", sprintf "%s %s" exe args, workDir)
D
Don Syme 已提交
53 54
#else
        printfn "[%s] %s %s" workDir exe args
55
        Shell.Exec(exe, args, workDir)
D
Don Syme 已提交
56
#endif
57 58 59 60 61 62 63
        |> assertExitCodeZero
)

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

64
let releaseDir = Path.Combine(__SOURCE_DIRECTORY__, "../artifacts/bin/fcs")
65 66 67 68

// Read release notes & version info from RELEASE_NOTES.md
let release = LoadReleaseNotes (__SOURCE_DIRECTORY__ + "/RELEASE_NOTES.md")
let isAppVeyorBuild = buildServer = BuildServer.AppVeyor
69
let isJenkinsBuild = buildServer = BuildServer.Jenkins
70 71 72
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
73

74 75 76 77 78
let buildVersion =
    if hasRepoVersionTag then assemblyVersion
    else if isAppVeyorBuild then sprintf "%s-b%s" assemblyVersion AppVeyorEnvironment.BuildNumber
    else assemblyVersion

79 80 81 82 83
Target "Clean" (fun _ ->
    CleanDir releaseDir
)

Target "Restore" (fun _ ->
84
    // We assume a paket restore has already been run
B
Brett V. Forsgren 已提交
85
    runDotnet __SOURCE_DIRECTORY__ "restore ../src/buildtools/buildtools.proj -v n"
86
    runDotnet __SOURCE_DIRECTORY__ "restore FSharp.Compiler.Service.sln -v n"
87 88
)

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

93
Target "Build" (fun _ ->
B
Brett V. Forsgren 已提交
94
    runDotnet __SOURCE_DIRECTORY__ "build ../src/buildtools/buildtools.proj -v n -c Proto"
B
Brett V. Forsgren 已提交
95 96 97
    let fslexPath = __SOURCE_DIRECTORY__ + "/../artifacts/bin/fslex/Proto/netcoreapp2.0/fslex.dll"
    let fsyaccPath = __SOURCE_DIRECTORY__ + "/../artifacts/bin/fsyacc/Proto/netcoreapp2.0/fsyacc.dll"
    runDotnet __SOURCE_DIRECTORY__ (sprintf "build FSharp.Compiler.Service.sln -v n -c Release /p:FsLexPath=%s /p:FsYaccPath=%s" fslexPath fsyaccPath)
98 99
)

100
Target "Test" (fun _ ->
101
    // This project file is used for the netcoreapp2.0 tests to work out reference sets
102
    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"
103

104
    // Now run the tests
B
Brett V. Forsgren 已提交
105 106
    let logFilePath = Path.Combine(__SOURCE_DIRECTORY__, "..", "artifacts", "TestResults", "Release", "FSharp.Compiler.Service.Test.xml")
    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)
107
)
108

109
Target "NuGet" (fun _ ->
B
Brett V. Forsgren 已提交
110
    runDotnet __SOURCE_DIRECTORY__ "pack FSharp.Compiler.Service.sln -v n -c Release"
111 112
)

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

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

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

135
Target "Start" DoNothing
136
Target "Release" DoNothing
D
Don Syme 已提交
137 138
Target "GenerateDocs" DoNothing
Target "TestAndNuGet" DoNothing
139

140
"Start"
141
  =?> ("BuildVersion", isAppVeyorBuild)
142
  ==> "Restore"
143 144
  ==> "Build"

145 146
"Build"
  ==> "Test"
147

148
"Build"
149 150
  ==> "NuGet"

151
"Test"
D
Don Syme 已提交
152 153 154 155
  ==> "TestAndNuGet"

"NuGet"
  ==> "TestAndNuGet"
156
  
157 158 159 160 161
"Build"
  ==> "NuGet"
  ==> "PublishNuGet"
  ==> "Release"

D
Don Syme 已提交
162 163
"Build"
  ==> "GenerateDocsEn"
164
  ==> "GenerateDocs"
D
Don Syme 已提交
165 166

"Build"
167
  ==> "GenerateDocsJa"
D
Don Syme 已提交
168 169 170
  ==> "GenerateDocs"

"GenerateDocs"
171 172 173
  ==> "Release"

RunTargetOrDefault "Build"