build.fsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. let utilityProjName = "Utility"
  27. let utilityProjpath = "Utility/Utility.fsproj"
  28. // --------------------------------------------------------------------------------------
  29. // Helpers
  30. // --------------------------------------------------------------------------------------
  31. open Fake.DotNet
  32. let buildConf = DotNet.BuildConfiguration.Release
  33. let dotnetSdk = lazy DotNet.install DotNet.Versions.FromGlobalJson
  34. let inline dtntSmpl arg = DotNet.Options.lift dotnetSdk.Value arg
  35. let targetFrameworks = ["net461"; "netcoreapp3.1"]
  36. // --------------------------------------------------------------------------------------
  37. // Targets
  38. // --------------------------------------------------------------------------------------
  39. let dotnetBuild =
  40. DotNet.build (fun x ->
  41. // Чтобы в Linux'е не компилировался net461, дан этот костыль:
  42. { x with
  43. Configuration = buildConf
  44. Framework =
  45. if not Environment.isWindows then
  46. Some "netcoreapp3.1"
  47. else
  48. None
  49. }
  50. |> dtntSmpl)
  51. Target.create "BuildServer" (fun _ ->
  52. serverProjPath
  53. |> Fake.IO.Path.getDirectory
  54. |> dotnetBuild
  55. )
  56. Target.create "BuildTest" (fun _ ->
  57. testProjPath
  58. |> Fake.IO.Path.getDirectory
  59. |> dotnetBuild
  60. )
  61. Target.create "BuildUtility" (fun _ ->
  62. utilityProjpath
  63. |> Fake.IO.Path.getDirectory
  64. |> dotnetBuild
  65. )
  66. Target.create "Copy3rd" <| fun _ ->
  67. let srcDir = @"3rd"
  68. if not <| System.IO.Directory.Exists srcDir then
  69. failwithf "'%s' not found" srcDir
  70. targetFrameworks
  71. |> List.iter (fun targetFramework ->
  72. let localPath = sprintf "bin/%A/%s" buildConf targetFramework
  73. let dstDir = sprintf "%s/%s/%s" serverProjName localPath srcDir
  74. Fake.IO.Shell.copyDir dstDir srcDir (fun _ -> true)
  75. )
  76. let run projName targetFramework projPath =
  77. let dir = Fake.IO.Path.getDirectory projPath
  78. let localpath = sprintf "bin/%A/%s/%s.exe" buildConf targetFramework projName
  79. let path = Fake.IO.Path.combine dir localpath
  80. if not <| Fake.IO.File.exists path then
  81. failwithf "not found %s" path
  82. Command.RawCommand(path, Arguments.Empty)
  83. |> CreateProcess.fromCommand
  84. |> CreateProcess.withWorkingDirectory (Fake.IO.Path.getDirectory path)
  85. |> Proc.run
  86. Target.create "RunTest" (fun _ ->
  87. let targetFramework = targetFrameworks.[0]
  88. let x = run testProjName targetFramework testProjPath
  89. if x.ExitCode <> 0 then
  90. failwith "test error"
  91. )
  92. Target.create "TrimTrailingWhitespace" (fun _ ->
  93. // по-хорошему, нужно использовать .gitignore, но и так пока сойдет
  94. let files =
  95. !! "**/*.fs"
  96. ++ "**/*.fsx"
  97. ++ "**/*.fsproj"
  98. ++ "**/*.cs"
  99. ++ "**/*.csproj"
  100. -- "**/obj/**"
  101. -- "**/paket-files/**"
  102. -- "**/packages/**"
  103. files
  104. |> Seq.iter (fun path ->
  105. System.IO.File.ReadAllLines path
  106. |> Array.map (fun x -> x.TrimEnd())
  107. |> fun content -> System.IO.File.WriteAllLines(path, content)
  108. )
  109. )
  110. Target.create "CopyToMainProj" (fun _ ->
  111. let srcDir = sprintf @"QspServer/bin/%A" buildConf
  112. let dstDir = @"e:/Project/Qsp/QspVscodeExtension/release/bin"
  113. Fake.IO.Shell.copyDir dstDir srcDir (fun _ -> true)
  114. )
  115. // --------------------------------------------------------------------------------------
  116. // Build order
  117. // --------------------------------------------------------------------------------------
  118. open Fake.Core.TargetOperators
  119. Target.create "Default" ignore
  120. "BuildServer"
  121. ==> "Copy3rd"
  122. ==> "Default"
  123. "BuildTest"
  124. ==> "Copy3rd"
  125. ==> "CopyToMainProj"
  126. ==> "RunTest"
  127. Target.runOrDefault "Default"