build.fsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // --------------------------------------------------------------------------------------
  2. // FAKE build script
  3. // --------------------------------------------------------------------------------------
  4. #r "./packages/build/FAKE/tools/FakeLib.dll"
  5. open Fake.IO.Globbing.Operators
  6. open Fake.Core
  7. // --------------------------------------------------------------------------------------
  8. // Build variables
  9. // --------------------------------------------------------------------------------------
  10. let f projName =
  11. let pattern = sprintf @"**\%s.fsproj" projName
  12. let xs = !! pattern
  13. xs
  14. |> Seq.tryExactlyOne
  15. |> Option.defaultWith (fun () ->
  16. xs
  17. |> List.ofSeq
  18. |> failwithf "'%s' expected exactly one but:\n%A" pattern
  19. )
  20. let testProjName = "Test"
  21. let testProjPath = @"Test\Test.fsproj"
  22. let mainProjName = "QspServer"
  23. let mainProjName2 = "QSParse"
  24. let mainProjPath = f mainProjName
  25. // --------------------------------------------------------------------------------------
  26. // Helpers
  27. // --------------------------------------------------------------------------------------
  28. open Fake.DotNet
  29. let buildConf = DotNet.BuildConfiguration.Debug
  30. let dotnetSdk = lazy DotNet.install DotNet.Versions.FromGlobalJson
  31. let inline dtntSmpl arg = DotNet.Options.lift dotnetSdk.Value arg
  32. // --------------------------------------------------------------------------------------
  33. // Targets
  34. // --------------------------------------------------------------------------------------
  35. Target.create "BuildTest" (fun _ ->
  36. testProjPath
  37. |> Fake.IO.Path.getDirectory
  38. |> DotNet.build (fun x ->
  39. { x with Configuration = buildConf }
  40. |> dtntSmpl)
  41. )
  42. Target.create "Copy3rd" <| fun _ ->
  43. let srcDir = @"3rd"
  44. if not <| System.IO.Directory.Exists srcDir then
  45. failwithf "'%s' not found" srcDir
  46. let localPath = sprintf "bin/%A/net461" buildConf
  47. let dstDir = sprintf "%s/%s/%s" mainProjName localPath srcDir
  48. // printfn "%s\n%s" srcDir dstDir
  49. Fake.IO.Shell.copyDir dstDir srcDir (fun _ -> true)
  50. let run projName projPath =
  51. let dir = Fake.IO.Path.getDirectory projPath
  52. let localpath = sprintf "bin/%A/net461/%s.exe" buildConf projName
  53. let path = Fake.IO.Path.combine dir localpath
  54. if not <| Fake.IO.File.exists path then
  55. failwithf "not found %s" path
  56. Command.RawCommand(path, Arguments.Empty)
  57. |> CreateProcess.fromCommand
  58. |> CreateProcess.withWorkingDirectory (Fake.IO.Path.getDirectory path)
  59. |> Proc.run
  60. Target.create "RunTest" (fun _ ->
  61. let x = run testProjName testProjPath
  62. if x.ExitCode <> 0 then
  63. raise <| Fake.Testing.Common.FailedTestsException "test error"
  64. )
  65. Target.create "TrimTrailingWhitespace" (fun _ ->
  66. // по-хорошему, нужно использовать .gitignore, но и так пока сойдет
  67. let files =
  68. !! "**/*.fs"
  69. ++ "**/*.fsx"
  70. ++ "**/*.fsproj"
  71. ++ "**/*.cs"
  72. ++ "**/*.csproj"
  73. -- "**/obj/**"
  74. -- "**/paket-files/**"
  75. -- "**/packages/**"
  76. files
  77. |> Seq.iter (fun path ->
  78. System.IO.File.ReadAllLines path
  79. |> Array.map (fun x -> x.TrimEnd())
  80. |> fun content -> System.IO.File.WriteAllLines(path, content)
  81. )
  82. )
  83. Target.create "CopyToMainProj" (fun _ ->
  84. let srcDir = @"QspServer\bin\Debug\net461"
  85. let dstDir = @"e:\Project\Qsp\QspVscodeExtension\release\bin"
  86. Fake.IO.Shell.copyDir dstDir srcDir (fun _ -> true)
  87. )
  88. // --------------------------------------------------------------------------------------
  89. // Build order
  90. // --------------------------------------------------------------------------------------
  91. open Fake.Core.TargetOperators
  92. "BuildTest"
  93. ==> "Copy3rd"
  94. // ==> "CopyToMainProj"
  95. ==> "RunTest"
  96. Target.runOrDefault "RunTest"