2020-07-07 07:45:34 +08:00
|
|
|
[CmdletBinding()]
|
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory=$True)]
|
2020-07-08 05:09:33 +08:00
|
|
|
[string]$Root,
|
2020-07-07 07:45:34 +08:00
|
|
|
[Parameter()]
|
|
|
|
[switch]$IgnoreErrors # allows one to just format
|
|
|
|
)
|
|
|
|
|
|
|
|
$clangFormat = 'C:\Program Files\LLVM\bin\clang-format.exe'
|
|
|
|
if (-not (Test-Path $clangFormat))
|
|
|
|
{
|
|
|
|
Write-Error "clang-format not found; is it installed in the CI machines?"
|
|
|
|
throw
|
|
|
|
}
|
|
|
|
|
2020-07-08 05:09:33 +08:00
|
|
|
$toolsrc = Get-Item "$Root/toolsrc"
|
|
|
|
Push-Location $toolsrc
|
2020-07-07 07:45:34 +08:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-07-08 05:09:33 +08:00
|
|
|
$files = Get-ChildItem -Recurse -LiteralPath "$toolsrc/src" -Filter '*.cpp'
|
|
|
|
$files += Get-ChildItem -Recurse -LiteralPath "$toolsrc/include/vcpkg" -Filter '*.h'
|
|
|
|
$files += Get-ChildItem -Recurse -LiteralPath "$toolsrc/include/vcpkg-test" -Filter '*.h'
|
|
|
|
$files += Get-Item "$toolsrc/include/pch.h"
|
2020-07-07 07:45:34 +08:00
|
|
|
$fileNames = $files.FullName
|
|
|
|
|
|
|
|
& $clangFormat -style=file -i @fileNames
|
|
|
|
|
2020-07-08 05:09:33 +08:00
|
|
|
$changedFiles = & "$PSScriptRoot/Get-ChangedFiles.ps1" -Directory $toolsrc
|
2020-07-07 07:45:34 +08:00
|
|
|
if (-not $IgnoreErrors -and $null -ne $changedFiles)
|
|
|
|
{
|
|
|
|
$msg = @(
|
|
|
|
"",
|
|
|
|
"The formatting of the C++ files didn't match our expectation.",
|
|
|
|
"If your build fails here, you need to format the following files with:"
|
|
|
|
)
|
|
|
|
$msg += " $(& $clangFormat -version)"
|
|
|
|
$msg += " $changedFiles"
|
|
|
|
$msg += ""
|
|
|
|
|
|
|
|
$msg += "clang-format should produce the following diff:"
|
2020-07-08 05:09:33 +08:00
|
|
|
$msg += git diff $toolsrc
|
2020-07-07 07:45:34 +08:00
|
|
|
|
|
|
|
Write-Error ($msg -join "`n")
|
|
|
|
throw
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
Pop-Location
|
|
|
|
}
|