build.fsx 5.5 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 95
    runDotnet __SOURCE_DIRECTORY__ "build ../src/buildtools/buildtools.proj -v n -c Proto"
    runDotnet __SOURCE_DIRECTORY__ "build FSharp.Compiler.Service.sln -v n -c release"
96 97
)

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

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

106
Target "NuGet" (fun _ ->
B
Brett V. Forsgren 已提交
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"