Skip to content

Commit d66d9b7

Browse files
bnormtschuchortdev
authored andcommitted
Add support for running Kotlin/JS compiler
1 parent be6e88f commit d66d9b7

File tree

8 files changed

+439
-22
lines changed

8 files changed

+439
-22
lines changed

core/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ dependencies {
3232
// running compiler plugins passed via the pluginClasspath CLI option works
3333
testRuntime "org.jetbrains.kotlin:kotlin-scripting-compiler:$kotlin_version"
3434

35+
// Include Kotlin/JS standard library in test classpath for auto loading
36+
testRuntime "org.jetbrains.kotlin:kotlin-stdlib-js"
37+
3538
// The Kotlin compiler should be near the end of the list because its .jar file includes
3639
// an obsolete version of Guava
3740
implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.tschuchort.compiletesting
2+
3+
import org.jetbrains.kotlin.cli.common.ExitCode as CliExitCode
4+
5+
/** ExitCode of the entire Kotlin compilation process */
6+
enum class ExitCode {
7+
OK, INTERNAL_ERROR, COMPILATION_ERROR, SCRIPT_EXECUTION_ERROR
8+
}
9+
10+
internal fun convertKotlinExitCode(code: CliExitCode) = when(code) {
11+
CliExitCode.OK -> ExitCode.OK
12+
CliExitCode.INTERNAL_ERROR -> ExitCode.INTERNAL_ERROR
13+
CliExitCode.COMPILATION_ERROR -> ExitCode.COMPILATION_ERROR
14+
CliExitCode.SCRIPT_EXECUTION_ERROR -> ExitCode.SCRIPT_EXECUTION_ERROR
15+
}

core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import okio.Buffer
2222
import org.jetbrains.kotlin.base.kapt3.AptMode
2323
import org.jetbrains.kotlin.base.kapt3.KaptFlag
2424
import org.jetbrains.kotlin.base.kapt3.KaptOptions
25-
import org.jetbrains.kotlin.cli.common.ExitCode
2625
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
2726
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
2827
import org.jetbrains.kotlin.cli.common.arguments.validateArguments
@@ -332,11 +331,6 @@ class KotlinCompilation {
332331
val kaptStubsDir get() = kaptBaseDir.resolve("stubs")
333332
val kaptIncrementalDataDir get() = kaptBaseDir.resolve("incrementalData")
334333

335-
/** ExitCode of the entire Kotlin compilation process */
336-
enum class ExitCode {
337-
OK, INTERNAL_ERROR, COMPILATION_ERROR, SCRIPT_EXECUTION_ERROR
338-
}
339-
340334
/** Result of the compilation */
341335
inner class Result(
342336
/** The exit code of the compilation */
@@ -906,19 +900,12 @@ class KotlinCompilation {
906900
}
907901
}
908902

909-
private fun kotlinDependencyRegex(prefix:String): Regex {
903+
internal fun kotlinDependencyRegex(prefix:String): Regex {
910904
return Regex("$prefix(-[0-9]+\\.[0-9]+(\\.[0-9]+)?)([-0-9a-zA-Z]+)?\\.jar")
911905
}
912906

913-
private fun convertKotlinExitCode(code: ExitCode) = when(code) {
914-
ExitCode.OK -> KotlinCompilation.ExitCode.OK
915-
ExitCode.INTERNAL_ERROR -> KotlinCompilation.ExitCode.INTERNAL_ERROR
916-
ExitCode.COMPILATION_ERROR -> KotlinCompilation.ExitCode.COMPILATION_ERROR
917-
ExitCode.SCRIPT_EXECUTION_ERROR -> KotlinCompilation.ExitCode.SCRIPT_EXECUTION_ERROR
918-
}
919-
920907
/** Returns the files on the classloader's classpath and modulepath */
921-
private fun getHostClasspaths(): List<File> {
908+
internal fun getHostClasspaths(): List<File> {
922909
val classGraph = ClassGraph()
923910
.enableSystemJarsAndModules()
924911
.removeTemporaryFilesAfterScan()

0 commit comments

Comments
 (0)