Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion build_scripts/windows/scripts/azps.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
$env:AZ_INSTALLER="MSI"
& "$PSScriptRoot\..\python.exe" -IBm azure.cli $args
if ($MyInvocation.ExpectingInput) {
$input | & "$PSScriptRoot\..\python.exe" -IBm azure.cli $args
}
else {
& "$PSScriptRoot\..\python.exe" -IBm azure.cli $args
}
exit $LASTEXITCODE

# SIG # Begin signature block
# MIInuQYJKoZIhvcNAQcCoIInqjCCJ6YCAQExDzANBglghkgBZQMEAgEFADB5Bgor
Expand Down
41 changes: 41 additions & 0 deletions build_scripts/windows/scripts/test_msi_installation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,44 @@ if ($installed_version -ne $artifact_version){
# Test bundled pip with extension installation
& $az_full_path extension add -n account
& $az_full_path self-test

# ---------------------------------------------------------------------
# azps.ps1 wrapper regression tests
# ---------------------------------------------------------------------
$azps_full_path = Join-Path (Split-Path $az_full_path -Parent) "azps.ps1"
if (-not (Test-Path $azps_full_path)) {
Write-Output "azps.ps1 was not installed at $azps_full_path"
Exit 1
}

# Baseline: the wrapper runs and --version returns success.
& $azps_full_path --version
if ($LASTEXITCODE -ne 0) {
Write-Output "azps.ps1 --version returned $LASTEXITCODE (expected 0)"
Exit 1
}

# A .ps1 wrapper must propagate non-zero exit codes from the
# child process. Unknown commands exit with code 2; an unfixed wrapper
# would exit 0 here.
& $azps_full_path this-command-does-not-exist-xyz *> $null
if ($LASTEXITCODE -eq 0) {
Write-Output "azps.ps1 did not propagate a failure exit code"
Exit 1
}

# When pwsh.exe invokes a .ps1 via
# -Command, the script's exit code is only surfaced if the script
# itself calls 'exit N'. Skip this check if pwsh.exe is unavailable
# so we don't false-pass on a stale $LASTEXITCODE value.
if (Get-Command pwsh.exe -ErrorAction SilentlyContinue) {
$global:LASTEXITCODE = 0
& pwsh.exe -NoProfile -Command "& '$azps_full_path' this-command-does-not-exist-xyz *> `$null; exit `$LASTEXITCODE"
if (-not $? -or $LASTEXITCODE -eq 0) {
Write-Output "azps.ps1 exit code swallowed when invoked via 'pwsh.exe -Command'"
Exit 1
}
}
else {
Write-Output "pwsh.exe not found; skipping pwsh.exe -Command regression check"
}
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
18 changes: 15 additions & 3 deletions src/azure-cli/azps.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
$env:AZ_INSTALLER="PIP"

if (Test-Path "$PSScriptRoot\python.exe") {
# Perfer python.exe in venv
& "$PSScriptRoot\python.exe" -m azure.cli $args
# Prefer python.exe in venv
if ($MyInvocation.ExpectingInput) {
$input | & "$PSScriptRoot\python.exe" -m azure.cli $args
}
else {
& "$PSScriptRoot\python.exe" -m azure.cli $args
}
}
Comment thread
AaronRobinsonMSFT marked this conversation as resolved.
else {
# Run system python.exe
python.exe -m azure.cli $args
if ($MyInvocation.ExpectingInput) {
$input | python.exe -m azure.cli $args
}
else {
python.exe -m azure.cli $args
}
}

exit $LASTEXITCODE

# SIG # Begin signature block
# MIInqgYJKoZIhvcNAQcCoIInmzCCJ5cCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
Expand Down
Loading