forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewDatabaseForRule.ps1
More file actions
53 lines (40 loc) · 1.63 KB
/
NewDatabaseForRule.ps1
File metadata and controls
53 lines (40 loc) · 1.63 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
. "$PSScriptRoot\Get-CompilerExecutable.ps1"
. "$PSScriptRoot\Get-CompilerArgs.ps1"
. "$PSScriptRoot\GetNewDBName.ps1"
function New-Database-For-Rule {
param([Parameter(Mandatory)]
[string]
$RuleName,
[Parameter(Mandatory)]
[string]
$RuleTestDir,
[Parameter(Mandatory)]
[string]
$Configuration,
[Parameter(Mandatory)]
[ValidateSet('c', 'cpp')]
[string]
$Language
)
Write-Host "Creating Database for Rule $RuleName..."
$cppFiles = Get-ChildItem $RuleTestDir/*.c*
$cppFilesString = ([String]::Join(' ', $cppFiles))
Write-Host "Found '.cpp' files $cppFilesString."
$CompilerExecutable = Get-CompilerExecutable -Configuration $Configuration -Language $Language
$CompilerArgs = Get-CompilerArgs -Configuration $Configuration -Language $Language
$BUILD_COMMAND = "$CompilerExecutable $CompilerArgs $cppFilesString"
if ($UseTmpDir) {
$DB_PATH = Get-New-DB-Name
}
else {
$DB_PATH = Get-New-DB-Name -Dir $RuleTestDir
}
Write-Host "codeql database create -l cpp -s $RuleTestDir --command='$BUILD_COMMAND' $DB_PATH"
$stdOut = Join-Path ([System.IO.Path]::GetTempPath()) ([System.Guid]::NewGuid())
$procDetails = Start-Process -FilePath "codeql" -RedirectStandardOutput $stdOut -PassThru -NoNewWindow -Wait -ArgumentList "database create -l cpp -s $RuleTestDir --command=`"$BUILD_COMMAND`" $DB_PATH"
Get-Content $stdOut | Out-String | Write-Host
if (-Not $procDetails.ExitCode -eq 0) {
throw Get-Content $stdOut | Out-String
}
return $DB_PATH
}