mirror of
https://github.com/github/codeql.git
synced 2026-04-25 08:45:14 +02:00
Address review.
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
import os
|
||||
|
||||
|
||||
def test(codeql, java_full):
|
||||
os.mkdir("out")
|
||||
codeql.database.create(
|
||||
command=["kotlinc test.kt -d out", "javac User.java -cp out", "kotlinc ktUser.kt -cp out"]
|
||||
command=["kotlinc test.kt -d out", "javac User.java -cp out -d out2", "kotlinc ktUser.kt -cp out -d out2"]
|
||||
)
|
||||
|
||||
@@ -14,10 +14,6 @@ def build():
|
||||
|
||||
|
||||
def test(codeql, java_full, build):
|
||||
for var in [
|
||||
"CODEQL_EXTRACTOR_JAVA_AGENT_ENABLE_KOTLIN",
|
||||
"CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN",
|
||||
]:
|
||||
if var in os.environ:
|
||||
del os.environ[var]
|
||||
os.environ.pop("CODEQL_EXTRACTOR_JAVA_AGENT_ENABLE_KOTLIN", None)
|
||||
os.environ.pop("CODEQL_EXTRACTOR_JAVA_AGENT_DISABLE_KOTLIN", None)
|
||||
codeql.database.create(command=build)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
def test(codeql, java_full, cwd):
|
||||
java_srcs = [str(s) for s in cwd.glob('*.java')]
|
||||
import pathlib
|
||||
|
||||
|
||||
def test(codeql, java_full):
|
||||
java_srcs = " ".join([str(s) for s in pathlib.Path().glob("*.java")])
|
||||
codeql.database.create(
|
||||
command=[
|
||||
f"javac {' '.join(java_srcs)} -d {cwd / 'build'}",
|
||||
f"javac {java_srcs} -d build",
|
||||
"kotlinc -language-version 1.9 user.kt -cp build",
|
||||
]
|
||||
)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import commands
|
||||
import pathlib
|
||||
|
||||
|
||||
def test(codeql, java_full, cwd):
|
||||
def test(codeql, java_full):
|
||||
# Compile Java untraced. Note the Java source is hidden under `javasrc` so the Kotlin compiler
|
||||
# will certainly reference the jar, not the source or class file for extlib.Lib
|
||||
java_srcs = (cwd / "libsrc" / "extlib").glob("*.java")
|
||||
java_srcs = pathlib.Path("libsrc", "extlib").glob("*.java")
|
||||
commands.run(["javac", *java_srcs, "-d", "build"])
|
||||
commands.run("jar cf extlib.jar -C build extlib")
|
||||
codeql.database.create(command="kotlinc test.kt -cp extlib.jar")
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import commands
|
||||
import pathlib
|
||||
|
||||
|
||||
def test(codeql, java_full, cwd):
|
||||
def test(codeql, java_full):
|
||||
# Compile library Kotlin file untraced. Note the library is hidden under `libsrc` so the Kotlin compiler
|
||||
# will certainly reference the jar, not the source or class file.
|
||||
commands.run(["kotlinc", *(cwd / "libsrc").glob("*.kt"), "-d", "build"])
|
||||
commands.run(["kotlinc", *pathlib.Path("libsrc").glob("*.kt"), "-d", "build"])
|
||||
commands.run(
|
||||
["jar", "cf", "extlib.jar", "-C", "build", "abcdefghij", "-C", "build", "META-INF"]
|
||||
)
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
Test script
|
||||
Log file
|
||||
1
|
||||
CodeQL Kotlin extractor
|
||||
INFO
|
||||
Extraction started
|
||||
CodeQL Kotlin extractor
|
||||
INFO
|
||||
Extraction for invocation TRAP file <FILENAME>
|
||||
CodeQL Kotlin extractor
|
||||
INFO
|
||||
Kotlin version <VERSION>
|
||||
CodeQL Kotlin extractor
|
||||
INFO
|
||||
Extracting file test.kt
|
||||
CodeQL Kotlin extractor
|
||||
INFO
|
||||
Extraction completed
|
||||
Log file 1
|
||||
{"origin": "CodeQL Kotlin extractor", "kind": "INFO", "message": "Extraction started"}
|
||||
{"origin": "CodeQL Kotlin extractor", "kind": "INFO", "message": "Extraction for invocation TRAP file <FILENAME>"}
|
||||
{"origin": "CodeQL Kotlin extractor", "kind": "INFO", "message": "Kotlin version <VERSION>"}
|
||||
{"origin": "CodeQL Kotlin extractor", "kind": "INFO", "message": "Extracting file test.kt"}
|
||||
{"origin": "CodeQL Kotlin extractor", "kind": "INFO", "message": "Extraction completed"}
|
||||
|
||||
@@ -10,12 +10,11 @@ def test(codeql, java_full, cwd: pathlib.Path, expected_files):
|
||||
|
||||
with open("logs.actual", "w") as f_out:
|
||||
log_dir = cwd / "test-db" / "log"
|
||||
file_index = 0
|
||||
for log_file in log_dir.glob("kotlin-extractor*.log"):
|
||||
file_index += 1
|
||||
f_out.write(f"Test script\nLog file\n{file_index}\n")
|
||||
for file_index, log_file in enumerate(log_dir.glob("kotlin-extractor*.log"), 1):
|
||||
f_out.write(f"Log file {file_index}\n")
|
||||
for line in log_file.read_text().splitlines():
|
||||
j = json.loads(line)
|
||||
del j["timestamp"]
|
||||
msg = j["message"]
|
||||
msg = re.sub(
|
||||
r"(?<=Extraction for invocation TRAP file ).*[\\/]test-db[\\/]trap[\\/]java[\\/]invocations[\\/]kotlin\..*\.trap",
|
||||
@@ -36,4 +35,5 @@ def test(codeql, java_full, cwd: pathlib.Path, expected_files):
|
||||
):
|
||||
# These vary between machines etc, and aren't very interesting, so just ignore them
|
||||
continue
|
||||
f_out.write(f"{j['origin']}\n{j['kind']}\n{msg}\n")
|
||||
j["message"] = msg
|
||||
print(json.dumps(j), file=f_out)
|
||||
|
||||
@@ -4,9 +4,6 @@ import os
|
||||
|
||||
def check_extensions(directory, counts):
|
||||
if runs_on.windows:
|
||||
# It's important that the path is a Unicode path on Windows, so
|
||||
# that the right system calls get used.
|
||||
directory = "" + directory
|
||||
if not directory.startswith("\\\\?\\"):
|
||||
directory = "\\\\?\\" + os.path.abspath(directory)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user