Merge pull request #12431 from igfoo/igfoo/double_interception

Kotlin: Test double interceptions
This commit is contained in:
Ian Lynagh
2023-03-13 14:30:49 +00:00
committed by GitHub
9 changed files with 55 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
#!/usr/bin/env python3
import glob
import os
import re
from create_database_utils import *
def say(s):
print(s)
sys.stdout.flush()
say('Doing normal compilation')
# This is a normal intercepted compilation
runSuccessfully([get_cmd('kotlinc'), 'normal.kt'])
say('Identifying extractor jar')
# Find the extractor jar that is being used
trapDir = os.environ['CODEQL_EXTRACTOR_JAVA_TRAP_DIR']
invocationTrapDir = os.path.join(trapDir, 'invocations')
invocationTraps = os.listdir(invocationTrapDir)
if len(invocationTraps) != 1:
raise Exception('Expected to find 1 invocation TRAP, but found ' + str(invocationTraps))
invocationTrap = os.path.join(invocationTrapDir, invocationTraps[0])
with open(invocationTrap, 'r') as f:
content = f.read()
m = re.search('^// Using extractor: (.*)$', content, flags = re.MULTILINE)
extractorJar = m.group(1)
def getManualFlags(invocationTrapName):
return ['-Xplugin=' + extractorJar, '-P', 'plugin:kotlin-extractor:invocationTrapFile=' + os.path.join(trapDir, 'invocations', invocationTrapName + '.trap')]
# This is both normally intercepted, and it has the extractor flags manually added
say('Doing double-interception compilation')
runSuccessfully([get_cmd('kotlinc'), 'doubleIntercepted.kt'] + getManualFlags('doubleIntercepted'))
os.environ['CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN'] = 'true'
# We don't see this compilation at all
say('Doing unseen compilation')
runSuccessfully([get_cmd('kotlinc'), 'notSeen.kt'])
# This is extracted as it has the extractor flags manually added
say('Doing manual compilation')
runSuccessfully([get_cmd('kotlinc'), 'manual.kt'] + getManualFlags('manual'))

View File

@@ -0,0 +1,3 @@
| code/doubleIntercepted.kt:0:0:0:0 | doubleIntercepted |
| code/manual.kt:0:0:0:0 | manual |
| code/normal.kt:0:0:0:0 | normal |

View File

@@ -0,0 +1,4 @@
import java
from File f
select f

View File

@@ -0,0 +1,7 @@
import sys
from create_database_utils import *
run_codeql_database_create(
['"%s" build.py' % sys.executable],
source="code", lang="java")