diff --git a/prepare/compiler-embeddable/build.gradle.kts b/prepare/compiler-embeddable/build.gradle.kts index f456447ce39..986d64b7369 100644 --- a/prepare/compiler-embeddable/build.gradle.kts +++ b/prepare/compiler-embeddable/build.gradle.kts @@ -2,15 +2,25 @@ description = "Kotlin Compiler (embeddable)" plugins { - `java` + kotlin("jvm") } +val testCompilationClasspath by configurations.creating + dependencies { runtime(kotlinStdlib()) runtime(project(":kotlin-script-runtime")) runtime(project(":kotlin-reflect")) runtime(project(":kotlin-daemon-embeddable")) runtime(commonDep("org.jetbrains.intellij.deps", "trove4j")) + testCompile(commonDep("junit:junit")) + testCompile(project(":kotlin-test:kotlin-test-junit")) + testCompilationClasspath(kotlinStdlib()) +} + +sourceSets { + "main" {} + "test" { projectDefault() } } publish() @@ -22,7 +32,7 @@ compilerDummyJar(compilerDummyForDependenciesRewriting("compilerDummy") { classifier = "dummy" }) -runtimeJar(embeddableCompiler()) { +val runtimeJar = runtimeJar(embeddableCompiler()) { exclude("com/sun/jna/**") exclude("org/jetbrains/annotations/**") mergeServiceFiles() @@ -31,3 +41,14 @@ runtimeJar(embeddableCompiler()) { sourcesJar() javadocJar() +projectTest { + dependsOn(runtimeJar) + doFirst { + val runtimeJarConfig = configurations["runtimeJar"] + val runtimeConfig = configurations["runtime"] + systemProperty("compilerClasspath", "${runtimeJarConfig.allArtifacts.files.files.first().path}${File.pathSeparator}${runtimeConfig.asPath}") + systemProperty("compilationClasspath", testCompilationClasspath.asPath) + } +} + + diff --git a/libraries/tools/kotlin-compiler-embeddable/test/resources/projects/smoke/Smoke.kt b/prepare/compiler-embeddable/testData/projects/smoke/Smoke.kt similarity index 100% rename from libraries/tools/kotlin-compiler-embeddable/test/resources/projects/smoke/Smoke.kt rename to prepare/compiler-embeddable/testData/projects/smoke/Smoke.kt diff --git a/libraries/tools/kotlin-compiler-embeddable/test/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt b/prepare/compiler-embeddable/tests/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt similarity index 68% rename from libraries/tools/kotlin-compiler-embeddable/test/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt rename to prepare/compiler-embeddable/tests/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt index d9b9bb3dc2a..81f59075c0c 100644 --- a/libraries/tools/kotlin-compiler-embeddable/test/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt +++ b/prepare/compiler-embeddable/tests/kotlin/org/jetbrains/kotlin/compiler/embeddable/CompilerEmbeddableSmokeTests.kt @@ -36,16 +36,23 @@ public class CompilerSmokeTest { private val javaExecutable = File( File(System.getProperty("java.home"), "bin"), "java") - private val embeddableJar: File by lazy { - val f = File(System.getProperty("compilerJar") ?: "kotlin-compiler-embeddable.jar") - if (!f.exists()) - throw FileNotFoundException("cannot find kotlin-compiler-embeddable.jar ($f)") - f + private val compilerClasspath: List by lazy { + filesFromProp("compilerClasspath", "kotlin-compiler-embeddable.jar") } + private val compilationClasspath: List by lazy { + filesFromProp("compilationClasspath", "kotlin-stdlib.jar", "kotlin-script-runtime.jar") + } + + private fun filesFromProp(propName: String, vararg defaultPaths: String): List = + (System.getProperty(propName)?.split(File.pathSeparator) ?: defaultPaths.asList()).map { + File(it).takeIf(File::exists) + ?: throw FileNotFoundException("cannot find ($it)") + } + @Test fun testSmoke() { - val (out, code) = runCompiler(File("../test/resources/projects/smoke/Smoke.kt").absolutePath) + val (out, code) = runCompiler(File("testData/projects/smoke/Smoke.kt").absolutePath) assertEquals(0, code, "compilation failed:\n" + out) } @@ -58,12 +65,15 @@ public class CompilerSmokeTest { } private fun runCompiler(vararg arguments: String): Pair { - val cmd = listOf(javaExecutable.absolutePath, - "-Djava.awt.headless=true", - "-cp", - embeddableJar.absolutePath, - COMPILER_CLASS_FQN) + - arguments + val cmd = listOf( + javaExecutable.absolutePath, + "-Djava.awt.headless=true", + "-cp", + compilerClasspath.joinToString(File.pathSeparator), + COMPILER_CLASS_FQN, + "-cp", + compilationClasspath.joinToString(File.pathSeparator) + ) + arguments val proc = createProcess(cmd, _workingDir.root) return readOutput(proc) }