forked from OpenRA/OpenRA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.ps1
273 lines (242 loc) · 7.72 KB
/
make.ps1
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
####### The starting point for the script is the bottom #######
###############################################################
########################## FUNCTIONS ##########################
###############################################################
function All-Command
{
if ((CheckForDotnet) -eq 1)
{
return
}
Write-Host "Building in" $configuration "configuration..." -ForegroundColor Cyan
dotnet build -c $configuration --nologo -p:TargetPlatform=win-x64
if ($lastexitcode -ne 0)
{
Write-Host "Build failed. If just the development tools failed to build, try installing Visual Studio. You may also still be able to run the game." -ForegroundColor Red
}
else
{
Write-Host "Build succeeded." -ForegroundColor Green
}
if (!(Test-Path "IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP") -Or (((get-date) - (get-item "IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP").LastWriteTime) -gt (new-timespan -days 30)))
{
echo "Downloading IP2Location GeoIP database."
$target = Join-Path $pwd.ToString() "IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP"
[Net.ServicePointManager]::SecurityProtocol = 'Tls12'
(New-Object System.Net.WebClient).DownloadFile("https://github.com/OpenRA/GeoIP-Database/releases/download/monthly/IP2LOCATION-LITE-DB1.IPV6.BIN.ZIP", $target)
}
}
function Clean-Command
{
if ((CheckForDotnet) -eq 1)
{
return
}
dotnet clean /nologo
Remove-Item ./bin -Recurse -ErrorAction Ignore
Remove-Item ./*/obj -Recurse -ErrorAction Ignore
Write-Host "Clean complete." -ForegroundColor Green
}
function Version-Command
{
if ($command.Length -gt 1)
{
$version = $command[1]
}
elseif (Get-Command 'git' -ErrorAction SilentlyContinue)
{
$gitRepo = git rev-parse --is-inside-work-tree
if ($gitRepo)
{
$version = git name-rev --name-only --tags --no-undefined HEAD 2>$null
if ($version -eq $null)
{
$version = "git-" + (git rev-parse --short HEAD)
}
}
else
{
Write-Host "Not a git repository. The version will remain unchanged." -ForegroundColor Red
}
}
else
{
Write-Host "Unable to locate Git. The version will remain unchanged." -ForegroundColor Red
}
if ($version -ne $null)
{
$version | out-file ".\VERSION"
$mods = Get-ChildItem ./mods/*/mod.yaml | Select-Object -Expand FullName
foreach ($mod in $mods)
{
$replacement = (gc $mod) -Replace "Version:.*", ("Version: {0}" -f $version)
sc $mod $replacement
$prefix = $(gc $mod) | Where { $_.ToString().EndsWith(": User") }
if ($prefix -and $prefix.LastIndexOf("/") -ne -1)
{
$prefix = $prefix.Substring(0, $prefix.LastIndexOf("/"))
}
$replacement = (gc $mod) -Replace ".*: User", ("{0}/{1}: User" -f $prefix, $version)
sc $mod $replacement
}
Write-Host ("Version strings set to '{0}'." -f $version)
}
}
function Test-Command
{
if ((CheckForUtility) -eq 1)
{
return
}
Write-Host "Testing mods..." -ForegroundColor Cyan
Write-Host "Testing Tiberian Sun mod MiniYAML..." -ForegroundColor Cyan
InvokeCommand "$utilityPath ts --check-yaml"
Write-Host "Testing Dune 2000 mod MiniYAML..." -ForegroundColor Cyan
InvokeCommand "$utilityPath d2k --check-yaml"
Write-Host "Testing Tiberian Dawn mod MiniYAML..." -ForegroundColor Cyan
InvokeCommand "$utilityPath cnc --check-yaml"
Write-Host "Testing Red Alert mod MiniYAML..." -ForegroundColor Cyan
InvokeCommand "$utilityPath ra --check-yaml"
}
function Tests-Command
{
Write-Host "Running unit tests..." -ForegroundColor Cyan
dotnet build OpenRA.Test\OpenRA.Test.csproj -c Debug --nologo -p:TargetPlatform=win-x64
dotnet test bin\OpenRA.Test.dll --test-adapter-path:.
}
function Check-Command
{
Write-Host "Compiling in Debug configuration..." -ForegroundColor Cyan
dotnet clean -c Debug --nologo --verbosity minimal
dotnet build -c Debug --nologo -warnaserror -p:TargetPlatform=win-x64
if ($lastexitcode -ne 0)
{
Write-Host "Build failed." -ForegroundColor Red
}
if ((CheckForUtility) -eq 0)
{
Write-Host "Checking for explicit interface violations..." -ForegroundColor Cyan
InvokeCommand "$utilityPath all --check-explicit-interfaces"
Write-Host "Checking for incorrect conditional trait interface overrides..." -ForegroundColor Cyan
InvokeCommand "$utilityPath all --check-conditional-trait-interface-overrides"
}
}
function Check-Scripts-Command
{
if ((Get-Command "luac.exe" -ErrorAction SilentlyContinue) -ne $null)
{
Write-Host "Testing Lua scripts..." -ForegroundColor Cyan
foreach ($script in ls "mods/*/maps/*/*.lua")
{
luac -p $script
}
foreach ($script in ls "mods/*/scripts/*.lua")
{
luac -p $script
}
Write-Host "Check completed!" -ForegroundColor Green
}
else
{
Write-Host "luac.exe could not be found. Please install Lua." -ForegroundColor Red
}
}
function CheckForUtility
{
if (Test-Path $utilityPath)
{
return 0
}
Write-Host "OpenRA.Utility.exe could not be found. Build the project first using the `"all`" command." -ForegroundColor Red
return 1
}
function CheckForDotnet
{
if ((Get-Command "dotnet" -ErrorAction SilentlyContinue) -eq $null)
{
Write-Host "The 'dotnet' tool is required to compile OpenRA. Please install the .NET Core SDK or Visual Studio and try again. https://dotnet.microsoft.com/download" -ForegroundColor Red
return 1
}
return 0
}
function WaitForInput
{
Write-Host "Press enter to continue."
while ($true)
{
if ([System.Console]::KeyAvailable)
{
exit
}
Start-Sleep -Milliseconds 50
}
}
function InvokeCommand
{
param($expression)
# $? is the return value of the called expression
# Invoke-Expression itself will always succeed, even if the invoked expression fails
# So temporarily store the return value in $success
$expression += '; $success = $?'
Invoke-Expression $expression
if ($success -eq $False)
{
exit 1
}
}
###############################################################
############################ Main #############################
###############################################################
if ($PSVersionTable.PSVersion.Major -clt 3)
{
Write-Host "The makefile requires PowerShell version 3 or higher." -ForegroundColor Red
Write-Host "Please download and install the latest Windows Management Framework version from Microsoft." -ForegroundColor Red
WaitForInput
}
if ($args.Length -eq 0)
{
Write-Host "Command list:"
Write-Host ""
Write-Host " all, a Builds the game and its development tools."
Write-Host " version, v Sets the version strings for the default mods to the"
Write-Host " latest version for the current Git branch."
Write-Host " clean, c Removes all built and copied files. Use the 'all' and"
Write-Host " 'dependencies' commands to restore removed files."
Write-Host " test, t Tests the default mods for errors."
Write-Host " check, ck Checks .cs files for StyleCop violations."
Write-Host " check-scripts, cs Checks .lua files for syntax errors."
Write-Host ""
$command = (Read-Host "Enter command").Split(' ', 2)
}
else
{
$command = $args
}
$env:ENGINE_DIR = ".."
$utilityPath = "bin\OpenRA.Utility.exe"
$configuration = "Release"
if ($args.Contains("CONFIGURATION=Debug"))
{
$configuration = "Debug"
}
$execute = $command
if ($command.Length -gt 1)
{
$execute = $command[0]
}
switch ($execute)
{
{"all", "a" -contains $_} { All-Command }
{"version", "v" -contains $_} { Version-Command }
{"clean", "c" -contains $_} { Clean-Command }
{"test", "t" -contains $_} { Test-Command }
{"tests", "ut" -contains $_} { Tests-Command }
{"check", "ck" -contains $_} { Check-Command }
{"check-scripts", "cs" -contains $_} { Check-Scripts-Command }
Default { Write-Host ("Invalid command '{0}'" -f $command) }
}
#In case the script was called without any parameters we keep the window open
if ($args.Length -eq 0)
{
WaitForInput
}