Created
November 8, 2016 05:58
-
-
Save BrukerJWD/57e1d5317c809f6578a90a594380de93 to your computer and use it in GitHub Desktop.
Wrapper for include-what-you-use which inspects all cpps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string]$Dir = ".", | |
[string]$Filter = "*.cpp" | |
) | |
$ErrorActionPreference = "Stop" | |
$iwyu = "\path\to\bin\include-what-you-use.exe" | |
# Retreive the version of Visual Studio | |
$bbp = (get-item env:BUILD_PLATFORM).Value # win32-vc110, ... | |
$bbp = $bbp.Split("-vc").get(3) # 110 | |
$bbp = $bbp.substring(0,2) + "." + $bbp.substring(2,1) # 11.0 | |
# Retreive the inlcude directories from vcxproj files | |
$includes = New-Object System.Collections.ArrayList | |
Get-ChildItem $dir\build\*\*\* -Filter *.vcxproj | ForEach-Object { | |
([XML](Get-Content -Path $_)).Project.ItemDefinitionGroup | Select -ExpandProperty childnodes | where {$_.name -like 'ClCompile'} | Select -ExpandProperty childnodes | where {$_.name -like 'AdditionalIncludeDirectories'} | ForEach-Object { | |
$_.InnerText.Split(";") | ForEach-Object { | |
[void]$includes.Add($_) | |
} | |
} | |
} | |
$includes = $includes | Sort | Get-Unique | |
$includes = $includes[1..($includes.length-1)] # Remove first element | |
#create the argument list | |
$arguments = """-F$env:ProgramFiles (x86)\Microsoft SDKs\Windows\v7.1A\Include"" " | |
$arguments += """-F$env:ProgramFiles (x86)\Microsoft Visual Studio " + $bbp + "\VC\include"" " | |
$arguments += """-F$env:ProgramFiles (x86)\Microsoft Visual Studio " + $bbp + "\VC\atlmfc\include"" " | |
$arguments += """-I" + ($includes -Join """ ""-I") + """ " | |
$arguments += "-Xiwyu --mapping_file=$iwyu\..\..\vs.imp " # path to mapping file | |
$arguments += "-DWIN32 -DNDEBUG -D_WINDOWS -D_USRDLL " | |
$arguments += "-w -x c++ -std=c++11 -fcxx-exceptions -fexceptions -fms-compatibility -fms-extensions -fmsc-version=1600 -Wno-invalid-token-paste " | |
$arguments += "-Xiwyu --verbose=2 -Xiwyu --transitive_includes_only " | |
Write-Host $arguments | |
[void]$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | |
$files = Get-ChildItem $dir\src\*\*, $dir\src\*\*\*,$dir\src\*\*\*\* -Filter $Filter | |
for ($f = 0; $f -lt $files.Count; $f++) { | |
$file = $files[$f] | |
[System.Console]::Clear() | |
Write-Host $file.Name | |
& $iwyu $arguments $file.FullName | |
if ($host.Name -eq "ConsoleHost") { | |
Write-Host "Press r to repeat and space to continue ..." -ForegroundColor "green" | |
$key = $true | |
while ($key) { | |
switch ($host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").Character) { | |
'r' { $f--; $key = $false } | |
' ' { $key = $false } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment