build.fsx 5.1 KB

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