From 9606917c81792c52097847fa8037907d92b161a2 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Tue, 7 Jul 2020 14:09:33 -0700 Subject: [vcpkg ci] Update formatting CI (#12314) * stage checking formatting this means that the port CI won't run if the formatting failed * fix invalid names * add formatting of manifests * fix dependsOn name * fix a thing * CRs * oops, typo --- scripts/azure-pipelines/azure-pipelines.yml | 31 ++++++++++++- .../windows/Check-CxxFormatting.ps1 | 51 ++++++++++++++++++++ .../windows/Check-ManifestFormatting.ps1 | 51 ++++++++++++++++++++ .../azure-pipelines/windows/Get-ChangedFiles.ps1 | 9 ++++ .../azure-pipelines/windows/azure-pipelines.yml | 8 +--- .../azure-pipelines/windows/check-formatting.ps1 | 54 ---------------------- 6 files changed, 142 insertions(+), 62 deletions(-) create mode 100644 scripts/azure-pipelines/windows/Check-CxxFormatting.ps1 create mode 100644 scripts/azure-pipelines/windows/Check-ManifestFormatting.ps1 create mode 100644 scripts/azure-pipelines/windows/Get-ChangedFiles.ps1 delete mode 100644 scripts/azure-pipelines/windows/check-formatting.ps1 (limited to 'scripts') diff --git a/scripts/azure-pipelines/azure-pipelines.yml b/scripts/azure-pipelines/azure-pipelines.yml index c0cda8432..9c66be5a3 100644 --- a/scripts/azure-pipelines/azure-pipelines.yml +++ b/scripts/azure-pipelines/azure-pipelines.yml @@ -5,7 +5,36 @@ variables: windows-pool: 'PrWin-2020-06-30' linux-pool: 'PrLin-2020-06-30' -jobs: +stages: +- stage: check_cxx_formatting + displayName: 'Check the formatting of the C++' + pool: $(windows-pool) + jobs: + - job: + steps: + - task: Powershell@2 + displayName: 'Check C++ Formatting' + inputs: + filePath: 'scripts/azure-pipelines/windows/Check-CxxFormatting.ps1' + arguments: '-Root .' +- stage: check_manifest_formatting + displayName: Check the formatting of port manifests + pool: $(windows-pool) + dependsOn: [] + jobs: + - job: + steps: + - task: Powershell@2 + displayName: 'Check port manifest Formatting' + inputs: + filePath: 'scripts/azure-pipelines/windows/Check-ManifestFormatting.ps1' + arguments: '-Root . -Downloads D:\Downloads' +- stage: run_port_ci + displayName: 'Run the Port CI' + dependsOn: + - check_cxx_formatting + - check_manifest_formatting + jobs: - template: windows/azure-pipelines.yml parameters: triplet: x86-windows diff --git a/scripts/azure-pipelines/windows/Check-CxxFormatting.ps1 b/scripts/azure-pipelines/windows/Check-CxxFormatting.ps1 new file mode 100644 index 000000000..7f300164f --- /dev/null +++ b/scripts/azure-pipelines/windows/Check-CxxFormatting.ps1 @@ -0,0 +1,51 @@ +[CmdletBinding()] +Param( + [Parameter(Mandatory=$True)] + [string]$Root, + [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 "$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 + + $changedFiles = & "$PSScriptRoot/Get-ChangedFiles.ps1" -Directory $toolsrc + 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/Check-ManifestFormatting.ps1 b/scripts/azure-pipelines/windows/Check-ManifestFormatting.ps1 new file mode 100644 index 000000000..e4f52ae7b --- /dev/null +++ b/scripts/azure-pipelines/windows/Check-ManifestFormatting.ps1 @@ -0,0 +1,51 @@ +[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.", + "If your build fails here, you need to run:" + ) + $msg += " vcpkg x-format-manifest --all" + $msg += "" + + $msg += "vcpkg should produce the following diff:" + $msg += git diff $portsTree + + Write-Error ($msg -join "`n") + throw +} diff --git a/scripts/azure-pipelines/windows/Get-ChangedFiles.ps1 b/scripts/azure-pipelines/windows/Get-ChangedFiles.ps1 new file mode 100644 index 000000000..e299369a0 --- /dev/null +++ b/scripts/azure-pipelines/windows/Get-ChangedFiles.ps1 @@ -0,0 +1,9 @@ +[CmdletBinding()] +Param( + [Parameter(Mandatory=$True)] + [string]$Directory +) + +git status --porcelain $Directory | ForEach-Object { + (-split $_)[1] +} diff --git a/scripts/azure-pipelines/windows/azure-pipelines.yml b/scripts/azure-pipelines/windows/azure-pipelines.yml index 1d18c0339..4136615c7 100644 --- a/scripts/azure-pipelines/windows/azure-pipelines.yml +++ b/scripts/azure-pipelines/windows/azure-pipelines.yml @@ -20,13 +20,7 @@ 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. + # Note: D: is the Azure machines' temporary disk. - task: CmdLine@2 displayName: 'Build vcpkg' inputs: diff --git a/scripts/azure-pipelines/windows/check-formatting.ps1 b/scripts/azure-pipelines/windows/check-formatting.ps1 deleted file mode 100644 index e3c3d213e..000000000 --- a/scripts/azure-pipelines/windows/check-formatting.ps1 +++ /dev/null @@ -1,54 +0,0 @@ -[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 -} -- cgit v1.2.3