This repository has been archived by the owner on Feb 7, 2022. It is now read-only.
forked from BepInEx/BepInEx
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.cake
285 lines (232 loc) · 12.3 KB
/
build.cake
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#addin nuget:?package=Cake.FileHelpers&version=3.3.0
#addin nuget:?package=SharpZipLib&version=1.3.0
#addin nuget:?package=Cake.Compression&version=0.2.4
#addin nuget:?package=Cake.Json&version=5.2.0
#addin nuget:?package=Newtonsoft.Json&version=12.0.3
var target = Argument("target", "Build");
var isBleedingEdge = Argument("bleeding_edge", false);
var buildId = Argument("build_id", 0);
var lastBuildCommit = Argument("last_build_commit", "");
var buildVersion = "";
var currentCommit = RunGit("rev-parse HEAD");
var currentCommitShort = RunGit("log -n 1 --pretty=\"format:%h\"").Trim();
var currentBranch = RunGit("rev-parse --abbrev-ref HEAD");
var latestTag = RunGit("describe --tags --abbrev=0");
string RunGit(string command, string separator = "")
{
using(var process = StartAndReturnProcess("git", new ProcessSettings { Arguments = command, RedirectStandardOutput = true }))
{
process.WaitForExit();
return string.Join(separator, process.GetStandardOutput());
}
}
Task("Cleanup")
.Does(() =>
{
Information("Removing old binaries");
CreateDirectory("./bin");
CleanDirectory("./bin");
Information("Cleaning up old build objects");
CleanDirectories(GetDirectories("./**/bin/"));
CleanDirectories(GetDirectories("./**/obj/"));
});
Task("PullDependencies")
.Does(() =>
{
Information("Updating git submodules");
StartProcess("git", "submodule update --init --recursive");
Information("Restoring NuGet packages");
NuGetRestore("./BepInEx.sln");
});
Task("Build")
.IsDependentOn("Cleanup")
.IsDependentOn("PullDependencies")
.Does(() =>
{
var bepinExProperties = Directory("./BepInEx.Shared");
buildVersion = FindRegexMatchGroupInFile(bepinExProperties + File("BepInEx.Shared.projitems"), @"\<Version\>([0-9]+\.[0-9]+\.[0-9]+)\<\/Version\>", 1, System.Text.RegularExpressions.RegexOptions.None).Value;
var buildSettings = new MSBuildSettings {
Configuration = "Release",
Restore = true
};
if (isBleedingEdge)
{
buildSettings.Properties["BuildInfo"] = new[] {
TransformText("BLEEDING EDGE Build #<%buildNumber%> from <%shortCommit%> at <%branchName%>")
.WithToken("buildNumber", buildId)
.WithToken("shortCommit", currentCommit)
.WithToken("branchName", currentBranch)
.ToString()
};
buildSettings.Properties["AssemblyVersion"] = new[] { buildVersion + "." + buildId };
buildVersion += "-be." + buildId;
buildSettings.Properties["Version"] = new[] { buildVersion };
}
//buildSettings.Properties["TargetFrameworks"] = new []{ "net35" };
MSBuild("./BepInEx.Unity/BepInEx.Unity.csproj", buildSettings);
//buildSettings.Properties["TargetFrameworks"] = new []{ "net452" };
MSBuild("./BepInEx.NetLauncher/BepInEx.NetLauncher.csproj", buildSettings);
//buildSettings.Properties["TargetFrameworks"] = new []{ "net472" };
MSBuild("./BepInEx.IL2CPP/BepInEx.IL2CPP.csproj", buildSettings);
});
const string DOORSTOP_VER_WIN = "3.1.0.0";
const string DOORSTOP_VER_UNIX = "1.3.0.0";
const string MONO_VER = "2020.11.08";
const string DOORSTOP_DLL = "winhttp.dll";
Task("DownloadDependencies")
.Does(() =>
{
Information("Downloading Doorstop");
var doorstopPath = Directory("./bin/doorstop");
var doorstopX64Path = doorstopPath + File("doorstop_x64.zip");
var doorstopX86Path = doorstopPath + File("doorstop_x86.zip");
var doorstopLinuxPath = doorstopPath + File("doorstop_linux.zip");
var doorstopMacPath = doorstopPath + File("doorstop_macos.zip");
CreateDirectory(doorstopPath);
DownloadFile($"https://github.com/NeighTools/UnityDoorstop/releases/download/v{DOORSTOP_VER_WIN}/Doorstop_x64_{DOORSTOP_VER_WIN}.zip", doorstopX64Path);
DownloadFile($"https://github.com/NeighTools/UnityDoorstop/releases/download/v{DOORSTOP_VER_WIN}/Doorstop_x86_{DOORSTOP_VER_WIN}.zip", doorstopX86Path);
DownloadFile($"https://github.com/NeighTools/UnityDoorstop.Unix/releases/download/v{DOORSTOP_VER_UNIX}/doorstop_v{DOORSTOP_VER_UNIX}_linux.zip", doorstopLinuxPath);
DownloadFile($"https://github.com/NeighTools/UnityDoorstop.Unix/releases/download/v{DOORSTOP_VER_UNIX}/doorstop_v{DOORSTOP_VER_UNIX}_macos.zip", doorstopMacPath);
Information("Extracting Doorstop");
ZipUncompress(doorstopX86Path, doorstopPath + Directory("x86"));
ZipUncompress(doorstopX64Path, doorstopPath + Directory("x64"));
ZipUncompress(doorstopLinuxPath, doorstopPath + Directory("unix"));
ZipUncompress(doorstopMacPath, doorstopPath + Directory("unix"));
Information("Downloading Mono");
var monoPath = Directory("./bin/doorstop/mono");
var monoX64Path = doorstopPath + File("mono_x64.zip");
var monoX86Path = doorstopPath + File("mono_x86.zip");
CreateDirectory(monoPath);
DownloadFile($"https://github.com/BepInEx/mono/releases/download/{MONO_VER}/mono-x64.zip", monoX64Path);
DownloadFile($"https://github.com/BepInEx/mono/releases/download/{MONO_VER}/mono-x86.zip", monoX86Path);
Information("Extracting Mono");
ZipUncompress(monoX64Path, monoPath + Directory("x64"));
ZipUncompress(monoX86Path, monoPath + Directory("x86"));
});
Task("MakeDist")
.IsDependentOn("Build")
.IsDependentOn("DownloadDependencies")
.Does(() =>
{
var distDir = Directory("./bin/dist");
//var distPatcherDir = distDir + Directory("patcher");
var doorstopPath = Directory("./bin/doorstop");
CreateDirectory(distDir);
//CreateDirectory(distPatcherDir);
var changelog = TransformText("<%commit_count%> commits since <%last_tag%>\r\n\r\nChangelog (excluding merges):\r\n<%commit_log%>")
.WithToken("commit_count", RunGit($"rev-list --count {latestTag}..HEAD"))
.WithToken("last_tag", latestTag)
.WithToken("commit_log", RunGit($"--no-pager log --no-merges --pretty=\"format:* (%h) [%an] %s\" {latestTag}..HEAD", "\r\n"))
.ToString();
void PackageBepin(string platform, string arch, string originDir, string doorstopConfigFile = null, bool copyMono = false)
{
string platformName = platform + (arch == null ? "" : "_" + arch);
bool isUnix = arch == "unix";
Information("Creating distributions for platform \"" + platformName + "\"...");
string doorstopArchPath = null;
if (arch != null)
{
doorstopArchPath = doorstopPath + Directory(arch)
+ File(isUnix ? "*.*" : DOORSTOP_DLL);
}
var distArchDir = distDir + Directory(platformName);
var bepinDir = distArchDir + Directory("BepInEx");
var doorstopDir = distArchDir;
if (isUnix) doorstopDir += Directory("doorstop_libs");
CreateDirectory(distArchDir);
CreateDirectory(doorstopDir);
CreateDirectory(bepinDir + Directory("core"));
CreateDirectory(bepinDir + Directory("plugins"));
CreateDirectory(bepinDir + Directory("patchers"));
if (doorstopArchPath != null)
{
CopyFile("./doorstop/" + doorstopConfigFile, Directory(distArchDir) + File(isUnix ? "run_bepinex.sh" : "doorstop_config.ini"));
CopyFiles(doorstopArchPath, doorstopDir);
if (isUnix)
{
ReplaceTextInFiles($"{distArchDir}/run_bepinex.sh", "\r\n", "\n");
}
if (copyMono)
{
CopyDirectory("./bin/doorstop/mono/" + arch + "/mono", Directory(distArchDir) + Directory("mono"));
}
}
CopyFiles("./bin/" + Directory(originDir) + "/*.*", Directory(bepinDir) + Directory("core"));
FileWriteText(distArchDir + File("changelog.txt"), changelog);
if (platform == "NetLauncher")
{
DeleteFile(Directory(bepinDir) + Directory("core") + File("BepInEx.NetLauncher.exe.config"));
MoveFiles(Directory(bepinDir) + Directory("core") + File("BepInEx.NetLauncher.*"), Directory(distArchDir));
}
}
PackageBepin("UnityMono", "x86", "Unity", "doorstop_config_mono.ini");
PackageBepin("UnityMono", "x64", "Unity", "doorstop_config_mono.ini");
PackageBepin("UnityMono", "unix", "Unity", "run_bepinex.sh");
PackageBepin("UnityIL2CPP", "x86", "IL2CPP", "doorstop_config_il2cpp.ini", copyMono: true);
PackageBepin("UnityIL2CPP", "x64", "IL2CPP", "doorstop_config_il2cpp.ini", copyMono: true);
PackageBepin("NetLauncher", null, "NetLauncher");
//CopyFileToDirectory(File("./bin/patcher/BepInEx.Patcher.exe"), distPatcherDir);
});
Task("Pack")
.IsDependentOn("MakeDist")
.Does(() =>
{
var distDir = Directory("./bin/dist");
var commitPrefix = isBleedingEdge ? $"_{currentCommitShort}_" : "_";
Information("Packing BepInEx");
ZipCompress(distDir + Directory("UnityMono_x86"), distDir + File($"BepInEx_UnityMono_x86{commitPrefix}{buildVersion}.zip"));
ZipCompress(distDir + Directory("UnityMono_x64"), distDir + File($"BepInEx_UnityMono_x64{commitPrefix}{buildVersion}.zip"));
ZipCompress(distDir + Directory("UnityMono_unix"), distDir + File($"BepInEx_UnityMono_unix{commitPrefix}{buildVersion}.zip"));
ZipCompress(distDir + Directory("UnityIL2CPP_x86"), distDir + File($"BepInEx_UnityIL2CPP_x86{commitPrefix}{buildVersion}.zip"));
ZipCompress(distDir + Directory("UnityIL2CPP_x64"), distDir + File($"BepInEx_UnityIL2CPP_x64{commitPrefix}{buildVersion}.zip"));
ZipCompress(distDir + Directory("NetLauncher"), distDir + File($"BepInEx_NetLauncher{commitPrefix}{buildVersion}.zip"));
// Information("Packing BepInEx.Patcher");
// ZipCompress(distDir + Directory("patcher"), distDir + File($"BepInEx_Patcher{commitPrefix}{buildVersion}.zip"));
if(isBleedingEdge)
{
var changelog = "";
if(!string.IsNullOrEmpty(lastBuildCommit)) {
changelog = TransformText("<ul><%changelog%></ul>")
.WithToken("changelog", RunGit($"--no-pager log --no-merges --pretty=\"format:<li>(<code>%h</code>) [%an] %s</li>\" {lastBuildCommit}..HEAD"))
.ToString();
}
FileWriteText(distDir + File("info.json"),
SerializeJsonPretty(new Dictionary<string, object>{
["id"] = buildId.ToString(),
["date"] = DateTime.Now.ToString("o"),
["changelog"] = changelog,
["hash"] = currentCommit,
["artifacts"] = new Dictionary<string, object>[] {
new Dictionary<string, object> {
["file"] = $"BepInEx_UnityMono_x64{commitPrefix}{buildVersion}.zip",
["description"] = "BepInEx Unity Mono for Windows x64 machines"
},
new Dictionary<string, object> {
["file"] = $"BepInEx_UnityMono_x86{commitPrefix}{buildVersion}.zip",
["description"] = "BepInEx Unity Mono for Windows x86 machines"
},
new Dictionary<string, object> {
["file"] = $"BepInEx_unix{commitPrefix}{buildVersion}.zip",
["description"] = "BepInEx Unity Mono for Unix machines with GCC (Linux, MacOS)"
},
new Dictionary<string, object> {
["file"] = $"BepInEx_UnityIL2CPP_x64{commitPrefix}{buildVersion}.zip",
["description"] = "BepInEx Unity IL2CPP for Windows x64 machines"
},
new Dictionary<string, object> {
["file"] = $"BepInEx_UnityIL2CPP_x86{commitPrefix}{buildVersion}.zip",
["description"] = "BepInEx Unity IL2CPP for Windows x86 machines"
},
new Dictionary<string, object> {
["file"] = $"BepInEx_NetLauncher{commitPrefix}{buildVersion}.zip",
["description"] = "BepInEx .NET Launcher for .NET Framework/XNA games"
},
// new Dictionary<string, object> {
// ["file"] = $"BepInEx_Patcher{commitPrefix}{buildVersion}.zip",
// ["description"] = "Hardpatcher for BepInEx. IMPORTANT: USE ONLY IF DOORSTOP DOES NOT WORK FOR SOME REASON!"
// }
}
}));
}
});
RunTarget(target);