Skip to content

Commit 70b85a3

Browse files
authored
Merge pull request github#12431 from igfoo/igfoo/double_interception
Kotlin: Test double interceptions
2 parents 705691b + 4fbc747 commit 70b85a3

File tree

9 files changed

+55
-0
lines changed

9 files changed

+55
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
3+
import glob
4+
import os
5+
import re
6+
from create_database_utils import *
7+
8+
def say(s):
9+
print(s)
10+
sys.stdout.flush()
11+
12+
say('Doing normal compilation')
13+
# This is a normal intercepted compilation
14+
runSuccessfully([get_cmd('kotlinc'), 'normal.kt'])
15+
16+
say('Identifying extractor jar')
17+
# Find the extractor jar that is being used
18+
trapDir = os.environ['CODEQL_EXTRACTOR_JAVA_TRAP_DIR']
19+
invocationTrapDir = os.path.join(trapDir, 'invocations')
20+
invocationTraps = os.listdir(invocationTrapDir)
21+
if len(invocationTraps) != 1:
22+
raise Exception('Expected to find 1 invocation TRAP, but found ' + str(invocationTraps))
23+
invocationTrap = os.path.join(invocationTrapDir, invocationTraps[0])
24+
with open(invocationTrap, 'r') as f:
25+
content = f.read()
26+
m = re.search('^// Using extractor: (.*)$', content, flags = re.MULTILINE)
27+
extractorJar = m.group(1)
28+
29+
def getManualFlags(invocationTrapName):
30+
return ['-Xplugin=' + extractorJar, '-P', 'plugin:kotlin-extractor:invocationTrapFile=' + os.path.join(trapDir, 'invocations', invocationTrapName + '.trap')]
31+
32+
# This is both normally intercepted, and it has the extractor flags manually added
33+
say('Doing double-interception compilation')
34+
runSuccessfully([get_cmd('kotlinc'), 'doubleIntercepted.kt'] + getManualFlags('doubleIntercepted'))
35+
os.environ['CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN'] = 'true'
36+
# We don't see this compilation at all
37+
say('Doing unseen compilation')
38+
runSuccessfully([get_cmd('kotlinc'), 'notSeen.kt'])
39+
# This is extracted as it has the extractor flags manually added
40+
say('Doing manual compilation')
41+
runSuccessfully([get_cmd('kotlinc'), 'manual.kt'] + getManualFlags('manual'))

java/ql/integration-tests/posix-only/kotlin/kotlin_double_interception/code/doubleIntercepted.kt

Whitespace-only changes.

java/ql/integration-tests/posix-only/kotlin/kotlin_double_interception/code/manual.kt

Whitespace-only changes.

java/ql/integration-tests/posix-only/kotlin/kotlin_double_interception/code/manuallyIntercepted.kt

Whitespace-only changes.

java/ql/integration-tests/posix-only/kotlin/kotlin_double_interception/code/normal.kt

Whitespace-only changes.

java/ql/integration-tests/posix-only/kotlin/kotlin_double_interception/code/notSeen.kt

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| code/doubleIntercepted.kt:0:0:0:0 | doubleIntercepted |
2+
| code/manual.kt:0:0:0:0 | manual |
3+
| code/normal.kt:0:0:0:0 | normal |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import java
2+
3+
from File f
4+
select f
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import sys
2+
3+
from create_database_utils import *
4+
5+
run_codeql_database_create(
6+
['"%s" build.py' % sys.executable],
7+
source="code", lang="java")

0 commit comments

Comments
 (0)