68 lines
3.3 KiB
PowerShell
68 lines
3.3 KiB
PowerShell
# Parses every .ps1 under the given folders with the PowerShell parser of the PowerShell that runs this script and
|
|
# fails on any parse error, printed as file:line:message. Run it under Windows PowerShell 5.1 (powershell.exe), the
|
|
# PowerShell on the project lead's PCs: 5.1 rejects "$name: text" (a drive-qualified variable reference) where newer parsers may
|
|
# not, and that class caused the two launcher failures of 4 October 2026 (commits 82275e6 and 018f739).
|
|
#
|
|
# A built-in negative test parses fixtures\bad-drive-ref.ps1.txt first and refuses to pass unless that file FAILS with
|
|
# the 5.1 message, so a green run proves the check bites.
|
|
#
|
|
# powershell -NoProfile -ExecutionPolicy Bypass -File tools\ci\windows\check-ps51.ps1 [-Root <repo>] [-AnyVersion]
|
|
param(
|
|
[string]$Root = '',
|
|
[string[]]$Folders = @('proto-cuda/windows-app', 'proto-cuda/windows-miner', 'proto-cuda/windows-node',
|
|
'proving/windows-wsl2', 'relay/clients', 'relay/playbooks', 'packaging/windows', 'app/windows', 'tools/ci/windows'),
|
|
[switch]$AnyVersion
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
if (-not $Root) { $Root = (Resolve-Path (Join-Path $PSScriptRoot '..\..\..')).Path }
|
|
$v = $PSVersionTable.PSVersion
|
|
Write-Host "PowerShell $v ($($PSVersionTable.PSEdition))"
|
|
if ($v.Major -ne 5 -and -not $AnyVersion) {
|
|
Write-Host "::error::this check must run under Windows PowerShell 5.1 (powershell.exe), not PowerShell $v; pass -AnyVersion to override"
|
|
exit 2
|
|
}
|
|
|
|
function Parse-File([string]$path) {
|
|
$tokens = $null
|
|
$errors = $null
|
|
[void][System.Management.Automation.Language.Parser]::ParseFile($path, [ref]$tokens, [ref]$errors)
|
|
return ,@($errors)
|
|
}
|
|
|
|
# ---- 1. the negative test: the fixture with "$x: y" must fail to parse ----
|
|
$fixture = Join-Path $PSScriptRoot 'fixtures\bad-drive-ref.ps1.txt'
|
|
$fixtureErrors = Parse-File $fixture
|
|
if ($fixtureErrors.Count -eq 0) {
|
|
Write-Host "::error::self-test failed: $fixture parsed without errors, so this parser does not catch the 5.1 drive-qualified variable bug"
|
|
exit 2
|
|
}
|
|
$msg = $fixtureErrors[0].Message
|
|
Write-Host ("self-test: fixture bad-drive-ref.ps1.txt fails as expected at line {0}: {1}" -f $fixtureErrors[0].Extent.StartLineNumber, $msg)
|
|
if ($msg -notmatch 'Variable reference is not valid') {
|
|
Write-Host "::error::self-test: the fixture failed, but not with the 'Variable reference is not valid' message (got: $msg)"
|
|
exit 2
|
|
}
|
|
|
|
# ---- 2. every .ps1 under the folders ----
|
|
$files = @()
|
|
foreach ($f in $Folders) {
|
|
$dir = Join-Path $Root $f
|
|
if (-not (Test-Path $dir)) { Write-Host "note: no folder $f"; continue }
|
|
$files += Get-ChildItem -Path $dir -Recurse -Filter '*.ps1' -File | Where-Object { $_.FullName -notmatch '\\igneum-windows-app\\|\\build\\|\\dist\\' }
|
|
}
|
|
$bad = 0
|
|
foreach ($file in ($files | Sort-Object FullName)) {
|
|
$rel = $file.FullName.Substring($Root.Length).TrimStart('\', '/')
|
|
$errs = Parse-File $file.FullName
|
|
if ($errs.Count -eq 0) { Write-Host "ok $rel"; continue }
|
|
foreach ($e in $errs) {
|
|
$bad += 1
|
|
$line = $e.Extent.StartLineNumber
|
|
$col = $e.Extent.StartColumnNumber
|
|
Write-Host "FAIL ${rel}:${line}:${col}: $($e.Message)"
|
|
Write-Host "::error file=$($rel -replace '\\', '/'),line=$line,col=${col}::$($e.Message)"
|
|
}
|
|
}
|
|
Write-Host ("{0} files parsed, {1} parse errors" -f $files.Count, $bad)
|
|
if ($bad -gt 0) { exit 1 }
|
|
exit 0
|