forked from OpenRA/ra2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
124 lines (102 loc) · 4.08 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
// OS X: brew install cake
// Windows: choco install cake.portable
//
// Example:
// cake -auto=true -openra-root=~/projects/openra
var target = Argument("target", "default").ToLowerInvariant();
var configuration = Argument("configuration", "Debug");
var rootDir = Directory(".");
var depsDir = Directory("./OpenRA.Mods.RA2/dependencies");
// TODO: Combine 'deps' and 'depsInOpenRA' into an array of pairs/structs
var deps = new[] {
"Eluant.dll",
"OpenRA.Game.exe",
"OpenRA.Mods.Common.dll",
"OpenRA.Mods.RA.dll",
"OpenRA.Mods.TS.dll"
};
var depsInOpenRA = new[] {
"Eluant.dll",
"OpenRA.Game.exe",
"mods/common/OpenRA.Mods.Common.dll",
"mods/ra/OpenRA.Mods.RA.dll",
"mods/ts/OpenRA.Mods.TS.dll"
};
// Location on-disk of the OpenRA source code.
var openraRoot = Argument<string>("openra-root", null);
// Should dependencies be automatically copied (if found in openraRoot)?
var auto = Argument<bool>("auto", false);
Task("deps").Does(() => {
var missingDeps = new List<string>();
foreach (var dep in deps)
{
var fullPath = System.IO.Path.Combine(depsDir.Path.FullPath, dep);
if (!System.IO.File.Exists(fullPath))
missingDeps.Add(dep);
}
if (!missingDeps.Any())
{
Information("All dependencies accounted for. Aborting 'deps' task.");
return;
}
// Steps to resolving dependency location:
// 1) environment variable OPENRA_ROOT
// 2) -openra-root=<path> command-line argument
// 3) Ask the user for the path (only if `auto` is false!)
if (string.IsNullOrWhiteSpace(openraRoot))
openraRoot = Environment.GetEnvironmentVariable("OPENRA_ROOT");
if (!auto && string.IsNullOrWhiteSpace(openraRoot))
{
Console.Write("Please enter the path to the OpenRA root: ");
openraRoot = Console.ReadLine();
}
if (openraRoot.StartsWith("~"))
openraRoot = openraRoot.Replace("~", IsRunningOnWindows() ?
Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%") :
Environment.GetEnvironmentVariable("HOME"));
var missingDepsCopy = missingDeps.ToArray();
for (var i = 0; i < missingDepsCopy.Length; i++)
{
var dep = missingDepsCopy[i];
var depPathInOpenRA = depsInOpenRA[i];
var depPath = System.IO.Path.Combine(depsDir.Path.FullPath, dep);
var oraPath = System.IO.Path.Combine(openraRoot, depPathInOpenRA);
if (!System.IO.File.Exists(oraPath))
Error(string.Format("Could not automatically resolve missing dependency '{0}'.", dep));
else
{
if (!auto)
{
Console.Write(string.Format("Would you like to copy {0} to {1}? [Y/n] ", oraPath, depPath));
var input = Console.ReadLine().ToLowerInvariant();
if (!string.IsNullOrWhiteSpace(input) && input != "y" && input != "yes")
continue;
}
System.IO.File.Copy(oraPath, depPath, true);
if (System.IO.File.Exists(depPath))
missingDeps.Remove(dep);
}
}
if (missingDeps.Any())
throw new Exception(string.Format("Missing {0} dependencies.", missingDeps.Count));
});
Task("default")
.IsDependentOn("deps")
.Does(() => {
if (IsRunningOnWindows())
MSBuild("./OpenRA.Mods.RA2/OpenRA.Mods.RA2.sln", settings => settings.SetConfiguration(configuration));
else
XBuild("./OpenRA.Mods.RA2/OpenRA.Mods.RA2.sln", settings => settings.SetConfiguration(configuration));
System.IO.File.Copy("./OpenRA.Mods.RA2/bin/Debug/OpenRA.Mods.RA2.dll", "./OpenRA.Mods.RA2.dll", true);
});
Task("clean").Does(() => {
DeleteFiles("./OpenRA.Mods.RA2/bin/*/*.dll");
DeleteFiles("./OpenRA.Mods.RA2/bin/*/*.exe");
DeleteFiles("./OpenRA.Mods.RA2/obj/*/*.dll");
DeleteFiles("./OpenRA.Mods.RA2/obj/*/*.exe");
DeleteFiles("./OpenRA.Mods.RA2/dependencies/*.exe");
DeleteFiles("./OpenRA.Mods.RA2/dependencies/*.dll");
if (FileExists("./OpenRA.Mods.RA2.dll"))
DeleteFile("./OpenRA.Mods.RA2.dll");
});
RunTarget(target);