|
| 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')) |
0 commit comments