From 6a41626eaf33d2f3392e06d98a94c630bfc30977 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Mon, 6 Jul 2020 16:45:34 -0700 Subject: [vcpkg] Format the C++ in CI (#11655) * [vcpkg] Format the C++ in the CI * format the C++ * CR --- .../azure-pipelines/windows/azure-pipelines.yml | 6 +++ .../azure-pipelines/windows/check-formatting.ps1 | 54 ++++++++++++++++++++++ .../azure-pipelines/windows/provision-image.txt | 24 ++++++++++ 3 files changed, 84 insertions(+) create mode 100644 scripts/azure-pipelines/windows/check-formatting.ps1 (limited to 'scripts') diff --git a/scripts/azure-pipelines/windows/azure-pipelines.yml b/scripts/azure-pipelines/windows/azure-pipelines.yml index a76b6afdf..1d18c0339 100644 --- a/scripts/azure-pipelines/windows/azure-pipelines.yml +++ b/scripts/azure-pipelines/windows/azure-pipelines.yml @@ -20,6 +20,12 @@ jobs: condition: always() inputs: filePath: 'scripts/azure-pipelines/windows/disk-space.ps1' + - task: Powershell@2 + displayName: 'Check C++ Formatting' + condition: eq('${{ parameters.triplet }}', 'x86-windows') + inputs: + filePath: 'scripts/azure-pipelines/windows/check-formatting.ps1' + arguments: '-Toolsrc ./toolsrc' # Note: D: is the Azure machines' temporary disk. - task: CmdLine@2 displayName: 'Build vcpkg' diff --git a/scripts/azure-pipelines/windows/check-formatting.ps1 b/scripts/azure-pipelines/windows/check-formatting.ps1 new file mode 100644 index 000000000..e3c3d213e --- /dev/null +++ b/scripts/azure-pipelines/windows/check-formatting.ps1 @@ -0,0 +1,54 @@ +[CmdletBinding()] +Param( + [Parameter(Mandatory=$True)] + [string]$Toolsrc, + [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 +} + +$Toolsrc = Get-Item $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 + + $changedFiles = git status --porcelain $Toolsrc | ForEach-Object { + (-split $_)[1] + } + + 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:" + $msg += git diff $Toolsrc + + Write-Error ($msg -join "`n") + throw + } +} +finally +{ + Pop-Location +} diff --git a/scripts/azure-pipelines/windows/provision-image.txt b/scripts/azure-pipelines/windows/provision-image.txt index 2d2790ec7..798b96e9a 100644 --- a/scripts/azure-pipelines/windows/provision-image.txt +++ b/scripts/azure-pipelines/windows/provision-image.txt @@ -391,6 +391,30 @@ Function InstallLLVM { } } +<# +.SYNOPSIS +Installs LLVM. + +.DESCRIPTION +InstallLLVM installs LLVM from the supplied URL. + +.PARAMETER Url +The URL of the LLVM installer. +#> +Function InstallLLVM { + try { + Write-Host 'Downloading LLVM...' + [string]$installerPath = Get-TempFilePath -Extension 'exe' + curl.exe -L -o $installerPath -s -S $Url + Write-Host 'Installing LLVM...' + $proc = Start-Process -FilePath $installerPath -ArgumentList @('/S') -NoNewWindow -Wait -PassThru + PrintMsiExitCodeMessage $proc.ExitCode + } + catch { + Write-Error "Failed to install LLVM! $($_.Exception.Message)" + } +} + <# .SYNOPSIS Installs MPI -- cgit v1.2.3