mirror of
https://github.com/github/codeql.git
synced 2025-12-22 19:56:32 +01:00
Kotlin/Bazel: port custom_plugin test to use bazel
This commit is contained in:
@@ -1,53 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
import shutil
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
import shlex
|
||||
|
||||
|
||||
def run_process(cmd):
|
||||
try:
|
||||
print("Running command: " + shlex.join(cmd))
|
||||
return subprocess.run(cmd, check=True, capture_output=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("In: " + os.getcwd(), file=sys.stderr)
|
||||
print("Command failed: " + shlex.join(cmd), file=sys.stderr)
|
||||
print("stdout output:\n" + e.stdout.decode(encoding='UTF-8',
|
||||
errors='strict'), file=sys.stderr)
|
||||
print("stderr output:\n" + e.stderr.decode(encoding='UTF-8',
|
||||
errors='strict'), file=sys.stderr)
|
||||
raise e
|
||||
|
||||
root = '../../../../../../../../..'
|
||||
|
||||
sys.path.append(root + '/ql/java/kotlin-extractor')
|
||||
import kotlin_plugin_versions
|
||||
defaultKotlinDependencyVersion = kotlin_plugin_versions.get_single_version()
|
||||
|
||||
builddir = 'build'
|
||||
dependency_dir = root + '/resources/kotlin-dependencies/'
|
||||
dependencies = ['kotlin-stdlib-' + defaultKotlinDependencyVersion +
|
||||
'.jar', 'kotlin-compiler-' + defaultKotlinDependencyVersion + '.jar']
|
||||
classpath = ':'.join([dependency_dir + dep for dep in dependencies])
|
||||
srcs = ['plugin/Plugin.kt']
|
||||
output = 'plugin.jar'
|
||||
|
||||
if os.path.exists(builddir):
|
||||
shutil.rmtree(builddir)
|
||||
os.makedirs(builddir)
|
||||
|
||||
run_process(['kotlinc',
|
||||
'-J-Xmx2G',
|
||||
'-d', builddir,
|
||||
'-module-name', 'test',
|
||||
'-no-reflect', '-no-stdlib',
|
||||
'-jvm-target', '1.8',
|
||||
'-classpath', classpath] + srcs)
|
||||
|
||||
run_process(['jar', '-c', '-f', output,
|
||||
'-C', builddir, '.',
|
||||
'-C', 'plugin/resources', 'META-INF'])
|
||||
shutil.rmtree(builddir)
|
||||
@@ -0,0 +1,26 @@
|
||||
load("@codeql_kotlin_defaults//:defaults.bzl", "kotlin_extractor_defaults")
|
||||
load("@rules_kotlin//kotlin:core.bzl", "kt_kotlinc_options")
|
||||
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
|
||||
load("//java/kotlin-extractor:versions.bzl", "get_language_version")
|
||||
|
||||
_version = kotlin_extractor_defaults.extractor_version
|
||||
|
||||
kt_kotlinc_options(
|
||||
name = "kotlinc-options",
|
||||
include_stdlibs = "none",
|
||||
jvm_target = "1.8",
|
||||
language_version = get_language_version(_version),
|
||||
)
|
||||
|
||||
kt_jvm_library(
|
||||
name = "plugin",
|
||||
srcs = ["Plugin.kt"],
|
||||
kotlinc_opts = ":kotlinc-options",
|
||||
module_name = "test",
|
||||
resource_strip_prefix = "%s/resources" % package_name(),
|
||||
resources = glob(["resources/**"]),
|
||||
deps = [
|
||||
"@kotlin-compiler-%s" % _version,
|
||||
"@kotlin-stdlib-%s" % _version,
|
||||
],
|
||||
)
|
||||
@@ -1,6 +1,25 @@
|
||||
from create_database_utils import *
|
||||
import subprocess
|
||||
|
||||
subprocess.call("./build_plugin", shell=True)
|
||||
import pathlib
|
||||
import shutil
|
||||
|
||||
this_dir = pathlib.Path(__file__).resolve().parent
|
||||
cwd = pathlib.Path.cwd()
|
||||
builddir = cwd / 'build'
|
||||
|
||||
builddir.mkdir(exist_ok=True)
|
||||
|
||||
try:
|
||||
runSuccessfully(['bazel', f'--output_user_root={builddir}', '--max_idle_secs=1', 'build',
|
||||
'//java/ql/integration-tests/linux-only/kotlin/custom_plugin/plugin', '--spawn_strategy=local',
|
||||
'--nouse_action_cache', '--noremote_accept_cached', '--noremote_upload_local_results',
|
||||
f'--symlink_prefix={cwd / "bazel-"}'], cwd=this_dir)
|
||||
finally:
|
||||
# rules_python creates a read-only directory in bazel's output, this allows cleanup to succeed
|
||||
runSuccessfully(['chmod', '-R', '+w', builddir])
|
||||
|
||||
shutil.copy(
|
||||
'bazel-bin/java/ql/integration-tests/linux-only/kotlin/custom_plugin/plugin/plugin.jar', 'plugin.jar')
|
||||
|
||||
run_codeql_database_create(
|
||||
["kotlinc -J-Xmx2G -Xplugin=plugin.jar a.kt b.kt c.kt d.kt e.kt"], lang="java")
|
||||
|
||||
Reference in New Issue
Block a user