forked from OpenRA/ra2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.ps1
412 lines (357 loc) · 10.6 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
####### The starting point for the script is the bottom #######
###############################################################
########################## FUNCTIONS ##########################
###############################################################
function All-Command
{
If (!(Test-Path "*.sln"))
{
return
}
if ((CheckForDotnet) -eq 1)
{
return
}
dotnet build /p:Configuration=Release /nologo
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
}
}
function Clean-Command
{
If (!(Test-Path "*.sln"))
{
return
}
if ((CheckForDotnet) -eq 1)
{
return
}
dotnet clean /nologo
rm *.dll
rm mods/*/*.dll
rm *.dll.config
rm *.pdb
rm mods/*/*.pdb
rm *.exe
rm ./*/bin -r
rm ./*/obj -r
rm $env:ENGINE_DIRECTORY/*.dll
rm $env:ENGINE_DIRECTORY/mods/*/*.dll
rm env:ENGINE_DIRECTORY/*.config
rm env:ENGINE_DIRECTORY/*.pdb
rm mods/*/*.pdb
rm env:ENGINE_DIRECTORY/*.exe
rm env:ENGINE_DIRECTORY/*/bin -r
rm env:ENGINE_DIRECTORY/*/obj -r
if (Test-Path env:ENGINE_DIRECTORY/thirdparty/download/)
{
rmdir env:ENGINE_DIRECTORY/thirdparty/download -Recurse -Force
}
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)
{
$mod = "mods/" + $modID + "/mod.yaml"
$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 $modID mod MiniYAML..." -ForegroundColor Cyan
Invoke-Expression "$utilityPath $modID --check-yaml"
}
function Check-Command
{
If (!(Test-Path "*.sln"))
{
Write-Host "No custom solution file found. Skipping static code checks." -ForegroundColor Cyan
return
}
Write-Host "Compiling in debug configuration..." -ForegroundColor Cyan
dotnet build /p:Configuration=Debug /nologo
if ($lastexitcode -ne 0)
{
Write-Host "Build failed." -ForegroundColor Red
}
if ((CheckForUtility) -eq 0)
{
Write-Host "Checking for explicit interface violations..." -ForegroundColor Cyan
Invoke-Expression "$utilityPath $modID --check-explicit-interfaces"
Write-Host "Checking for incorrect conditional trait interface overrides..." -ForegroundColor Cyan
Invoke-Expression "$utilityPath $modID --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
}
Write-Host "Check completed!" -ForegroundColor Green
}
else
{
Write-Host "luac.exe could not be found. Please install Lua." -ForegroundColor Red
}
}
function Docs-Command
{
if ((CheckForUtility) -eq 1)
{
return
}
./make.ps1 version
Invoke-Expression "$utilityPath $modID --docs | Out-File -Encoding 'UTF8' DOCUMENTATION.md"
Invoke-Expression "$utilityPath $modID --weapon-docs | Out-File -Encoding "UTF8" WEAPONS.md"
Invoke-Expression "$utilityPath $modID --lua-docs | Out-File -Encoding 'UTF8' Lua-API.md"
Write-Host "Docs generated." -ForegroundColor Green
}
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
{
echo "Press enter to continue."
while ($true)
{
if ([System.Console]::KeyAvailable)
{
exit
}
Start-Sleep -Milliseconds 50
}
}
function ReadConfigLine($line, $name)
{
$prefix = $name + '='
if ($line.StartsWith($prefix))
{
[Environment]::SetEnvironmentVariable($name, $line.Replace($prefix, '').Replace('"', ''))
}
}
function ParseConfigFile($fileName)
{
$names = @("MOD_ID", "ENGINE_VERSION", "AUTOMATIC_ENGINE_MANAGEMENT", "AUTOMATIC_ENGINE_SOURCE",
"AUTOMATIC_ENGINE_EXTRACT_DIRECTORY", "AUTOMATIC_ENGINE_TEMP_ARCHIVE_NAME", "ENGINE_DIRECTORY")
$reader = [System.IO.File]::OpenText($fileName)
while($null -ne ($line = $reader.ReadLine()))
{
foreach ($name in $names)
{
ReadConfigLine $line $name
}
}
$reader.Close()
$missing = @()
foreach ($name in $names)
{
if (!([System.Environment]::GetEnvironmentVariable($name)))
{
$missing += $name
}
}
if ($missing)
{
echo "Required mod.config variables are missing:"
foreach ($m in $missing)
{
echo " $m"
}
echo "Repair your mod.config (or user.config) and try again."
WaitForInput
exit
}
}
###############################################################
############################ Main #############################
###############################################################
if ($PSVersionTable.PSVersion.Major -clt 3)
{
echo "The makefile requires PowerShell version 3 or higher."
echo "Please download and install the latest Windows Management Framework version from Microsoft."
WaitForInput
}
if ($args.Length -eq 0)
{
echo "Command list:"
echo ""
echo " all Builds the game, its development tools and the mod dlls."
echo " version Sets the version strings for all mods to the latest"
echo " version for the current Git branch."
echo " clean Removes all built and copied files."
echo " from the mods and the engine directories."
echo " test Tests the mod's MiniYAML for errors."
echo " check Checks .cs files for StyleCop violations."
echo " check-scripts Checks .lua files for syntax errors."
echo " docs Generates the trait and Lua API documentation."
echo ""
$command = (Read-Host "Enter command").Split(' ', 2)
}
else
{
$command = $args
}
# Set the working directory for our IO methods
$templateDir = $pwd.Path
[System.IO.Directory]::SetCurrentDirectory($templateDir)
# Load the environment variables from the config file
# and get the mod ID from the local environment variable
ParseConfigFile "mod.config"
if (Test-Path "user.config")
{
ParseConfigFile "user.config"
}
$modID = $env:MOD_ID
$env:MOD_SEARCH_PATHS = (Get-Item -Path ".\" -Verbose).FullName + "\mods,./mods"
# Run the same command on the engine's make file
if ($command -eq "all" -or $command -eq "clean")
{
$versionFile = $env:ENGINE_DIRECTORY + "/VERSION"
$currentEngine = ""
if (Test-Path $versionFile)
{
$reader = [System.IO.File]::OpenText($versionFile)
$currentEngine = $reader.ReadLine()
$reader.Close()
}
if ($currentEngine -ne "" -and $currentEngine -eq $env:ENGINE_VERSION)
{
cd $env:ENGINE_DIRECTORY
Invoke-Expression ".\make.cmd $command"
echo ""
cd $templateDir
}
elseif ($env:AUTOMATIC_ENGINE_MANAGEMENT -ne "True")
{
echo "Automatic engine management is disabled."
echo "Please manually update the engine to version $env:ENGINE_VERSION."
WaitForInput
}
else
{
echo "OpenRA engine version $env:ENGINE_VERSION is required."
if (Test-Path $env:ENGINE_DIRECTORY)
{
if ($currentEngine -ne "")
{
echo "Deleting engine version $currentEngine."
}
else
{
echo "Deleting existing engine (unknown version)."
}
rm $env:ENGINE_DIRECTORY -r
}
echo "Downloading engine..."
if (Test-Path $env:AUTOMATIC_ENGINE_EXTRACT_DIRECTORY)
{
rm $env:AUTOMATIC_ENGINE_EXTRACT_DIRECTORY -r
}
$url = $env:AUTOMATIC_ENGINE_SOURCE
$url = $url.Replace("$", "").Replace("{ENGINE_VERSION}", $env:ENGINE_VERSION)
mkdir $env:AUTOMATIC_ENGINE_EXTRACT_DIRECTORY > $null
$dlPath = Join-Path $pwd (Split-Path -leaf $env:AUTOMATIC_ENGINE_EXTRACT_DIRECTORY)
$dlPath = Join-Path $dlPath (Split-Path -leaf $env:AUTOMATIC_ENGINE_TEMP_ARCHIVE_NAME)
$client = new-object System.Net.WebClient
[Net.ServicePointManager]::SecurityProtocol = 'Tls12'
$client.DownloadFile($url, $dlPath)
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::ExtractToDirectory($dlPath, $env:AUTOMATIC_ENGINE_EXTRACT_DIRECTORY)
rm $dlPath
$extractedDir = Get-ChildItem $env:AUTOMATIC_ENGINE_EXTRACT_DIRECTORY -Recurse | ?{ $_.PSIsContainer } | Select-Object -First 1
Move-Item $extractedDir.FullName -Destination $templateDir
Rename-Item $extractedDir.Name (Split-Path -leaf $env:ENGINE_DIRECTORY)
rm $env:AUTOMATIC_ENGINE_EXTRACT_DIRECTORY -r
cd $env:ENGINE_DIRECTORY
Invoke-Expression ".\make.cmd version $env:ENGINE_VERSION"
Invoke-Expression ".\make.cmd $command"
echo ""
cd $templateDir
}
}
$utilityPath = $env:ENGINE_DIRECTORY + "/OpenRA.Utility.exe"
$styleCheckPath = $env:ENGINE_DIRECTORY + "/OpenRA.StyleCheck.exe"
$execute = $command
if ($command.Length -gt 1)
{
$execute = $command[0]
}
switch ($execute)
{
"all" { All-Command }
"version" { Version-Command }
"clean" { Clean-Command }
"test" { Test-Command }
"check" { Check-Command }
"check-scripts" { Check-Scripts-Command }
"docs" { Docs-Command }
Default { echo ("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
}