-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathCompileFixTool.ps1
More file actions
executable file
·153 lines (115 loc) · 4.04 KB
/
CompileFixTool.ps1
File metadata and controls
executable file
·153 lines (115 loc) · 4.04 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env pwsh
param(
# path to the matrix file.
[Parameter(Mandatory)]
[string]
$MatrixReport,
[Parameter(Mandatory = $false)]
[string]
$ReportDir = (Get-Location),
[Parameter(Mandatory)]
[ValidateSet('c', 'cpp')]
[string]
$Language,
# The compiler to use.
[Parameter(Mandatory)]
[ValidateSet('clang', 'armclang', 'tiarmclang', 'gcc', 'qcc')]
[string]
$Configuration
)
Import-Module -Name "$PSScriptRoot/../PSCodingStandards/CodingStandards"
. "$PSScriptRoot/NewDatabaseForRule.ps1"
. "$PSScriptRoot/Config.ps1"
. "$PSScriptRoot/Get-CompilerExecutable.ps1"
#
# Verify All the Required CLI Tools are Installed
#
Write-Host "Checking 'codeql' program...." -NoNewline
Test-ProgramInstalled -Program "codeql"
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
$CODEQL_VERSION = (codeql version --format json | ConvertFrom-Json).version
Write-Host "Checking 'codeql' version = $REQUIRED_CODEQL_VERSION...." -NoNewline
if (-Not ($CODEQL_VERSION -eq $REQUIRED_CODEQL_VERSION)) {
throw "Invalid CodeQL version $CODEQL_VERSION. Please install $REQUIRED_CODEQL_VERSION."
}
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
Write-Host "Checking '$(Get-CompilerExecutable -Configuration $Configuration -Language $Language)' program...." -NoNewline
Test-ProgramInstalled -Program (Get-CompilerExecutable -Configuration $Configuration -Language $Language)
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
$allQueries = @()
# load all the queries
foreach ($s in $AVAILABLE_SUITES) {
$allQueries += Get-RulesInSuite -Suite $s -Language $Language
}
$csv = Import-CSV $MatrixReport
# filter down to the rows that failed
$failedQueries = $csv | Where-Object { $_.COMPILE_PASS -eq $false }
$PROMPT = @"
################ COMPILE FAILED FOR QUERY {0} ################
Suite : {1}
Package : {2}
Rule : {3}
Path to test : {4} [ctrl+click to edit]
You may attempt to fix the file and recompile using this tool
iteratively.
Queries Currently in Triage: {5}
This is Query {6} of {7}
-------------------------------------------------------------
Action(1=Attempt Compile, 2=Next, 3=Add to Triage, 4=Save Progress and Write Triage Report)
"@
function Get-Query-From-Name {
param(
[Parameter(Mandatory)]
[array]
$AllQueries,
[Parameter(Mandatory)]
[string]
$RuleName
)
foreach ($q in $AllQueries) {
if ($q.short_name -eq $RuleName) {
return $q
}
}
throw "Cannot find query $RuleName."
}
$TRIAGE = @()
$ctr = 0
:ctrl foreach ($row in $failedQueries) {
$ctr += 1
while ($true) {
$q = Get-Query-From-Name -AllQueries $allQueries -RuleName $row.QUERY
$testDirectory = (Get-TestDirectory -RuleObject $q -Language $Language)
$testPath = Join-Path $testDirectory "test.cpp"
$P = $PROMPT -f $row.QUERY, $row.SUITE, $row.PACKAGE, $row.RULE, $testPath, $TRIAGE.Length, $ctr, $failedQueries.Length
$cmd = Read-Host -Prompt $P
if ($cmd -eq "1") {
try {
New-Database-For-Rule -RuleName $row.RULE -RuleTestDir $testDirectory -Configuration $Configuration -Language $Language
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
}
catch {
Write-Host -ForegroundColor ([ConsoleColor]4) "FAILED"
}
}
if ($cmd -eq "2") {
break
}
if ($cmd -eq "3") {
$TRIAGE += $row
break
}
if ($cmd -eq "4") {
$TRIAGE += $row
break ctrl
}
}
}
# write out the triage report
$fileTag = "$($Configuration.ToLower())-$(Get-Date -Format "yyyy-MM-dd_HH-mm-ss")"
$reportOutputFile = Join-Path $ReportDir "CompileTriageReport-$fileTag.csv"
# Write out the detailed report
Write-Host "Writing detailed triage report to $reportOutputFile"
foreach ($r in $TRIAGE) {
[PSCustomObject]$r | Export-CSV -Path $reportOutputFile -Append -NoTypeInformation
}