@@ -134,6 +134,7 @@ function Compile-SourceScript {
134
134
RedirectStandardInput = $stdInFile.FullName
135
135
Wait = $true
136
136
NoNewWindow = $true
137
+ PassThru = $true
137
138
}
138
139
if ($PSBoundParameters [' SkipWrapper' ]) {
139
140
$processArgs [' ArgumentList' ] = @ (
@@ -149,7 +150,38 @@ function Compile-SourceScript {
149
150
150
151
# Begin compilation
151
152
if ($PSBoundParameters [' SkipWrapper' ]) { " Compiling $ ( $sourceFile.Name ) ..." | Write-Host - ForegroundColor Yellow }
152
- Start-Process @processArgs
153
+ switch ($MOD_NAME ) {
154
+ ' sourcemod' {
155
+ $p = Start-Process @processArgs
156
+ $global :LASTEXITCODE = $p.ExitCode
157
+ }
158
+ ' amxmodx' {
159
+ # The amxmodx compiler always exits with exit code 0, so we have to use a regex on the stdout
160
+ $global :LASTEXITCODE = 0
161
+
162
+ $tempDir = Join-Path ([System.IO.Path ]::GetTempPath()) (New-Guid ).Guid
163
+ $stdoutFile = Join-Path $tempDir ' stdout'
164
+ $stderrFile = Join-Path $tempDir ' stderr'
165
+ $processArgs [' RedirectStandardOutput' ] = $stdoutFile
166
+ $processArgs [' RedirectStandardError' ] = $stderrFile
167
+ New-Item $tempDir - ItemType Directory - Force
168
+ $p = Start-Process @processArgs
169
+ $stdout = Get-Content $stdoutFile
170
+ $stderr = Get-Content $stderrFile
171
+ foreach ($line in $stdout ) {
172
+ if ($line -match ' ^.*\.sma\(\d+\)\s*:\s*error (\d+)' ) {
173
+ $global :LASTEXITCODE = $matches [1 ] -as [int ] | Select-Object - First 1
174
+ break
175
+ }
176
+ }
177
+
178
+ # Cleanup
179
+ Remove-Item $tempDir - Recurse - Force
180
+ }
181
+ default {
182
+ throw " Invalid mod name $MOD_NAME ."
183
+ }
184
+ }
153
185
if ($PSBoundParameters [' SkipWrapper' ]) { " End of compilation." | Write-Host - ForegroundColor Yellow }
154
186
155
187
# Get all items in compiled directory after compilation by hash
0 commit comments