mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge pull request #15477 from igfoo/igfoo/kot_path_trans
Kotlin: Add path transformer support
This commit is contained in:
@@ -2,6 +2,7 @@ package com.github.codeql
|
||||
|
||||
import com.github.codeql.utils.versions.usesK2
|
||||
import com.semmle.util.files.FileUtil
|
||||
import com.semmle.util.trap.pathtransformers.PathTransformer
|
||||
import java.io.BufferedInputStream
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.BufferedReader
|
||||
@@ -371,9 +372,9 @@ private fun doFile(
|
||||
context.clear()
|
||||
}
|
||||
|
||||
val srcFileRelativePath = srcFilePath.replace(':', '_')
|
||||
val srcFileRelativePath = PathTransformer.std().fileAsDatabaseString(File(srcFilePath))
|
||||
|
||||
val dbSrcFilePath = Paths.get("$dbSrcDir/$srcFileRelativePath")
|
||||
val dbSrcFilePath = FileUtil.appendAbsolutePath(dbSrcDir, srcFileRelativePath).toPath()
|
||||
val dbSrcDirPath = dbSrcFilePath.parent
|
||||
Files.createDirectories(dbSrcDirPath)
|
||||
val srcTmpFile =
|
||||
@@ -385,7 +386,7 @@ private fun doFile(
|
||||
srcTmpFile.outputStream().use { Files.copy(Paths.get(srcFilePath), it) }
|
||||
srcTmpFile.renameTo(dbSrcFilePath.toFile())
|
||||
|
||||
val trapFileName = "$dbTrapDir/$srcFileRelativePath.trap"
|
||||
val trapFileName = FileUtil.appendAbsolutePath(dbTrapDir, "$srcFileRelativePath.trap").getAbsolutePath()
|
||||
val trapFileWriter = getTrapFileWriter(compression, logger, trapFileName)
|
||||
|
||||
if (checkTrapIdentical || !trapFileWriter.exists()) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
| file:///src/kotlin_source.kt:1:1:2:1 | Foo |
|
||||
@@ -0,0 +1,5 @@
|
||||
import java
|
||||
|
||||
from Class c
|
||||
where c.fromSource()
|
||||
select c
|
||||
@@ -0,0 +1,2 @@
|
||||
class Foo {
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
from create_database_utils import *
|
||||
|
||||
path_transformer_file = 'path_transformer'
|
||||
root = os.getcwd().replace('\\', '/')
|
||||
with open(path_transformer_file, 'w') as f:
|
||||
f.write('#/src\n' + root + '//\n')
|
||||
os.environ['SEMMLE_PATH_TRANSFORMER'] = root + '/' + path_transformer_file
|
||||
|
||||
run_codeql_database_create(["kotlinc kotlin_source.kt"], lang="java")
|
||||
files = ['test-db/trap/java/src/kotlin_source.kt.trap.gz', 'test-db/src/src/kotlin_source.kt']
|
||||
exists = list(map(os.path.exists, files))
|
||||
if exists != [True] * 2:
|
||||
print(exists)
|
||||
raise Exception("Didn't get expected filed")
|
||||
Reference in New Issue
Block a user