build.fsx 4.2 KB

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