-
Notifications
You must be signed in to change notification settings - Fork 853
Expand file tree
/
Copy pathinitrun.ps1
More file actions
72 lines (61 loc) · 2.19 KB
/
Copy pathinitrun.ps1
File metadata and controls
72 lines (61 loc) · 2.19 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
<#
.SYNOPSIS
Run a command in an initialized WinUI build environment.
.DESCRIPTION
Calls init.ps1 with the specified flavor (default: amd64chk), then executes the
given command with all environment variables and PATH entries set. This eliminates
the need to persist a shell session after running init.
.PARAMETER Flavor
Build flavor. Default: amd64chk.
Examples: amd64chk, amd64fre, x86chk, x86fre, arm64chk, arm64fre
.PARAMETER Command
The command and arguments to run after initialization.
.EXAMPLE
.\initrun.ps1 build.cmd mux /q
.\initrun.ps1 msb "dxaml\xcp\dxaml\dllsrv\winrt\native\Microsoft.ui.xaml.vcxproj" /q
.\initrun.ps1 -Flavor arm64fre build.cmd mux /q
.\initrun.ps1 run-tests-vm.ps1 *CommandBar*
#>
param(
[Alias("i")]
[string]$Flavor = "amd64chk",
[Parameter(Position = 0, ValueFromRemainingArguments = $true)]
[string[]]$Command
)
$ErrorActionPreference = "Stop"
$scriptDir = $PSScriptRoot
if (-not $Command -or $Command.Count -eq 0) {
Get-Help $MyInvocation.MyCommand.Path -Detailed
exit 1
}
# Run init with /envcheck to set up environment variables and PATH
# This skips NuGet restore — a full init must have been run previously.
try {
& (Join-Path $scriptDir "init.ps1") $Flavor /envcheck /notitle
} catch {
Write-Host "ERROR: init.ps1 $Flavor /envcheck failed: $_" -ForegroundColor Red
Write-Host "Run a full init first: .\init.ps1 $Flavor" -ForegroundColor Red
exit 1
}
# Execute the command
$cmd = $Command[0]
$cmdArgs = @()
if ($Command.Count -gt 1) {
$cmdArgs = $Command[1..($Command.Count - 1)]
}
# Resolve the command — check PATH and current directory
$resolved = Get-Command $cmd -ErrorAction SilentlyContinue
if ($resolved) {
$cmd = $resolved.Source
} elseif (Test-Path (Join-Path $scriptDir $cmd)) {
$cmd = Join-Path $scriptDir $cmd
}
# Use Invoke-Expression to preserve named parameters like -IPAddress
$escapedArgs = $cmdArgs | ForEach-Object {
if ($_ -match '^-') { $_ } # pass switches/named params as-is
elseif ($_ -match '\s') { "'$_'" } # quote args with spaces
else { $_ }
}
$fullCmd = "& '$cmd' $($escapedArgs -join ' ')"
Invoke-Expression $fullCmd
exit $LASTEXITCODE