123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- // --------------------------------------------------------------------------------------
- // FAKE build script
- // --------------------------------------------------------------------------------------
- #r "paket:
- nuget Fake.Core.Target
- nuget Fake.Core.Process
- nuget Fake.DotNet.Cli
- nuget Fake.Core.ReleaseNotes
- nuget Fake.DotNet.AssemblyInfoFile
- nuget Fake.DotNet.Paket
- nuget Fake.Tools.Git
- nuget Fake.Core.Environment
- nuget Fake.Core.UserInput
- nuget Fake.IO.FileSystem
- nuget Fake.IO.Zip
- nuget Fake.DotNet.MsBuild
- nuget Fake.Api.GitHub
- nuget Microsoft.Build"
- #load ".fake/build.fsx/intellisense.fsx"
- open Fake.IO.Globbing.Operators
- open Fake.Core
- // --------------------------------------------------------------------------------------
- // Build variables
- // --------------------------------------------------------------------------------------
- let f projName =
- let pattern = sprintf @"**/%s.fsproj" projName
- let xs = !! pattern
- xs
- |> Seq.tryExactlyOne
- |> Option.defaultWith (fun () ->
- xs
- |> List.ofSeq
- |> failwithf "'%s' expected exactly one but:\n%A" pattern
- )
- let testProjName = "Test"
- let testProjPath = @"Test/Test.fsproj"
- let serverProjName = "QspServer"
- let parserProjName = "QSParse"
- let serverProjPath = f serverProjName
- let utilityProjName = "Utility"
- let utilityProjpath = "Utility/Utility.fsproj"
- // --------------------------------------------------------------------------------------
- // Helpers
- // --------------------------------------------------------------------------------------
- open Fake.DotNet
- let buildConf = DotNet.BuildConfiguration.Release
- let dotnetSdk = lazy DotNet.install DotNet.Versions.FromGlobalJson
- let inline dtntSmpl arg = DotNet.Options.lift dotnetSdk.Value arg
- let targetFrameworks = ["net461"; "netcoreapp3.1"]
- // --------------------------------------------------------------------------------------
- // Targets
- // --------------------------------------------------------------------------------------
- let dotnetBuild =
- DotNet.build (fun x ->
- // Чтобы в Linux'е не компилировался net461, дан этот костыль:
- { x with
- Configuration = buildConf
- Framework =
- if not Environment.isWindows then
- Some "netcoreapp3.1"
- else
- None
- }
- |> dtntSmpl)
- Target.create "BuildServer" (fun _ ->
- serverProjPath
- |> Fake.IO.Path.getDirectory
- |> dotnetBuild
- )
- Target.create "BuildTest" (fun _ ->
- testProjPath
- |> Fake.IO.Path.getDirectory
- |> dotnetBuild
- )
- Target.create "BuildUtility" (fun _ ->
- utilityProjpath
- |> Fake.IO.Path.getDirectory
- |> dotnetBuild
- )
- Target.create "Copy3rd" <| fun _ ->
- let srcDir = @"3rd"
- if not <| System.IO.Directory.Exists srcDir then
- failwithf "'%s' not found" srcDir
- targetFrameworks
- |> List.iter (fun targetFramework ->
- let localPath = sprintf "bin/%A/%s" buildConf targetFramework
- let dstDir = sprintf "%s/%s/%s" serverProjName localPath srcDir
- Fake.IO.Shell.copyDir dstDir srcDir (fun _ -> true)
- )
- let run projName targetFramework projPath =
- let dir = Fake.IO.Path.getDirectory projPath
- let localpath = sprintf "bin/%A/%s/%s.exe" buildConf targetFramework projName
- let path = Fake.IO.Path.combine dir localpath
- if not <| Fake.IO.File.exists path then
- failwithf "not found %s" path
- Command.RawCommand(path, Arguments.Empty)
- |> CreateProcess.fromCommand
- |> CreateProcess.withWorkingDirectory (Fake.IO.Path.getDirectory path)
- |> Proc.run
- Target.create "RunTest" (fun _ ->
- let targetFramework = targetFrameworks.[0]
- let x = run testProjName targetFramework testProjPath
- if x.ExitCode <> 0 then
- failwith "test error"
- )
- Target.create "TrimTrailingWhitespace" (fun _ ->
- // по-хорошему, нужно использовать .gitignore, но и так пока сойдет
- let files =
- !! "**/*.fs"
- ++ "**/*.fsx"
- ++ "**/*.fsproj"
- ++ "**/*.cs"
- ++ "**/*.csproj"
- -- "**/obj/**"
- -- "**/paket-files/**"
- -- "**/packages/**"
- files
- |> Seq.iter (fun path ->
- System.IO.File.ReadAllLines path
- |> Array.map (fun x -> x.TrimEnd())
- |> fun content -> System.IO.File.WriteAllLines(path, content)
- )
- )
- Target.create "CopyToMainProj" (fun _ ->
- let srcDir = sprintf @"QspServer/bin/%A" buildConf
- let dstDir = @"e:/Project/Qsp/QspVscodeExtension/release/bin"
- Fake.IO.Shell.copyDir dstDir srcDir (fun _ -> true)
- )
- // --------------------------------------------------------------------------------------
- // Build order
- // --------------------------------------------------------------------------------------
- open Fake.Core.TargetOperators
- Target.create "Default" ignore
- "BuildServer"
- ==> "Copy3rd"
- ==> "Default"
- "BuildTest"
- ==> "Copy3rd"
- ==> "CopyToMainProj"
- ==> "RunTest"
- // "BuildServer" <=> "BuildTest"
- // Copy3rd запускает и BuildServer, и BuildTest. Шо делать, чтобы он отдельно запускал?
- Target.runOrDefault "Default"
|