-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBuild-RscSdk.ps1
50 lines (39 loc) · 1.49 KB
/
Build-RscSdk.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
<#
.SYNOPSIS
Wrapper for running the SDK build process in a separate PowerShell process to avoid file locking issues.
.DESCRIPTION
This script invokes the actual `_Build-RscSdk.ps1` script in a new `pwsh` process.
This approach streams the build output in real-time to the console.
#>
# Get the current script directory
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# Construct the command to run in a new pwsh session
$buildCommand = "$scriptDir\_Build-RscSdk.ps1 $args"
# Create a process to execute the command and stream output in real-time
$processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
$processStartInfo.FileName = "pwsh"
$processStartInfo.Arguments = "-Command $buildCommand"
$processStartInfo.RedirectStandardOutput = $true
$processStartInfo.RedirectStandardError = $true
$processStartInfo.UseShellExecute = $false
$processStartInfo.CreateNoWindow = $true
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $processStartInfo
# Start the process
$process.Start() | Out-Null
# Stream stdout and stderr in real-time
while (-not $process.StandardOutput.EndOfStream) {
$line = $process.StandardOutput.ReadLine()
Write-Host $line
}
while (-not $process.StandardError.EndOfStream) {
$line = $process.StandardError.ReadLine()
Write-Host $line -ForegroundColor Red
}
# Wait for the process to exit and capture the exit code
$process.WaitForExit()
$exitCode = $process.ExitCode
# Return the exit code
if ($exitCode -ne 0) {
exit $exitCode
}