-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuppress-warnings.ps1
114 lines (100 loc) · 3 KB
/
suppress-warnings.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -NoProfile
function GetFullPath($filename)
{
if ([System.IO.Path]::IsPathRooted($filename))
{
[System.IO.Path]::GetFullPath($filename)
}
else
{
[System.IO.Path]::GetFullPath((Join-Path (pwd) $filename))
}
}
# Why ish? See http://pdh11.blogspot.co.uk/2009/05/pathcanonicalize-versus-what-it-says-on.html
function GetCanonicalishPath($file, $proj)
{
if (![System.IO.Path]::IsPathRooted($file))
{
$proj = GetFullPath $proj
$projdir = [System.IO.Path]::GetDirectoryName($proj)
$file = "$projdir\$file"
}
else
{
$file = GetFullPath $file
}
$file.ToLower()
}
function ReadErrorLog($logLines)
{
$files = @{}
$logLines |
foreach {
$_ -match '^(.*)\(([^\)]*)\):.*\[([^]]*)\]$' > $null
$file, $line, $proj = $Matches[1], $Matches[2], $Matches[3]
$file = GetCanonicalishPath $file $proj
if (!$files.contains($file))
{
$files[$file] = @()
}
if (!$files[$file].contains($line))
{
$files[$file] += [int]$line
}
}
$files
}
function GetEncoding($filename)
{
[byte[]]$byte = get-content -Encoding byte -ReadCount 4 -TotalCount 4 $filename
if ($byte.Count -eq 4 -and $byte[0] -eq 0xef -and $byte[1] -eq 0xbb -and $byte[2] -eq 0xbf){
[System.Text.Encoding]::GetEncoding('utf-8')
}
else {
[System.Text.Encoding]::GetEncoding('iso-8859-1')
}
}
function InsertLegacyMarker($file, $lines, $legacyHeaderDir, $legacyMarker)
{
$encoding = GetEncoding $file
$fileContents = [System.IO.File]::ReadAllLines($file, $encoding)
$includeWildcard = "#include `"${legacyHeaderDir}/*"
$totalIncludes = ($fileContents | where { $_ -like $includeWildcard }).count
if ($totalIncludes -eq 0)
{
$includeWildcard = '#include "*'
$totalIncludes = ($fileContents | where { $_ -like $includeWildcard }).count
}
$line = 1
$includes = 0
$newContents = $fileContents | foreach {
if ($lines.contains($line))
{
$_ -match '^(\s*)' > $null
$Matches[1] + $legacyMarker
}
$_
if ($_ -like $includeWildcard)
{
++$includes
if ($includes -eq $totalIncludes)
{
"#include `"$legacyHeaderDir/LegacyCodeCompilerWarnings.hpp`""
}
}
++$line
}
[System.IO.File]::WriteAllLines($file, $newContents, $encoding)
}
$legacyHeaderDir, $legacyMarker, $logFile = @($args)
$logLines = $input
if ($logFile -ne $null)
{
$logLines = Get-Content $logFile
}
$files = ReadErrorLog $logLines
foreach ($entry in $files.GetEnumerator())
{
$entry.Name
InsertLegacyMarker $entry.Name $entry.Value $legacyHeaderDir $legacyMarker
}