chore(tools): improve run-clang-tidy script

This commit is contained in:
Oleg Shparber
2026-04-04 23:40:12 +03:00
parent 729ebf9eee
commit 80d51beb99
+22 -9
View File
@@ -6,6 +6,11 @@
#
# By default, uses the project's .clang-tidy configuration.
# Use -Check <name> to run a specific check (e.g., -Check readability-qualified-auto).
# Also supports clang-diagnostic-* checks (e.g., -Check clang-diagnostic-shadow).
#
# Check lists:
# clang-tidy checks: https://clang.llvm.org/extra/clang-tidy/checks/list.html
# clang diagnostics: https://clang.llvm.org/docs/DiagnosticsReference.html
# Use -Fix to apply suggested fixes.
# Use -Staged to only process files staged for commit.
# Use -Verbose to print each file being processed.
@@ -31,7 +36,14 @@ $buildDir = Resolve-Path $buildDir
$tidyArgs = @("-p", $buildDir)
if ($Check) {
$tidyArgs += "--config={Checks: '-*,$Check', HeaderFilterRegex: 'src/.*'}"
if ($Check -match '^clang-diagnostic-(.+)$') {
# clang-diagnostic-* checks can't be enabled via Checks; use a no-op check
# as a placeholder and enable the compiler warning via -extra-arg.
$tidyArgs += "--config={Checks: '-*,android-cloexec-accept', HeaderFilterRegex: 'src/.*'}"
$tidyArgs += "-extra-arg=-W$($Matches[1])"
} else {
$tidyArgs += "--config={Checks: '-*,$Check', HeaderFilterRegex: 'src/.*'}"
}
}
if ($Fix) {
$tidyArgs += "--fix"
@@ -39,14 +51,20 @@ if ($Fix) {
$srcDir = Join-Path -Path $PSScriptRoot -ChildPath "..\src"
# Only process files present in compile_commands.json to skip platform-specific files.
$compileDb = Get-Content "$buildDir/compile_commands.json" | ConvertFrom-Json
$dbFiles = $compileDb | ForEach-Object { [System.IO.Path]::GetFullPath($_.file) }
if ($Staged) {
$files = git diff --cached --name-only --diff-filter=ACMR -- "*.cpp" |
ForEach-Object { Join-Path -Path $PSScriptRoot -ChildPath ".." -AdditionalChildPath $_ } |
Where-Object { Test-Path $_ }
Where-Object { Test-Path $_ } |
ForEach-Object { [System.IO.Path]::GetFullPath($_) } |
Where-Object { $_ -in $dbFiles }
} else {
$excludeDir = Join-Path -Path $srcDir -ChildPath "contrib"
$files = Get-ChildItem -Recurse $srcDir -Include *.cpp |
Where-Object { -not $_.FullName.StartsWith($excludeDir) } |
Where-Object { -not $_.FullName.StartsWith($excludeDir) -and $_.FullName -in $dbFiles } |
Select-Object -ExpandProperty FullName
}
@@ -55,15 +73,10 @@ if (-not $files) {
exit 0
}
$failed = $false
foreach ($file in $files) {
Write-Verbose "Processing $file"
& clang-tidy @tidyArgs $file
if ($LASTEXITCODE -ne 0) {
$failed = $true
exit 1
}
}
if ($failed) {
exit 1
}