check_prefast_error.ps1 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #-------------------------------------------------------------------------------------------------------
  2. # Copyright (C) Microsoft. All rights reserved.
  3. # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. #-------------------------------------------------------------------------------------------------------
  5. param (
  6. [string]$directory,
  7. [string]$logFile = ""
  8. )
  9. . "$PSScriptRoot\util.ps1"
  10. if ((Test-Path $directory) -eq 0) {
  11. Write-Error ("ERROR: Directory {0} does not exist. Cannot scan for prefast defects" -f $directory);
  12. Exit(-1)
  13. }
  14. if (Test-Path -Path $logFile) {
  15. Remove-Item $logFile -Force
  16. }
  17. # load all prefast results
  18. $files = Get-ChildItem -recurse ("{0}\vc.nativecodeanalysis.all.xml" -f $directory)
  19. $filecount = 0;
  20. $count = 0;
  21. foreach ($file in $files) {
  22. $filecount++;
  23. [xml]$x = Get-Content $file
  24. foreach ($d in $x.DEFECTS.DEFECT) {
  25. WriteErrorMessage ("{0}{1}({2}): warning C{3}: {4}" -f $d.SFA.FILEPATH, $d.SFA.FILENAME, $d.SFA.LINE, $d.DEFECTCODE, $d.DESCRIPTION)
  26. $count++;
  27. }
  28. }
  29. if ($count -ne 0) {
  30. WriteErrorMessage ("ERROR: {0} prefast warning detected" -f $count)
  31. } elseif ($filecount -ne 0) {
  32. WriteMessage "No prefast warning detected"
  33. } else {
  34. WriteMessage "No prefast result found"
  35. }
  36. exit $count