Skip to content

Commit a85c43a

Browse files
authored
Merge pull request #234 from github/jsinglet/compiler-path-fix
small enhancement to make rules that don't match not appear
2 parents 3b17207 + a132ef4 commit a85c43a

File tree

5 files changed

+49
-9
lines changed

5 files changed

+49
-9
lines changed

scripts/PSCodingStandards/Get-RuleForPath.ps1

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ function Get-RuleForPath {
4141
$allQueries = @()
4242
$queriesToCheck = @()
4343

44-
# load all the queries
44+
4545
foreach ($s in $AVAILABLE_SUITES) {
4646
$allQueries += Get-RulesInSuite -Suite $s -Language $Language
4747
}
4848

49+
4950
$modifiedPathWithReplacement = Join-Path (Resolve-Path . -Relative) $Path
5051
# replace "src" with "test" to make it match up
5152
$sep = [IO.Path]::DirectorySeparatorChar
@@ -57,20 +58,18 @@ function Get-RuleForPath {
5758

5859
# for each query, create the test directory
5960
foreach($q in $allQueries){
60-
6161
# get test directory
6262
$testDirs = (Get-ATestDirectory -RuleObject $q -Language $Language)
6363
foreach($testDirectory in $testDirs){
6464
# resolve path to be compatible
65-
$testPath = Join-Path (Resolve-Path . -Relative) $testDirectory
65+
$testPath = (Join-Path (Resolve-Path . -Relative) $testDirectory)
6666

67-
# see if the TEST directory is a substring of the full path
68-
if($modifiedPath.StartsWith($testPath)){
67+
if((Split-Path $modifiedPath -Parent) -eq $testPath){
6968
$matchingRules += $q
7069
continue
7170
}
7271

73-
if($modifiedPathWithReplacement.StartsWith($testPath)){
72+
if((Split-Path $modifiedPathWithReplacement -Parent) -eq $testPath){
7473
$matchingRules += $q
7574
continue
7675
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function Test-GetRuleForPath {
2+
param(
3+
[Parameter(Mandatory)]
4+
[string]
5+
$PR
6+
)
7+
8+
$prData = (gh pr view -R github/codeql-coding-standards $PR --json headRefOid,headRepository,author,isCrossRepository,headRepositoryOwner,headRefName,files) | ConvertFrom-Json
9+
10+
foreach($f in $prData.files){
11+
try {
12+
Write-Host "[C] Scanning file for relationship $($f.path)..."
13+
$rulesToTest = Get-RuleForPath -Language c -Path "$($f.path)"
14+
15+
Write-Host "[C] Got $($rulesToTest.Count) potential C rules..."
16+
17+
foreach($r in $rulesToTest){
18+
$ruleNames += $r.__memberof_rule
19+
Write-Host "[C] Found rule $r "
20+
}
21+
}catch{
22+
Write-Host "No $Language rules found for path: $($f.path)"
23+
}
24+
25+
26+
try {
27+
Write-Host "[CPP] Scanning file for relationship $($f.path)..."
28+
$rulesToTest = Get-RuleForPath -Language cpp -Path "$($f.path)"
29+
30+
Write-Host "[CPP] Got $($rulesToTest.Count) potential CPP rules..."
31+
32+
foreach($r in $rulesToTest){
33+
Write-Host "[CPP] Found rule $r "
34+
}
35+
}catch{
36+
Write-Host "No CPP rules found for path: $($f.path)"
37+
}
38+
}
39+
}

scripts/matrix_testing/CompileFixTool.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
3737
$CODEQL_VERSION = (codeql version --format json | ConvertFrom-Json).version
3838

3939
Write-Host "Checking 'codeql' version = $REQUIRED_CODEQL_VERSION...." -NoNewline
40-
if (-Not $CODEQL_VERSION -eq $REQUIRED_CODEQL_VERSION) {
40+
if (-Not ($CODEQL_VERSION -eq $REQUIRED_CODEQL_VERSION)) {
4141
throw "Invalid CodeQL version $CODEQL_VERSION. Please install $REQUIRED_CODEQL_VERSION."
4242
}
4343
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"

scripts/matrix_testing/Config.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Import-Module -Name "$PSScriptRoot/../PSCodingStandards/CodingStandards"
2+
13
$COMPILER_MAPPINGS = @{
24
"cpp" = @{
35
"clang" = "clang++";
@@ -27,7 +29,7 @@ $COMPILER_ARGS = @{
2729

2830
}
2931

30-
$REQUIRED_CODEQL_VERSION = "2.6.3"
32+
$REQUIRED_CODEQL_VERSION = (Get-Content (Join-Path (Get-RepositoryRoot) "supported_codeql_configs.json") | ConvertFrom-Json).supported_environment.codeql_cli
3133

3234

3335
$REPORT_QUERY = @"

scripts/matrix_testing/CreateMatrixTestReport.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Write-Host -ForegroundColor ([ConsoleColor]2) "OK"
262262
$CODEQL_VERSION = (codeql version --format json | ConvertFrom-Json).version
263263

264264
Write-Host "Checking 'codeql' version = $REQUIRED_CODEQL_VERSION...." -NoNewline
265-
if (-Not $CODEQL_VERSION -eq $REQUIRED_CODEQL_VERSION) {
265+
if (-Not ($CODEQL_VERSION -eq $REQUIRED_CODEQL_VERSION)) {
266266
throw "Invalid CodeQL version $CODEQL_VERSION. Please install $REQUIRED_CODEQL_VERSION."
267267
}
268268
Write-Host -ForegroundColor ([ConsoleColor]2) "OK"

0 commit comments

Comments
 (0)