From 30767175d52d9667ce37d96fe1a7d1438dc94ea1 Mon Sep 17 00:00:00 2001 From: nicole mazzuca Date: Wed, 16 Dec 2020 13:14:35 -0800 Subject: [PATCH] [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 --- format.diff | 0 scripts/azure-pipelines/Create-FormatDiff.ps1 | 20 ++++++ scripts/azure-pipelines/Format-CxxCode.ps1 | 49 ++++++++++++++ scripts/azure-pipelines/azure-pipelines.yml | 65 ++++++++----------- .../Check-CMakeFunctionDocumentation.ps1 | 30 --------- .../windows/Check-CxxFormatting.ps1 | 55 ---------------- .../windows/Check-ManifestFormatting.ps1 | 49 -------------- .../windows/Get-ChangedFiles.ps1 | 9 --- 8 files changed, 97 insertions(+), 180 deletions(-) create mode 100644 format.diff create mode 100644 scripts/azure-pipelines/Create-FormatDiff.ps1 create mode 100644 scripts/azure-pipelines/Format-CxxCode.ps1 delete mode 100644 scripts/azure-pipelines/windows/Check-CMakeFunctionDocumentation.ps1 delete mode 100644 scripts/azure-pipelines/windows/Check-CxxFormatting.ps1 delete mode 100644 scripts/azure-pipelines/windows/Check-ManifestFormatting.ps1 delete mode 100644 scripts/azure-pipelines/windows/Get-ChangedFiles.ps1 diff --git a/format.diff b/format.diff new file mode 100644 index 0000000000..e69de29bb2 diff --git a/scripts/azure-pipelines/Create-FormatDiff.ps1 b/scripts/azure-pipelines/Create-FormatDiff.ps1 new file mode 100644 index 0000000000..5991180892 --- /dev/null +++ b/scripts/azure-pipelines/Create-FormatDiff.ps1 @@ -0,0 +1,20 @@ +[CmdletBinding(PositionalBinding=$False)] +Param( + [Parameter(Mandatory=$True)] + [String]$DiffFile +) + +Start-Process -FilePath 'git' -ArgumentList 'diff' ` + -NoNewWindow -Wait ` + -RedirectStandardOutput $DiffFile +if (0 -ne (Get-Item -LiteralPath $DiffFile).Length) +{ + $msg = @( + 'The formatting of the files in the repo were not what we expected,', + 'or the documentation was not regenerated.', + 'Please access the diff from format.diff in the build artifacts,' + 'and apply the patch with `git apply`' + ) + Write-Error ($msg -join "`n") + throw +} \ No newline at end of file diff --git a/scripts/azure-pipelines/Format-CxxCode.ps1 b/scripts/azure-pipelines/Format-CxxCode.ps1 new file mode 100644 index 0000000000..a20a9ce0ba --- /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 +} diff --git a/scripts/azure-pipelines/azure-pipelines.yml b/scripts/azure-pipelines/azure-pipelines.yml index 03bf38e4cd..b7121bb08d 100644 --- a/scripts/azure-pipelines/azure-pipelines.yml +++ b/scripts/azure-pipelines/azure-pipelines.yml @@ -7,59 +7,50 @@ variables: osx-pool: 'PrOsx-2020-09-28' stages: -- stage: check_cxx_formatting - displayName: 'Check the formatting of the C++' +- stage: FormatChecks + displayName: 'Formatting and Documentation Checks' pool: $(windows-pool) jobs: - job: workspace: clean: resources + variables: + - name: VCPKG_DOWNLOADS + value: D:\downloads + - name: DiffFile + value: $(Build.ArtifactStagingDirectory)\format.diff steps: - task: Powershell@2 - displayName: 'Check C++ Formatting' + displayName: 'Format C++' inputs: - filePath: 'scripts/azure-pipelines/windows/Check-CxxFormatting.ps1' + filePath: 'scripts/azure-pipelines/Format-CxxCode.ps1' arguments: '-Root .' pwsh: true -- stage: check_manifest_formatting - displayName: Check the formatting of port manifests - pool: $(windows-pool) - dependsOn: [] - variables: - - name: VCPKG_DOWNLOADS - value: D:\downloads - jobs: - - job: - workspace: - clean: resources - steps: - task: Powershell@2 - displayName: 'Check port manifest Formatting' + displayName: 'Generate Documentation' inputs: - filePath: 'scripts/azure-pipelines/windows/Check-ManifestFormatting.ps1' - arguments: '-Root .' + filePath: 'docs/regenerate.ps1' + arguments: '-VcpkgRoot . -WarningAction Stop' pwsh: true -- stage: check_documentation_generation - displayName: Check if the documentation has been regenerated correctly - pool: $(windows-pool) - dependsOn: [] - jobs: - - job: - workspace: - clean: resources - steps: + - script: .\bootstrap-vcpkg.bat + displayName: 'Build vcpkg' + - script: '.\vcpkg format-manifest --all' + displayName: 'Format Manifests' - task: Powershell@2 - displayName: 'Check documentation generation' + displayName: 'Create Diff' inputs: - filePath: 'scripts/azure-pipelines/windows/Check-CMakeFunctionDocumentation.ps1' - arguments: '-Root .' + filePath: scripts/azure-pipelines/Create-FormatDiff.ps1 + arguments: '-DiffFile $(DiffFile)' pwsh: true -- stage: run_port_ci - displayName: 'Run the Port CI' - dependsOn: - - check_cxx_formatting - - check_manifest_formatting - - check_documentation_generation + - task: PublishBuildArtifacts@1 + condition: failed() + displayName: 'Publish C++ Diff' + inputs: + PathtoPublish: '$(DiffFile)' + ArtifactName: 'format.diff' +- stage: RunPrTests + displayName: 'Run PR Tests:' + dependsOn: FormatChecks jobs: - template: windows/azure-pipelines.yml parameters: diff --git a/scripts/azure-pipelines/windows/Check-CMakeFunctionDocumentation.ps1 b/scripts/azure-pipelines/windows/Check-CMakeFunctionDocumentation.ps1 deleted file mode 100644 index 5505c34017..0000000000 --- a/scripts/azure-pipelines/windows/Check-CMakeFunctionDocumentation.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -[CmdletBinding()] -Param( - [Parameter(Mandatory=$True)] - [string]$Root -) - -if (-not (Test-Path "$Root/.vcpkg-root")) -{ - Write-Error "The vcpkg root was not at $Root" - throw -} - -& "$Root/docs/regenerate.ps1" -VcpkgRoot $Root -WarningAction 'Stop' - -$changedFiles = & "$PSScriptRoot/Get-ChangedFiles.ps1" -Directory "$Root/docs" -if ($null -ne $changedFiles) -{ - $msg = @( - "", - "The documentation files do not seem to have been regenerated.", - "Please re-run `docs/regenerate.ps1`." - ) - $msg += "" - - $msg += "This should produce the following diff:" - $msg += git diff "$Root/docs" - - Write-Error ($msg -join "`n") - throw -} diff --git a/scripts/azure-pipelines/windows/Check-CxxFormatting.ps1 b/scripts/azure-pipelines/windows/Check-CxxFormatting.ps1 deleted file mode 100644 index eaa9e692b0..0000000000 --- a/scripts/azure-pipelines/windows/Check-CxxFormatting.ps1 +++ /dev/null @@ -1,55 +0,0 @@ -[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)) -{ - $clangFormat = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\Llvm\x64\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.", - "See github.com/microsoft/vcpkg/blob/master/docs/maintainers/maintainer-guide.md#vcpkg-internal-code for solution." - ) - $msg += "File list:" - $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 deleted file mode 100644 index 75924c24af..0000000000 --- a/scripts/azure-pipelines/windows/Check-ManifestFormatting.ps1 +++ /dev/null @@ -1,49 +0,0 @@ -[CmdletBinding()] -Param( - [Parameter(Mandatory=$True)] - [string]$Root, - [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 (Test-Path "$Root/vcpkg.exe")) -{ - & "$Root/bootstrap-vcpkg.bat" - if (-not $?) - { - Write-Error "Bootstrapping vcpkg failed" - throw - } -} - -& "$Root/vcpkg.exe" 'format-manifest' '--all' -if (-not $?) -{ - Write-Error "Failed formatting manifests; are they well-formed?" - throw -} - -$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.", - "See github.com/microsoft/vcpkg/blob/master/docs/maintainers/maintainer-guide.md#manifest for solution." - ) - $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 deleted file mode 100644 index e299369a04..0000000000 --- a/scripts/azure-pipelines/windows/Get-ChangedFiles.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -[CmdletBinding()] -Param( - [Parameter(Mandatory=$True)] - [string]$Directory -) - -git status --porcelain $Directory | ForEach-Object { - (-split $_)[1] -}