-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbuild.cake
More file actions
204 lines (170 loc) · 5.64 KB
/
build.cake
File metadata and controls
204 lines (170 loc) · 5.64 KB
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
/**
* just a script to automate the publish process (cus i also need to copy assets and data and stuff)
*/
#addin nuget:?package=SharpZipLib&version=1.4.2
#addin nuget:?package=Cake.Compression&version=0.3.0
using System.IO;
using System.Linq;
using Path = System.IO.Path;
var target = Argument("Target", "Build");
var os = Argument("OS", System.Runtime.InteropServices.RuntimeInformation.RuntimeIdentifier);
var buildDir = "build_" + os;
var useGles = Argument<bool>("GLES", os == "win-x64");
var programFilesPath = Argument<string>("program-files", null);
var userFilesPath = Argument<string>("user-files", null);
List<string> ExecCapture(string procName, System.Collections.Generic.IEnumerable<string> args)
{
Verbose(procName + " " + string.Join(' ', args));
using var proc = StartAndReturnProcess(procName, new ProcessSettings()
{
Arguments = ProcessArgumentBuilder.FromStringsQuoted(args),
RedirectStandardOutput = true,
RedirectStandardError = true
});
proc.WaitForExit();
var output = new List<string>();
foreach (var str in proc.GetStandardOutput())
output.Add(str);
var code = proc.GetExitCode();
if (code != 0)
throw new Exception($"{procName} returned {code}");
return output;
}
void Exec(string procName, System.Collections.Generic.IEnumerable<string> args)
{
Verbose(procName + " " + string.Join(' ', args));
using var proc = StartAndReturnProcess(procName, new ProcessSettings()
{
Arguments = ProcessArgumentBuilder.FromStringsQuoted(args)
});
proc.WaitForExit();
var code = proc.GetExitCode();
if (code != 0)
throw new Exception($"{procName} returned {code}");
}
enum ShaderType { Vertex, Fragment }
Task("Build Shaders")
.Does(() =>
{
bool hasPython3 = false;
string pythonExec = "python3";
try
{
ExecCapture("python3", ["--version"]);
hasPython3 = true;
}
catch
{
try
{
pythonExec = "python";
foreach (var line in ExecCapture("python", ["--version"]))
{
if (line[0..8] == "Python 3")
{
hasPython3 = true;
break;
}
}
}
catch
{
hasPython3 = false;
}
}
if (!hasPython3)
{
Information("Could not find python3!");
Information("Shader preprocessing/validation skipped.");
return;
}
string glslang = EnvironmentVariable<string>("GLSL_VALIDATOR", "glslangValidator");
bool hasGlslang = false;
try
{
ExecCapture(glslang, ["-v"]);
hasGlslang = true;
}
catch
{
hasGlslang = false;
}
if (!hasGlslang)
{
Information("Could not find glslangValidator! Make sure it is in your PATH or the GLSL_VALIDATOR environment variable is set.");
Information("Shader preprocessing/validation skipped.");
return;
}
Exec(pythonExec, ["tools/shader-preprocessor.py", "gles300"]);
Exec(pythonExec, ["tools/shader-preprocessor.py", "gl330"]);
});
Task("Build")
.IsDependentOn("Build Shaders")
.Does(() =>
{
DotNetMSBuildSettings msBuildSettings = new DotNetMSBuildSettings();
if (useGles)
msBuildSettings.Properties.Add("GL", ["ES"]); // use ANGLE
else
msBuildSettings.Properties.Add("GL", ["Desktop"]); // use desktop GL
var buildSettings = new DotNetBuildSettings()
{
MSBuildSettings = msBuildSettings
};
var config = Argument("Configuration", "Debug");
if (config != "Debug") buildSettings.Configuration = config;
if (programFilesPath is not null)
msBuildSettings.Properties.Add("ProgramFilesPath", [programFilesPath]);
if (userFilesPath is not null)
msBuildSettings.Properties.Add("UserFilesPath", [userFilesPath]);
DotNetBuild("src/Rained/Rained.csproj", buildSettings);
});
Task("DotNetPublish")
.IsDependentOn("Build Shaders")
.Does(() =>
{
EnsureDirectoryExists(buildDir);
CleanDirectory(buildDir);
DotNetMSBuildSettings buildSettings = new DotNetMSBuildSettings();
buildSettings.Properties.Add("ProgramFilesPath", [programFilesPath ?? "[asm]"]);
buildSettings.Properties.Add("UserFilesPath", [userFilesPath ?? "[asm]"]);
if (HasArgument("full-release"))
buildSettings.Properties.Add("FullRelease", ["true"]);
if (useGles)
buildSettings.Properties.Add("GL", ["ES"]); // use ANGLE
else
buildSettings.Properties.Add("GL", ["Desktop"]); // use desktop GL
DotNetPublish("src/Rained/Rained.csproj", new DotNetPublishSettings
{
SelfContained = true,
OutputDirectory = buildDir,
Runtime = os,
MSBuildSettings = buildSettings
});
CreateDirectory(buildDir + "/assets");
CopyDirectory("assets", buildDir + "/assets");
CopyDirectory("scripts", buildDir + "/scripts");
CopyDirectory("config", buildDir + "/config");
CopyFile("LICENSE.md", buildDir + "/LICENSE.md");
CopyFile("CREDITS.md", buildDir + "/CREDITS.md");
if (FileExists(buildDir + "/config/preferences.json"))
{
DeleteFile(buildDir + "/config/preferences.json");
}
CopyDirectory("dist", buildDir);
// only keep console wrapper if building for Windows
if (os != "win-x64" && FileExists(buildDir + "/Rained.Console.exe"))
{
DeleteFile(buildDir + "/Rained.Console.exe");
}
});
Task("Package")
.IsDependentOn("DotNetPublish")
.Does(() =>
{
if (os == "linux-x64")
GZipCompress(buildDir, $"rained_{os}.tar.gz");
else
Zip(buildDir, $"rained_{os}.zip");
});
RunTarget(target);