-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBuild.ps1
More file actions
197 lines (162 loc) · 6.93 KB
/
Build.ps1
File metadata and controls
197 lines (162 loc) · 6.93 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
param
(
[Switch]$Archive,
[String]$BlockList,
[Switch]$Clean,
[String]$Configuration = "Release",
[Switch]$Help
)
$work = $pwd
$blockList = $BlockList.Split(";");
$artifactsDir = [System.IO.Directory]::CreateDirectory([System.IO.Path]::Combine($work, "Artifacts"))
if ($Help)
{
Write-Host "Code Mods Build Script"
Write-Host
Write-Host "Parameters:"
Write-Host "-Archive - archives the build artifacts."
Write-Host "-BlockList - semi-colon separated list of projects not to build."
Write-Host "-Clean - clean the projects before building."
Write-Host "-Configuration [name] - build with a specific configuration."
Write-Host "-Help - display help."
exit
}
$vs = ./Tools/vswhere.exe -nologo -latest -prerelease -property installationPath
$vsCommonTools = [System.IO.Path]::Combine($vs, "Common7", "Tools")
pushd $vsCommonTools
cmd /c "VsDevCmd.bat > nul 2> nul &set" |
foreach {
if ($_ -match "=") {
$v = $_.split("=", 2)
Set-Item -Force -Path "ENV:\$($v[0])" -Value "$($v[1])"
}
}
popd
function GetProjectProperty([String]$in_projectPath, [String]$in_propertyName)
{
return & msbuild /NoLogo /p:Configuration="${Configuration}" -getProperty:"${in_propertyName}" "${in_projectPath}"
}
function IsDependency([String]$in_path)
{
return $in_path.Contains("Dependencies")
}
function BuildSolutions([String]$in_root)
{
$root = [System.IO.Path]::Combine($work, $in_root)
foreach ($solutionPath in [System.IO.Directory]::EnumerateFiles($root, "*.sln", [System.IO.SearchOption]::AllDirectories))
{
if (IsDependency($solutionPath))
{
continue
}
$solutionDir = Split-Path $solutionPath
$solutionName = [System.IO.Path]::GetFileNameWithoutExtension($solutionPath)
if ($blockList.Contains($solutionName))
{
continue
}
$target = "Build"
if ($Clean)
{
$target = "Clean;" + $target
}
Write-Host
Write-Host ("**************" + '*' * $solutionPath.Length) -ForegroundColor DarkGreen
Write-Host "* Solution: ${solutionPath} *" -ForegroundColor DarkGreen
Write-Host ("**************" + '*' * $solutionPath.Length) -ForegroundColor DarkGreen
& msbuild /NoLogo /v:m /t:"${target}" /Restore /p:RestorePackagesConfig=true /p:Configuration="${Configuration}" "${solutionPath}"
if ($Archive)
{
$projects = dotnet sln "${solutionPath}" list |
Select-Object -Skip 2 |
ForEach-Object {
Join-Path $solutionDir $_.Trim()
}
foreach ($projectPath in $projects)
{
$projectDir = GetProjectProperty $projectPath "ProjectDir"
$projectName = (GetProjectProperty $projectPath "ProjectName").Replace(" ", "")
$binDir = [System.IO.Path]::Combine($projectDir, "bin")
foreach ($platformDir in [System.IO.Directory]::EnumerateDirectories($binDir))
{
$platformName = [System.IO.Path]::GetFileName($platformDir)
if ($platformName -eq $Configuration)
{
# Required for some .NET projects.
$targetDir = $platformDir
$targetName = "${projectName}-${Configuration}.zip"
}
else
{
$targetDir = [System.IO.Path]::Combine($platformDir, $Configuration)
$targetName = "${projectName}-${platformName}-${Configuration}.zip"
}
if (![System.IO.Directory]::Exists($targetDir))
{
Write-Host
Write-Host ("***********************" + '*' * $targetDir.Length) -ForegroundColor DarkRed
Write-Host "* Cannot archive project binaries." -ForegroundColor DarkRed
Write-Host "* Directory not found: ${targetDir}" -ForegroundColor DarkRed
Write-Host ("***********************" + '*' * $targetDir.Length) -ForegroundColor DarkRed
exit -1
}
$artifactRootDir = [System.IO.Directory]::CreateDirectory([System.IO.Path]::Combine($artifactsDir.FullName, $in_root, $solutionName))
$artifactTargetPath = [System.IO.Path]::Combine($artifactRootDir.FullName, $targetName)
cd $targetDir
Compress-Archive -Force * $artifactTargetPath
cd $work
}
}
}
}
}
function BuildMakefiles([String]$in_root)
{
$root = [System.IO.Path]::Combine($work, $in_root)
foreach ($makefilePath in [System.IO.Directory]::EnumerateFiles($root, "Makefile", [System.IO.SearchOption]::AllDirectories))
{
if (IsDependency($makefilePath))
{
continue
}
$makefileDir = Split-Path $makefilePath
$projectName = [System.IO.Path]::GetFileName($makefileDir)
if ($blockList.Contains($projectName))
{
continue
}
$args = @()
if ($Clean)
{
$args += "clean"
}
$args += "all"
Write-Host
Write-Host ("**************" + '*' * $makefilePath.Length) -ForegroundColor DarkGreen
Write-Host "* Makefile: ${makefilePath} *" -ForegroundColor DarkGreen
Write-Host ("**************" + '*' * $makefilePath.Length) -ForegroundColor DarkGreen
& make -C "${makefileDir}" @args
if ($Archive)
{
$projectNameSafe = $projectName.Replace(" ", "")
$binDir = [System.IO.Path]::Combine($makefileDir, "bin")
$targetName = "${projectNameSafe}-${Configuration}.zip"
if (![System.IO.Directory]::Exists($binDir))
{
Write-Host
Write-Host ("***********************" + '*' * $binDir.Length) -ForegroundColor DarkRed
Write-Host "* Cannot archive project binaries." -ForegroundColor DarkRed
Write-Host "* Directory not found: ${binDir}" -ForegroundColor DarkRed
Write-Host ("***********************" + '*' * $binDir.Length) -ForegroundColor DarkRed
exit -1
}
$artifactRootDir = [System.IO.Directory]::CreateDirectory([System.IO.Path]::Combine($artifactsDir.FullName, $in_root))
$artifactTargetPath = [System.IO.Path]::Combine($artifactRootDir.FullName, $targetName)
cd $binDir
Compress-Archive -Force * $artifactTargetPath
cd $work
}
}
}
BuildSolutions("Games")
BuildMakefiles("Games/Zelda 64 Recompiled/Majora's Mask")