This repository has been archived by the owner on Jan 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
/
build.fsx
178 lines (145 loc) · 5.54 KB
/
build.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// include Fake lib
#r @"packages/FAKE/tools/FakeLib.dll"
open Fake
open System
open System.IO
open System.Text.RegularExpressions
Target "RestorePackages" (fun _ ->
"packages.config"
|> RestorePackage (fun p ->
{ p with
ToolPath = "../lib/nuget/NuGet.exe" })
)
let buildDir = "./bin/Debug/"
let buildReleaseDir = "./bin/Release/"
let integrationTestDir = "./test/integration/"
let emacsBinDir = "../emacs/bin/"
Target "BuildDebug" (fun _ ->
MSBuildDebug buildDir "Build" ["./FSharp.AutoComplete.sln"]
|> Log "Build-Output: "
)
Target "BuildRelease" (fun _ ->
MSBuildRelease buildReleaseDir "Build" ["./FSharp.AutoComplete.sln"]
|> Log "Build-Output: "
)
let integrationTests =
!! (integrationTestDir + "/**/*Runner.fsx")
let runIntegrationTest (fn: string) : bool =
let dir = Path.GetDirectoryName fn
tracefn "Running FSIHelper '%s', '%s', '%s'" FSIHelper.fsiPath dir fn
let b, msgs = FSIHelper.executeFSI dir fn []
if not b then
for msg in msgs do
traceError msg.Message
// Normalize output files so that a simple
// `git diff` will be clean if the tests passed.
for fn in !! (dir + "/*.txt") ++ (dir + "/*.json") do
let lines = File.ReadAllLines fn
for i in [ 0 .. lines.Length - 1 ] do
if Path.DirectorySeparatorChar = '/' then
lines.[i] <- Regex.Replace(lines.[i],
"/.*?FSharp.AutoComplete/test/(.*?(\"|$))",
"<absolute path removed>/test/$1")
lines.[i] <- Regex.Replace(lines.[i],
"\"/[^\"]*?/([^\"/]*?\.dll\")",
"\"<absolute path removed>/$1")
else
if Path.GetExtension fn = ".json" then
lines.[i] <- Regex.Replace(lines.[i].Replace(@"\\", "/"),
"[a-zA-Z]:/.*?FSharp.AutoComplete/test/(.*?(\"|$))",
"<absolute path removed>/test/$1")
lines.[i] <- Regex.Replace(lines.[i],
"\"[a-zA-Z]:/[^\"]*?/([^\"/]*?\.dll\")",
"\"<absolute path removed>/$1")
else
lines.[i] <- Regex.Replace(lines.[i].Replace('\\','/'),
"[a-zA-Z]:/.*?FSharp.AutoComplete/test/(.*?(\"|$))",
"<absolute path removed>/test/$1")
// Write manually to ensure \n line endings on all platforms
using (new StreamWriter(fn))
<| fun f ->
for line in lines do
f.Write(line)
f.Write('\n')
b
Target "IntegrationTest" (fun _ ->
let runOk =
[ for i in integrationTests do
yield runIntegrationTest i ]
|> Seq.forall id
if not runOk then
failwith "Integration tests did not run successfully"
else
let ok, out, err =
Git.CommandHelper.runGitCommand
"."
("diff --exit-code " + integrationTestDir)
if not ok then
trace (toLines out)
failwithf "Integration tests failed:\n%s" err
)
Target "BuildEmacs" (fun _ ->
MSBuildDebug emacsBinDir "Build" ["./FSharp.AutoComplete.sln"]
|> Log "Build-Output: "
)
module Emacs =
let emacsd = "../emacs/"
let srcFiles = !! (emacsd + "*.el")
let testd = emacsd + "test/"
let utils = !! (testd + "/test-common.el")
let tmpd = emacsd + "tmp/"
let bind = emacsd + "bin/"
let exe =
match buildServer with
| AppVeyor -> Path.GetFullPath "../emacs-local/bin/emacs.exe"
| _ -> @"emacs"
let compileOpts =
[ for f in srcFiles do
yield sprintf """--batch --eval "(package-initialize)" --eval "(add-to-list 'load-path \"%s\")" --eval "(setq byte-compile-error-on-warn t)" -f batch-byte-compile %s"""
((Path.GetFullPath emacsd).Replace(@"\", @"\\").TrimEnd('\\'))
f ]
let checkDeclareOpts =
sprintf """--batch --eval "(package-initialize)" --eval "(when (check-declare-directory \"%s\") (kill-emacs 1)))" """
((Path.GetFullPath emacsd).Replace(@"\", @"\\").TrimEnd('\\'))
let makeLoad glob =
[ for f in glob do yield "-l " + f ]
|> String.concat " "
Target "EmacsTest" (fun _ ->
if not (Directory.Exists (Path.GetFullPath Emacs.tmpd)) then
Directory.CreateDirectory Emacs.tmpd |> ignore
let home = Environment.GetEnvironmentVariable("HOME")
Environment.SetEnvironmentVariable("HOME", Path.GetFullPath Emacs.tmpd)
let loadFiles = Emacs.makeLoad Emacs.utils
let tests =
[ yield Emacs.exe, loadFiles + " --batch --eval \"(progn (set-default-coding-systems 'utf-8) (load-packages))\""
yield Emacs.exe, loadFiles + " --batch -f run-fsharp-unit-tests"
// AppVeyor doesn't currently run the integration tests
if buildServer <> AppVeyor then
yield Emacs.exe, loadFiles + " --batch -f run-fsharp-integration-tests"
yield! [ for opts in Emacs.compileOpts do yield Emacs.exe, opts ]
// AppVeyor also fails to run check-declare-directory
if buildServer <> AppVeyor then
yield Emacs.exe, Emacs.checkDeclareOpts ]
ProcessTestRunner.RunConsoleTests
(fun p -> { p with WorkingDir = Emacs.emacsd })
tests
Environment.SetEnvironmentVariable("HOME", home)
)
Target "Clean" (fun _ ->
CleanDirs [ buildDir; buildReleaseDir; emacsBinDir ]
)
Target "Build" id
Target "Test" id
Target "All" id
"RestorePackages"
==> "BuildDebug"
==> "Build"
==> "IntegrationTest"
"RestorePackages"
==> "BuildEmacs"
==> "EmacsTest"
"EmacsTest" ==> "Test"
"IntegrationTest" ==> "Test"
"BuildDebug" ==> "All"
"Test" ==> "All"
RunTargetOrDefault "BuildDebug"