vcpkg/scripts/azure-pipelines/windows/Check-ManifestFormatting.ps1
Jack·Boos·Yu d367c4c0b8
[vcpkg] Improve format check failure message (#12460)
* [docs] Add format document

* improve the error message

* Check the error message

* Finish test

* restore file list
2020-07-29 21:12:06 -07:00

51 lines
1.2 KiB
PowerShell

[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$Root,
[Parameter()]
[string]$DownloadsDirectory,
[Parameter()]
[switch]$IgnoreErrors # allows one to just format
)
$portsTree = Get-Item "$Root/ports"
if (-not (Test-Path "$Root/.vcpkg-root"))
{
Write-Error "The vcpkg root was not at $Root"
throw
}
if (-not [string]::IsNullOrEmpty($DownloadsDirectory))
{
$env:VCPKG_DOWNLOADS = $DownloadsDirectory
}
if (-not (Test-Path "$Root/vcpkg.exe"))
{
& "$Root/bootstrap-vcpkg.bat"
if (-not $?)
{
Write-Error "Bootstrapping vcpkg failed"
throw
}
}
& "$Root/vcpkg.exe" 'x-format-manifest' '--all'
$changedFiles = & "$PSScriptRoot/Get-ChangedFiles.ps1" -Directory $portsTree
if (-not $IgnoreErrors -and $null -ne $changedFiles)
{
$msg = @(
"",
"The formatting of the manifest files didn't match our expectation.",
"See https://github.com/microsoft/vcpkg/blob/master/docs/maintainers/maintainer-guide.md#manifest for solution."
)
$msg += ""
$msg += "vcpkg should produce the following diff:"
$msg += git diff $portsTree
Write-Error ($msg -join "`n")
throw
}