build.fsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. let run projName projPath =
  43. let dir = Fake.IO.Path.getDirectory projPath
  44. let localpath = sprintf "bin/%A/net461/%s.exe" buildConf projName
  45. let path = Fake.IO.Path.combine dir localpath
  46. if not <| Fake.IO.File.exists path then
  47. failwithf "not found %s" path
  48. Command.RawCommand(path, Arguments.Empty)
  49. |> CreateProcess.fromCommand
  50. |> CreateProcess.withWorkingDirectory (Fake.IO.Path.getDirectory path)
  51. |> Proc.run
  52. Target.create "RunTest" (fun _ ->
  53. let x = run testProjName testProjPath
  54. if x.ExitCode <> 0 then
  55. raise <| Fake.Testing.Common.FailedTestsException "test error"
  56. )
  57. Target.create "TrimTrailingWhitespace" (fun _ ->
  58. // по-хорошему, нужно использовать .gitignore, но и так пока сойдет
  59. let files =
  60. !! "**/*.fs"
  61. ++ "**/*.fsx"
  62. ++ "**/*.fsproj"
  63. ++ "**/*.cs"
  64. ++ "**/*.csproj"
  65. -- "**/obj/**"
  66. -- "**/paket-files/**"
  67. -- "**/packages/**"
  68. files
  69. |> Seq.iter (fun path ->
  70. System.IO.File.ReadAllLines path
  71. |> Array.map (fun x -> x.TrimEnd())
  72. |> fun content -> System.IO.File.WriteAllLines(path, content)
  73. )
  74. )
  75. open Fake.IO
  76. // TODO: скачать и распаковать http://qsp.su/attachments/txt2gam011.zip в "Utils\txt2gam"
  77. let compilerPath =
  78. Lazy.Create (fun _ ->
  79. let compilerPath = "Utils/txt2gam/txt2gam.exe"
  80. if System.IO.File.Exists compilerPath then compilerPath
  81. else
  82. failwithf "Compiler not found at '%A'" compilerPath
  83. )
  84. let compiler src =
  85. let dst = Path.changeExtension ".qsp" src
  86. Command.RawCommand(compilerPath.Value, Arguments.ofList [src; dst])
  87. |> CreateProcess.fromCommand
  88. |> CreateProcess.withWorkingDirectory (Path.getDirectory compilerPath.Value)
  89. |> Proc.run
  90. |> fun x -> x.ExitCode
  91. Target.create "Watch" (fun _ ->
  92. use watcher =
  93. !! "Utils/txt2gam/*.qsps"
  94. |> Fake.IO.ChangeWatcher.run (fun changes ->
  95. changes
  96. |> Seq.iter (fun x ->
  97. Trace.trace "Compilation..."
  98. let code = compiler x.FullPath
  99. Trace.trace (sprintf "Compilation completed with code %d" code)
  100. )
  101. )
  102. System.Console.ReadLine() |> ignore
  103. watcher.Dispose() // по-идеи, и так должен выгрузиться
  104. )
  105. // --------------------------------------------------------------------------------------
  106. // Build order
  107. // --------------------------------------------------------------------------------------
  108. open Fake.Core.TargetOperators
  109. "BuildTest"
  110. ==> "RunTest"
  111. Target.runOrDefault "RunTest"