aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authornicole mazzuca <mazzucan@outlook.com>2020-07-06 16:45:34 -0700
committerGitHub <noreply@github.com>2020-07-06 16:45:34 -0700
commit6a41626eaf33d2f3392e06d98a94c630bfc30977 (patch)
treefb92f59f27b99c56ed48f6cae649468b4407a073 /scripts
parentae4968fad40e8c14541dae89c481ec32c0500426 (diff)
downloadvcpkg-6a41626eaf33d2f3392e06d98a94c630bfc30977.tar.gz
vcpkg-6a41626eaf33d2f3392e06d98a94c630bfc30977.zip
[vcpkg] Format the C++ in CI (#11655)
* [vcpkg] Format the C++ in the CI * format the C++ * CR
Diffstat (limited to 'scripts')
-rw-r--r--scripts/azure-pipelines/windows/azure-pipelines.yml6
-rw-r--r--scripts/azure-pipelines/windows/check-formatting.ps154
-rw-r--r--scripts/azure-pipelines/windows/provision-image.txt24
3 files changed, 84 insertions, 0 deletions
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
@@ -393,6 +393,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
.DESCRIPTION