mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-27 18:31:15 +08:00
[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
This commit is contained in:
parent
d52fbe6a45
commit
30767175d5
0
format.diff
Normal file
0
format.diff
Normal file
20
scripts/azure-pipelines/Create-FormatDiff.ps1
Normal file
20
scripts/azure-pipelines/Create-FormatDiff.ps1
Normal file
@ -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
|
||||
}
|
49
scripts/azure-pipelines/Format-CxxCode.ps1
Normal file
49
scripts/azure-pipelines/Format-CxxCode.ps1
Normal file
@ -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
|
||||
}
|
@ -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:
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$True)]
|
||||
[string]$Directory
|
||||
)
|
||||
|
||||
git status --porcelain $Directory | ForEach-Object {
|
||||
(-split $_)[1]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user