-
Notifications
You must be signed in to change notification settings - Fork 5
/
compileFSharpScripts.fsx
executable file
·177 lines (141 loc) · 4.67 KB
/
compileFSharpScripts.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
#!/usr/bin/env fsx
open System
open System.IO
open System.Linq
#r "System.Configuration"
open System.Configuration
#load "Fsdk/Misc.fs"
#load "Fsdk/Process.fs"
open Fsdk
open Fsdk.Process
let fsxRootDir = __SOURCE_DIRECTORY__ |> DirectoryInfo
let fsxTestsDir = Path.Combine(fsxRootDir.FullName, "test") |> DirectoryInfo
let rec FindFsxc(nestedCall: bool) : bool * FileInfo =
#if !LEGACY_FRAMEWORK
let fsxCompiler = "fsxc.dll"
#else
let fsxCompiler = "fsxc.exe"
#endif
let fsxcBinDir = Path.Combine(__SOURCE_DIRECTORY__, "fsxc", "bin")
let findFsxcExeFiles() =
Directory.GetFiles(fsxcBinDir, fsxCompiler, SearchOption.AllDirectories)
if not(Directory.Exists fsxcBinDir) || not(findFsxcExeFiles().Any()) then
if nestedCall then
Console.Error.WriteLine(
sprintf "'%s' compilation didn't work?" fsxCompiler
)
Environment.Exit 1
let prevCurrentDir = Directory.GetCurrentDirectory()
Directory.SetCurrentDirectory fsxRootDir.FullName
let configureProc =
Process.Execute(
{
Command = "./configure.sh"
Arguments = String.Empty
},
Echo.All
)
configureProc.UnwrapDefault() |> ignore<string>
let makeProc =
Process.Execute(
{
Command = "make"
Arguments = String.Empty
},
Echo.All
)
match makeProc.Result with
| Error _ ->
Console.WriteLine()
Console.Out.Flush()
failwith "Compilation failed"
| _ -> ()
Directory.SetCurrentDirectory prevCurrentDir
FindFsxc true
elif findFsxcExeFiles().Count() > 1 then
Console.Error.WriteLine(
sprintf
"More than one %s file found (%s), please just leave one"
fsxCompiler
(String.Join(", ", findFsxcExeFiles()))
)
Environment.Exit 1
failwith "Unreachable"
else
nestedCall, findFsxcExeFiles().Single() |> FileInfo
let compilationWasNeeded, fsxLocation = FindFsxc false
Console.WriteLine("Checking if all .fsx scripts build")
let fsxScripts =
Directory.GetFiles(
Directory.GetCurrentDirectory(),
"*.fsx",
SearchOption.AllDirectories
)
let buildFsxScript (script: string) (soFar: bool) : bool =
if (script = null) then
raise <| ArgumentNullException("script")
Console.WriteLine(sprintf "Building %s" script)
let proc =
Process.Execute(
{
#if !LEGACY_FRAMEWORK
Command = "dotnet"
Arguments = sprintf "%s -k %s" fsxLocation.FullName script
#else
Command = fsxLocation.FullName
Arguments = sprintf "-k %s" script
#endif
},
Echo.OutputOnly
)
let success =
match proc.Result with
| Success _ -> true
| WarningsOrAmbiguous output ->
output.PrintToConsole()
Console.WriteLine()
Console.Out.Flush()
failwith "Unexpected 'fsx' output ^ (with warnings?)"
| _ -> false
Console.WriteLine()
(success && soFar)
let rec buildAll (scripts: list<string>) (soFar: bool) : bool =
match scripts with
| [] -> soFar
| script :: tail ->
let scriptFile = FileInfo script
let binFolder =
sprintf
"%c%s%c"
Path.DirectorySeparatorChar
"bin"
Path.DirectorySeparatorChar
let skip =
// if compilation was needed, it's likely we are running under a
// repo which is not fsx itself, so we don't want to compile fsx's
// test scripts (because they have dependencies)
if compilationWasNeeded
&& scriptFile.Directory.FullName = fsxTestsDir.FullName then
true
elif scriptFile.FullName.Contains binFolder then
true
else
#if !LEGACY_FRAMEWORK
scriptFile.FullName.EndsWith "testLegacyFx.fsx"
#else
scriptFile.FullName.EndsWith "testNonLegacyFx.fsx"
#endif
if skip then
Console.WriteLine(sprintf "Skipping %s" script)
buildAll tail soFar
else
let sofarPlusOne = buildFsxScript script soFar
buildAll tail sofarPlusOne
let scripts = List.ofArray fsxScripts
let allCompile = buildAll scripts true
if allCompile then
Console.WriteLine("Success")
Environment.Exit(0)
else
Console.WriteLine("Some script(s) had errors")
Environment.Exit(1)