aboutsummaryrefslogtreecommitdiff
path: root/scripts/azure-pipelines/Format-CxxCode.ps1
diff options
context:
space:
mode:
authornicole mazzuca <mazzucan@outlook.com>2020-12-16 13:14:35 -0800
committerGitHub <noreply@github.com>2020-12-16 13:14:35 -0800
commit30767175d52d9667ce37d96fe1a7d1438dc94ea1 (patch)
tree982999e2593b2d8bc580e25ef9f50f84d30cb6be /scripts/azure-pipelines/Format-CxxCode.ps1
parentd52fbe6a45c9ee0736edb42be4d688ae858bc215 (diff)
downloadvcpkg-30767175d52d9667ce37d96fe1a7d1438dc94ea1.tar.gz
vcpkg-30767175d52d9667ce37d96fe1a7d1438dc94ea1.zip
[vcpkg ci] upload diff from clang-format to artifacts (#15141)
* [vcpkg ci] upload diff from clang-format to artifacts this allows people who do not have access to clang-format to format their code via diff
Diffstat (limited to 'scripts/azure-pipelines/Format-CxxCode.ps1')
-rw-r--r--scripts/azure-pipelines/Format-CxxCode.ps149
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/azure-pipelines/Format-CxxCode.ps1 b/scripts/azure-pipelines/Format-CxxCode.ps1
new file mode 100644
index 000000000..a20a9ce0b
--- /dev/null
+++ b/scripts/azure-pipelines/Format-CxxCode.ps1
@@ -0,0 +1,49 @@
+[CmdletBinding()]
+Param(
+ [Parameter(Mandatory=$True)]
+ [string]$Root
+)
+
+$Root = Resolve-Path -LiteralPath $Root
+
+$clangFormat = Get-Command 'clang-format' -ErrorAction 'SilentlyContinue'
+if ($null -ne $clangFormat)
+{
+ $clangFormat = $clangFormat.Source
+}
+
+if ($IsWindows)
+{
+ if ([String]::IsNullOrEmpty($clangFormat) -or -not (Test-Path $clangFormat))
+ {
+ $clangFormat = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\x64\bin\clang-format.exe'
+ }
+ if (-not (Test-Path $clangFormat))
+ {
+ $clangFormat = 'C:\Program Files\LLVM\bin\clang-format.exe'
+ }
+}
+
+if ([String]::IsNullOrEmpty($clangFormat) -or -not (Test-Path $clangFormat))
+{
+ Write-Error 'clang-format not found; is it installed?'
+ throw
+}
+
+$toolsrc = Get-Item "$Root/toolsrc"
+Push-Location $toolsrc
+
+try
+{
+ $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"
+ $fileNames = $files.FullName
+
+ & $clangFormat -style=file -i @fileNames
+}
+finally
+{
+ Pop-Location
+}