@@ -142,7 +142,7 @@ param(
142
142
143
143
# The compiler to use. Valid values are 'clang' and 'arm-clang'.
144
144
[Parameter (Mandatory )]
145
- [ValidateSet (' clang' , ' armclang' , ' tiarmclang' )]
145
+ [ValidateSet (' clang' , ' armclang' , ' tiarmclang' , ' gcc ' )]
146
146
[string ]
147
147
$Configuration ,
148
148
@@ -283,6 +283,9 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel
283
283
# . "$using:PSScriptRoot/GetTestDirectory.ps1"
284
284
. " $using :PSScriptRoot /NewDatabaseForRule.ps1"
285
285
. " $using :PSScriptRoot /ExecuteQueryAndDecodeAsJson.ps1"
286
+ . " $using :PSScriptRoot /Get-CompilerSpecificFiles.ps1"
287
+ . " $using :PSScriptRoot /Pop-CompilerSpecificFiles.ps1"
288
+ . " $using :PSScriptRoot /Push-CompilerSpecificFiles.ps1"
286
289
287
290
$q = $_
288
291
@@ -314,82 +317,100 @@ $jobRows = $queriesToCheck | ForEach-Object -ThrottleLimit $NumThreads -Parallel
314
317
315
318
$testDirectory = (Get-TestDirectory - RuleObject $q - Language $using :Language )
316
319
317
- Write-Host " Compiling database in $testDirectory ..." - NoNewline
318
-
319
320
try {
320
- $db = New-Database - For- Rule - RuleName $CurrentRuleName - RuleTestDir $testDirectory - Configuration $using :Configuration - Language $using :Language
321
- Write-Host - ForegroundColor ([ConsoleColor ]2 ) " OK"
322
- }
323
- catch {
324
- Write-Host - ForegroundColor ([ConsoleColor ]4 ) " FAILED"
325
- $row [" COMPILE_ERROR_OUTPUT" ] = $_
326
-
327
- return $row # although it is unlikely to succeed with the next rule skipping to the next rule
328
- # ensures all of the rules will be reported in the
329
- # output.
330
- }
331
-
332
- $row [" COMPILE_PASS" ] = $true
333
-
334
- Write-Host " Checking expected output..."
335
-
336
- # Dragons below 🐉🐉🐉
337
- #
338
- # Note this technique uses so-called "wizard" settings to make it possible
339
- # to compare hand compiled databases using qltest. The relative paths and
340
- # other options are required to be set as below (especially the detail about
341
- # the relative path of the dataset and the test).
342
-
343
- # the "dataset" should be the `db-cpp` directory inside the database
344
- # directory. HOWEVER. It should be the path relative to the test directory.
345
-
346
- $rulePath = Resolve-Path $testDirectory
347
- $dbPath = Resolve-Path $db
348
-
349
- Write-Host " Resolving database $dbPath relative to test directory $rulePath "
350
- $dataset = Resolve-Path (Join-Path $dbPath " db-cpp" )
351
-
352
- Push-Location $rulePath
353
- $datasetRelPath = Resolve-Path - Relative $dataset
354
- Pop-Location
355
-
356
- Write-Host " Using relative path: $datasetRelPath "
357
-
358
- # Actually do the qltest run.
359
- # codeql test run <qltest file> --dataset "relpath"
360
-
361
- if ($q.shared_implementation_short_name ) {
362
- $qlRefFile = Join-Path $rulePath " $ ( $q.shared_implementation_short_name ) .ql"
363
- }
364
- else {
365
- $qlRefFile = Join-Path $rulePath " $CurrentQueryName .qlref"
366
- }
367
-
368
- Write-Host " codeql test run $qlRefFile --dataset=`" $datasetRelPath `" "
369
-
370
- $stdOut = Join-Path ([System.IO.Path ]::GetTempPath()) ([System.Guid ]::NewGuid())
371
- $stdErr = Join-Path ([System.IO.Path ]::GetTempPath()) ([System.Guid ]::NewGuid())
372
-
373
-
374
- Write-Host " Standard Out Buffered to: $stdOut "
375
- Write-Host " Standard Error Buffered to: $stdErr "
376
-
377
- $procDetails = Start-Process - FilePath " codeql" - PassThru - NoNewWindow - Wait - ArgumentList " test run $qlRefFile --dataset=`" $datasetRelPath `" " - RedirectStandardOutput $stdOut - RedirectStandardError $stdErr
378
-
379
- if (-Not $procDetails.ExitCode -eq 0 ) {
380
-
381
- Write-Host - ForegroundColor ([ConsoleColor ]4 ) " FAILED"
382
- Get-Content $stdOut | Out-String | Write-Host
383
-
384
- $row [" TEST_DIFFERENCE" ] = Get-Content $stdOut | Out-String
321
+ # ##########################################################
322
+ # ##########################################################
323
+ # Push context
324
+ # ##########################################################
325
+ $context = Push-CompilerSpecificFiles - Configuration $using :Configuration - Language $using :Language - FileSet (Get-CompilerSpecificFiles - TestDirectory $testDirectory )
326
+
327
+ Write-Host " Compiling database in $testDirectory ..." - NoNewline
328
+
329
+ try {
330
+ $db = New-Database - For- Rule - RuleName $CurrentRuleName - RuleTestDir $testDirectory - Configuration $using :Configuration - Language $using :Language
331
+ Write-Host - ForegroundColor ([ConsoleColor ]2 ) " OK"
332
+ }
333
+ catch {
334
+ Write-Host - ForegroundColor ([ConsoleColor ]4 ) " FAILED"
335
+ $row [" COMPILE_ERROR_OUTPUT" ] = $_
336
+
337
+ return $row # although it is unlikely to succeed with the next rule skipping to the next rule
338
+ # ensures all of the rules will be reported in the
339
+ # output.
340
+ }
341
+
342
+ $row [" COMPILE_PASS" ] = $true
343
+
344
+ Write-Host " Checking expected output..."
345
+
346
+ # Dragons below 🐉🐉🐉
347
+ #
348
+ # Note this technique uses so-called "wizard" settings to make it possible
349
+ # to compare hand compiled databases using qltest. The relative paths and
350
+ # other options are required to be set as below (especially the detail about
351
+ # the relative path of the dataset and the test).
352
+
353
+ # the "dataset" should be the `db-cpp` directory inside the database
354
+ # directory. HOWEVER. It should be the path relative to the test directory.
355
+
356
+ $rulePath = Resolve-Path $testDirectory
357
+ $dbPath = Resolve-Path $db
358
+
359
+ Write-Host " Resolving database $dbPath relative to test directory $rulePath "
360
+ $dataset = Resolve-Path (Join-Path $dbPath " db-cpp" )
361
+
362
+ Push-Location $rulePath
363
+ $datasetRelPath = Resolve-Path - Relative $dataset
364
+ Pop-Location
365
+
366
+ Write-Host " Using relative path: $datasetRelPath "
367
+
368
+ # Actually do the qltest run.
369
+ # codeql test run <qltest file> --dataset "relpath"
370
+
371
+ if ($q.shared_implementation_short_name ) {
372
+ $qlRefFile = Join-Path $rulePath " $ ( $q.shared_implementation_short_name ) .ql"
373
+ }
374
+ else {
375
+ $qlRefFile = Join-Path $rulePath " $CurrentQueryName .qlref"
376
+ }
377
+
378
+ Write-Host " codeql test run $qlRefFile --dataset=`" $datasetRelPath `" "
379
+
380
+ $stdOut = Join-Path ([System.IO.Path ]::GetTempPath()) ([System.Guid ]::NewGuid())
381
+ $stdErr = Join-Path ([System.IO.Path ]::GetTempPath()) ([System.Guid ]::NewGuid())
382
+
383
+
384
+ Write-Host " Standard Out Buffered to: $stdOut "
385
+ Write-Host " Standard Error Buffered to: $stdErr "
386
+
387
+ $procDetails = Start-Process - FilePath " codeql" - PassThru - NoNewWindow - Wait - ArgumentList " test run $qlRefFile --dataset=`" $datasetRelPath `" " - RedirectStandardOutput $stdOut - RedirectStandardError $stdErr
388
+
389
+ if (-Not $procDetails.ExitCode -eq 0 ) {
390
+
391
+ Write-Host - ForegroundColor ([ConsoleColor ]4 ) " FAILED"
392
+ Get-Content $stdOut | Out-String | Write-Host
393
+
394
+ $row [" TEST_DIFFERENCE" ] = Get-Content $stdOut | Out-String
395
+
396
+ }
397
+ else {
398
+ $row [" TEST_PASS" ] = $true
399
+ Write-Host - ForegroundColor ([ConsoleColor ]2 ) " OK"
400
+ }
401
+
402
+ return $row
403
+ }catch {
404
+ Write-Host " Unknown error processing rule."
405
+ return $row
406
+ }finally {
385
407
408
+ # ##########################################################
409
+ # ##########################################################
410
+ # Context is restored here
411
+ # ##########################################################
412
+ Pop-CompilerSpecificFiles - Context $context
386
413
}
387
- else {
388
- $row [" TEST_PASS" ] = $true
389
- Write-Host - ForegroundColor ([ConsoleColor ]2 ) " OK"
390
- }
391
-
392
- return $row
393
414
}
394
415
395
416
# combine the outputs
0 commit comments