-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.fsx
207 lines (174 loc) · 6.04 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#r "Dependencies/NuGet/FAKE.3.5.8/tools/FakeLib.dll"
#r "Dependencies/NuGet/YamlDotNet.3.3.0/lib/net35/YamlDotNet.dll"
open System.IO
open System.Collections.Generic
open Fake
open YamlDotNet.RepresentationModel
// Properties
let config = (
// TODO: Clean this up
// * Cleaner checking of which file to use
// * Deserialize the file to an object
let mutable configFile = null
if File.Exists("build.yml") then
configFile <- "build.yml"
else if File.Exists("../Ketchup.build.yml") then
configFile <- "../Ketchup.build.yml"
if configFile = null then
new YamlStream()
else (
let yaml = new YamlStream()
yaml.Load(new StringReader(ReadFileAsString configFile))
yaml
)
)
let kspDir = lazy (
if config.Documents.Count = 0 then
raise (System.Exception("ksp_dir not specified in configuration"))
else (
let mapping = config.Documents.[0].RootNode :?> YamlMappingNode
let node = new YamlScalarNode("ksp_dir")
if mapping.Children.ContainsKey(node) then
mapping.Children.[node].ToString()
else
raise (System.Exception("ksp_dir not specified in configuration"))
)
)
let kspExe = lazy (
if config.Documents.Count = 0 then
"KSP.exe"
else (
let mapping = config.Documents.[0].RootNode :?> YamlMappingNode
let node = new YamlScalarNode("ksp_exe")
if mapping.Children.ContainsKey(node) then
mapping.Children.[node].ToString()
else
"KSP.exe"
)
)
let kspProfile = lazy (
if config.Documents.Count = 0 then
raise (System.Exception("profile not specified in configuration"))
else (
let mapping = config.Documents.[0].RootNode :?> YamlMappingNode
let node = new YamlScalarNode("profile")
if mapping.Children.ContainsKey(node) then
mapping.Children.[node].ToString()
else
raise (System.Exception("profile not specified in configuration"))
)
)
let kspDeployName = "Ketchup"
let kspDepDir = lazy (kspDir.Force() + "/KSP_Data/Managed")
let kspDeployDir = lazy (kspDir.Force() + "/GameData/" + kspDeployName)
let kspFirmwareDir = lazy (kspDir.Force() + "/saves/" + kspProfile.Force() + "/Ketchup/Firmware")
let kspLocalDepDir = "./Dependencies/KSP"
let kspAssemblies = ["Assembly-CSharp.dll"; "Assembly-CSharp-firstpass.dll"; "UnityEngine.dll"]
let artworkDir = "./Dependencies/NuGet/Apokee.Artwork.0.1.0.1/Content" // TODO: make this dynamic
let contribDir = "./Contrib"
let partsDir = "./Parts"
let patchesDir = "./Patches"
let outputDir = "./Output"
let buildDir = outputDir + "/Build"
let testDir = outputDir + "/Test"
let stageDir = outputDir + "/Stage/GameData"
let stageModDir = outputDir + "/Stage/GameData/" + kspDeployName
let packageDir = outputDir + "/Package"
let contribBuildDir = outputDir + "/Contrib"
let buildConfig = getBuildParamOrDefault "Configuration" "Debug"
MSBuildDefaults <- MSBuildDefaults |> (fun p ->
{ p with
Verbosity = Some(Minimal)
Properties = []
}
)
// Targets
Target "Default" (fun _ ->
trace "Default Target"
)
Target "Init" (fun _ ->
if not (TestDir kspLocalDepDir) then (
CreateDir kspLocalDepDir
)
kspAssemblies |> List.choose (fun a ->
match a with
| a when not (System.IO.File.Exists (kspLocalDepDir + "/" + a)) -> Some(kspDepDir.Force() + "/" + a)
| _ -> None
) |> Copy kspLocalDepDir
)
Target "BuildMod" (fun _ ->
!! "Source/**/*.csproj"
|> MSBuild (buildDir + "/" + buildConfig) "Build" ["Configuration", buildConfig]
|> ignore
)
Target "BuildTest" (fun _ ->
!! "Tests/**/*.csproj"
|> MSBuildDebug testDir "Build"
|> ignore
)
Target "BuildContrib" (fun _ ->
!! "Contrib/**/*.dasm"
|> Seq.iter (fun f ->
ExecProcess (fun psi ->
psi.FileName <- "Dependencies/Organic/Organic.exe"
psi.Arguments <- f + " " + contribBuildDir + "/" + (new FileInfo(f)).Name.Replace(".dasm", ".bin")
) (System.TimeSpan.FromSeconds 30.0) |> ignore
)
)
Target "Test" (fun _ ->
!! (testDir + "/*.Tests.dll")
|> xUnit (fun p ->
p
)
)
Target "Stage" (fun _ ->
CleanDir stageModDir
CopyFile stageModDir "./LICENSE"
CopyDir (stageModDir + "/Contrib") contribDir (fun f -> true)
CopyDir (stageModDir + "/Parts") partsDir (fun f -> true)
CopyDir (stageModDir + "/Patches") patchesDir (fun f -> true)
CopyDir (stageModDir + "/Plugins") (buildDir + "/" + buildConfig) (fun f -> true)
CleanDir (stageModDir + "/Textures")
CopyFile (stageModDir + "/Textures/AppLauncher.png") (artworkDir + "/logo-ketchup-38x38-white.png")
)
Target "Deploy" (fun _ ->
CleanDir (kspDeployDir.Force())
CleanDir (kspFirmwareDir.Force())
CopyDir (kspDeployDir.Force()) stageModDir (fun f -> true)
CopyDir (kspFirmwareDir.Force()) contribBuildDir (fun f -> true)
)
Target "Run" (fun _ ->
// TODO: Needs to be executed with Mono on Unix-like systems
// TODO: this should be asynchronous but FAKE kills the process if you use StartProcess
ExecProcess (fun psi ->
psi.FileName <- kspDir.Force() + "/" + kspExe.Force()
psi.WorkingDirectory <- kspDir.Force()
) (System.TimeSpan.FromMinutes 60.0) |> ignore
)
Target "Package" (fun _ ->
// TODO: assert that this has a value
let version = getBuildParam "Version"
CreateDir packageDir
!! (stageDir + "/**/*.*")
|> Zip (stageDir + "/..") (packageDir + "/Ketchup-" + version + ".zip")
)
Target "Clean" (fun _ ->
CleanDir outputDir
)
// Dependencies
"Init"
==> "Clean"
==> "BuildMod"
==> "BuildTest"
==> "Default"
"Default"
==> "Test"
==> "Stage"
"Stage"
==> "BuildContrib"
==> "Deploy"
==> "Run"
"Stage"
==> "Package"
// Start
RunTargetOrDefault "Default"