[JS IR] Add gradle plugin integration tests
This commit is contained in:
@@ -105,8 +105,10 @@ tasks.withType<Test> {
|
||||
":kotlin-reflect:install",
|
||||
":kotlin-annotation-processing-gradle:install",
|
||||
":kotlin-test:kotlin-test-jvm:install",
|
||||
":kotlin-test:kotlin-test-js:install",
|
||||
":kotlin-gradle-subplugin-example:install",
|
||||
":kotlin-stdlib-jdk8:install",
|
||||
":kotlin-stdlib-js:install",
|
||||
":examples:annotation-processor-example:install",
|
||||
":kotlin-scripting-common:install",
|
||||
":kotlin-scripting-jvm:install",
|
||||
|
||||
+2
@@ -198,6 +198,7 @@ abstract class BaseGradleIT {
|
||||
val daemonOptionSupported: Boolean = true,
|
||||
val incremental: Boolean? = null,
|
||||
val incrementalJs: Boolean? = null,
|
||||
val jsIrBackend: Boolean? = null,
|
||||
val androidHome: File? = null,
|
||||
val javaHome: File? = null,
|
||||
val androidGradlePluginVersion: AGPVersion? = null,
|
||||
@@ -719,6 +720,7 @@ Finished executing task ':$taskName'|
|
||||
add("-Pkotlin.incremental=$it")
|
||||
}
|
||||
options.incrementalJs?.let { add("-Pkotlin.incremental.js=$it") }
|
||||
options.jsIrBackend?.let { add("-Pkotlin.js.useIrBackend=$it") }
|
||||
options.usePreciseJavaTracking?.let { add("-Pkotlin.incremental.usePreciseJavaTracking=$it") }
|
||||
options.androidGradlePluginVersion?.let { add("-Pandroid_tools_version=$it") }
|
||||
if (options.debug) {
|
||||
|
||||
+252
-201
@@ -2,169 +2,20 @@ package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.gradle.api.logging.LogLevel
|
||||
import org.jetbrains.kotlin.gradle.tasks.USING_JS_INCREMENTAL_COMPILATION_MESSAGE
|
||||
import org.jetbrains.kotlin.gradle.tasks.USING_JS_IR_BACKEND_MESSAGE
|
||||
import org.jetbrains.kotlin.gradle.util.getFileByName
|
||||
import org.jetbrains.kotlin.gradle.util.getFilesByNames
|
||||
import org.jetbrains.kotlin.gradle.util.modify
|
||||
import org.junit.Assume.assumeFalse
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.util.zip.ZipFile
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
@Test
|
||||
fun testBuildAndClean() {
|
||||
val project = Project("kotlin2JsProject")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertReportExists()
|
||||
|
||||
assertTasksExecuted(
|
||||
":libraryProject:jarSources",
|
||||
":mainProject:compileKotlin2Js",
|
||||
":libraryProject:compileKotlin2Js"
|
||||
)
|
||||
|
||||
listOf(
|
||||
"mainProject/web/js/app.js",
|
||||
"mainProject/web/js/lib/kotlin.js",
|
||||
"libraryProject/build/kotlin2js/main/test-library.js",
|
||||
"mainProject/web/js/app.js.map"
|
||||
).forEach { assertFileExists(it) }
|
||||
}
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertTasksUpToDate(":mainProject:compileKotlin2Js")
|
||||
assertContainsRegex(":libraryProject:compileTestKotlin2Js (UP-TO-DATE|NO-SOURCE)".toRegex())
|
||||
}
|
||||
|
||||
project.build("clean") {
|
||||
assertSuccessful()
|
||||
assertReportExists()
|
||||
|
||||
// Test that we don't accidentally remove the containing directory
|
||||
// This would fail if we used the default clean task of the copy task
|
||||
assertFileExists("mainProject/web/js/lib")
|
||||
|
||||
assertNoSuchFile("main/project/web/js/app.js.map")
|
||||
assertNoSuchFile("main/project/web/js/example/main.kt")
|
||||
}
|
||||
|
||||
project.build("clean") {
|
||||
assertSuccessful()
|
||||
assertReportExists()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJarIncludesJsDefaultOutput() {
|
||||
val project = Project("kotlin2JsNoOutputFileProject")
|
||||
|
||||
project.build("jar") {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksExecuted(":compileKotlin2Js")
|
||||
val jarPath = "build/libs/kotlin2JsNoOutputFileProject.jar"
|
||||
assertFileExists(jarPath)
|
||||
val jar = ZipFile(fileInWorkingDir(jarPath))
|
||||
assertEquals(
|
||||
1, jar.entries().asSequence().count { it.name == "kotlin2JsNoOutputFileProject.js" },
|
||||
"The jar should contain an entry `kotlin2JsNoOutputFileProject.js` with no duplicates"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJarIncludesJsOutputSetExplicitly() {
|
||||
val project = Project("kotlin2JsModuleKind")
|
||||
|
||||
project.build(":jar") {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksExecuted(":compileKotlin2Js")
|
||||
val jarPath = "build/libs/kotlin2JsModuleKind.jar"
|
||||
assertFileExists(jarPath)
|
||||
val jar = ZipFile(fileInWorkingDir(jarPath))
|
||||
assertEquals(
|
||||
1, jar.entries().asSequence().count { it.name == "app.js" },
|
||||
"The jar should contain an entry `app.js` with no duplicates"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testModuleKind() {
|
||||
val project = Project("kotlin2JsModuleKind")
|
||||
|
||||
project.build("runRhino") {
|
||||
assertSuccessful()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDefaultOutputFile() {
|
||||
val project = Project("kotlin2JsNoOutputFileProject")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertFileExists(kotlinClassesDir() + "kotlin2JsNoOutputFileProject.js")
|
||||
assertFileExists(kotlinClassesDir(sourceSet = "test") + "kotlin2JsNoOutputFileProject_test.js")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompileTestCouldAccessProduction() {
|
||||
val project = Project("kotlin2JsProjectWithTests")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksExecuted(
|
||||
":compileKotlin2Js",
|
||||
":compileTestKotlin2Js"
|
||||
)
|
||||
|
||||
assertFileExists("build/kotlin2js/main/module.js")
|
||||
assertFileExists("build/kotlin2js/test/module-tests.js")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompilerTestAccessInternalProduction() {
|
||||
val project = Project("kotlin2JsInternalTest")
|
||||
|
||||
project.build("runRhino") {
|
||||
assertSuccessful()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJsCustomSourceSet() {
|
||||
val project = Project("kotlin2JsProjectWithCustomSourceset")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
assertTasksExecuted(
|
||||
":compileKotlin2Js",
|
||||
":compileIntegrationTestKotlin2Js"
|
||||
)
|
||||
|
||||
assertFileExists("build/kotlin2js/main/module.js")
|
||||
assertFileExists("build/kotlin2js/integrationTest/module-inttests.js")
|
||||
|
||||
val jarPath = "build/libs/kotlin2JsProjectWithCustomSourceset-inttests.jar"
|
||||
assertFileExists(jarPath)
|
||||
val jar = ZipFile(fileInWorkingDir(jarPath))
|
||||
assertEquals(
|
||||
1, jar.entries().asSequence().count { it.name == "module-inttests.js" },
|
||||
"The jar should contain an entry `module-inttests.js` with no duplicates"
|
||||
)
|
||||
}
|
||||
}
|
||||
class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true)
|
||||
|
||||
class Kotlin2JsGradlePluginIT : AbstractKotlin2JsGradlePluginIT(false) {
|
||||
@Test
|
||||
fun testKotlinJsBuiltins() {
|
||||
val project = Project("kotlinBuiltins")
|
||||
@@ -180,49 +31,6 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinJsSourceMap() {
|
||||
val project = Project("kotlin2JsNoOutputFileProject")
|
||||
|
||||
project.setupWorkingDir()
|
||||
|
||||
project.projectDir.getFileByName("build.gradle").modify {
|
||||
it + "\n" +
|
||||
"compileKotlin2Js.kotlinOptions.sourceMap = true\n" +
|
||||
"compileKotlin2Js.kotlinOptions.sourceMapPrefix = \"prefixprefix/\"\n" +
|
||||
"compileKotlin2Js.kotlinOptions.outputFile = \"\${buildDir}/kotlin2js/main/app.js\"\n"
|
||||
}
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
val mapFilePath = "build/kotlin2js/main/app.js.map"
|
||||
assertFileExists(mapFilePath)
|
||||
val map = fileInWorkingDir(mapFilePath).readText()
|
||||
|
||||
val sourceFilePath = "prefixprefix/src/main/kotlin/example/Dummy.kt"
|
||||
assertTrue("Source map should contain reference to $sourceFilePath") { map.contains("\"$sourceFilePath\"") }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinJsSourceMapInline() {
|
||||
val project = Project("kotlin2JsProjectWithSourceMapInline")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
val mapFilePath = kotlinClassesDir(subproject = "app") + "app.js.map"
|
||||
assertFileExists(mapFilePath)
|
||||
val map = fileInWorkingDir(mapFilePath).readText()
|
||||
|
||||
assertTrue("Source map should contain reference to main.kt") { map.contains("\"./src/main/kotlin/main.kt\"") }
|
||||
assertTrue("Source map should contain reference to foo.kt") { map.contains("\"./src/main/kotlin/foo.kt\"") }
|
||||
assertTrue("Source map should contain source of main.kt") { map.contains("\"fun main(args: Array<String>) {") }
|
||||
assertTrue("Source map should contain source of foo.kt") { map.contains("\"inline fun foo(): String {") }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDce() {
|
||||
val project = Project("kotlin2JsDceProject", minLogLevel = LogLevel.INFO)
|
||||
@@ -305,6 +113,239 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
assertTrue(fileInWorkingDir("$pathPrefix/kotlin.js").length() < 500 * 1000, "Looks like kotlin.js file was not minified by DCE")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractKotlin2JsGradlePluginIT(private val irBackend: Boolean) : BaseGradleIT() {
|
||||
override fun defaultBuildOptions(): BuildOptions =
|
||||
super.defaultBuildOptions().copy(jsIrBackend = irBackend)
|
||||
|
||||
private fun CompiledProject.checkIrCompilationMessage() {
|
||||
if (irBackend) {
|
||||
assertContains(USING_JS_IR_BACKEND_MESSAGE)
|
||||
} else {
|
||||
assertNotContains(USING_JS_IR_BACKEND_MESSAGE)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBuildAndClean() {
|
||||
val project = Project("kotlin2JsProject")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertReportExists()
|
||||
checkIrCompilationMessage()
|
||||
|
||||
assertTasksExecuted(
|
||||
":libraryProject:jarSources",
|
||||
":mainProject:compileKotlin2Js",
|
||||
":libraryProject:compileKotlin2Js"
|
||||
)
|
||||
|
||||
assertFileExists("mainProject/web/js/app.js")
|
||||
if (!irBackend) {
|
||||
assertFileExists("mainProject/web/js/lib/kotlin.js")
|
||||
assertFileExists("libraryProject/build/kotlin2js/main/test-library.js")
|
||||
assertFileExists("mainProject/web/js/app.js.map")
|
||||
}
|
||||
}
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
assertTasksUpToDate(":mainProject:compileKotlin2Js")
|
||||
assertContainsRegex(":libraryProject:compileTestKotlin2Js (UP-TO-DATE|NO-SOURCE)".toRegex())
|
||||
}
|
||||
|
||||
project.build("clean") {
|
||||
assertSuccessful()
|
||||
assertReportExists()
|
||||
|
||||
// Test that we don't accidentally remove the containing directory
|
||||
// This would fail if we used the default clean task of the copy task
|
||||
assertFileExists("mainProject/web/js/lib")
|
||||
|
||||
assertNoSuchFile("main/project/web/js/app.js.map")
|
||||
assertNoSuchFile("main/project/web/js/example/main.kt")
|
||||
}
|
||||
|
||||
project.build("clean") {
|
||||
assertSuccessful()
|
||||
assertReportExists()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJarIncludesJsDefaultOutput() {
|
||||
val project = Project("kotlin2JsNoOutputFileProject")
|
||||
|
||||
project.build("jar") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
|
||||
assertTasksExecuted(":compileKotlin2Js")
|
||||
val jarPath = "build/libs/kotlin2JsNoOutputFileProject.jar"
|
||||
assertFileExists(jarPath)
|
||||
val jar = ZipFile(fileInWorkingDir(jarPath))
|
||||
assertEquals(
|
||||
1, jar.entries().asSequence().count { it.name == "kotlin2JsNoOutputFileProject.js" },
|
||||
"The jar should contain an entry `kotlin2JsNoOutputFileProject.js` with no duplicates"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJarIncludesJsOutputSetExplicitly() {
|
||||
val project = Project("kotlin2JsModuleKind")
|
||||
|
||||
project.build(":jar") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
|
||||
assertTasksExecuted(":compileKotlin2Js")
|
||||
val jarPath = "build/libs/kotlin2JsModuleKind.jar"
|
||||
assertFileExists(jarPath)
|
||||
val jar = ZipFile(fileInWorkingDir(jarPath))
|
||||
assertEquals(
|
||||
1, jar.entries().asSequence().count { it.name == "app.js" },
|
||||
"The jar should contain an entry `app.js` with no duplicates"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testModuleKind() {
|
||||
val project = Project("kotlin2JsModuleKind")
|
||||
|
||||
project.build("runRhino") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDefaultOutputFile() {
|
||||
val project = Project("kotlin2JsNoOutputFileProject")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
if (irBackend) {
|
||||
assertFileExists(kotlinClassesDir() + "manifest")
|
||||
} else {
|
||||
assertFileExists(kotlinClassesDir() + "kotlin2JsNoOutputFileProject.js")
|
||||
}
|
||||
assertFileExists(kotlinClassesDir(sourceSet = "test") + "kotlin2JsNoOutputFileProject_test.js")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompileTestCouldAccessProduction() {
|
||||
val project = Project("kotlin2JsProjectWithTests")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
|
||||
assertTasksExecuted(
|
||||
":compileKotlin2Js",
|
||||
":compileTestKotlin2Js"
|
||||
)
|
||||
if (irBackend) {
|
||||
assertFileExists("build/kotlin2js/main/manifest")
|
||||
} else {
|
||||
assertFileExists("build/kotlin2js/main/module.js")
|
||||
}
|
||||
assertFileExists("build/kotlin2js/test/module-tests.js")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompilerTestAccessInternalProduction() {
|
||||
val project = Project("kotlin2JsInternalTest")
|
||||
|
||||
project.build("runRhino") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testJsCustomSourceSet() {
|
||||
val project = Project("kotlin2JsProjectWithCustomSourceset")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
|
||||
assertTasksExecuted(
|
||||
":compileKotlin2Js",
|
||||
":compileIntegrationTestKotlin2Js"
|
||||
)
|
||||
|
||||
if (!irBackend) {
|
||||
assertFileExists("build/kotlin2js/main/module.js")
|
||||
}
|
||||
assertFileExists("build/kotlin2js/integrationTest/module-inttests.js")
|
||||
|
||||
val jarPath = "build/libs/kotlin2JsProjectWithCustomSourceset-inttests.jar"
|
||||
assertFileExists(jarPath)
|
||||
val jar = ZipFile(fileInWorkingDir(jarPath))
|
||||
assertEquals(
|
||||
1, jar.entries().asSequence().count { it.name == "module-inttests.js" },
|
||||
"The jar should contain an entry `module-inttests.js` with no duplicates"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testKotlinJsSourceMap() {
|
||||
// TODO: Support source maps
|
||||
assumeFalse(irBackend)
|
||||
|
||||
val project = Project("kotlin2JsNoOutputFileProject")
|
||||
|
||||
project.setupWorkingDir()
|
||||
|
||||
project.projectDir.getFileByName("build.gradle").modify {
|
||||
it + "\n" +
|
||||
"compileKotlin2Js.kotlinOptions.sourceMap = true\n" +
|
||||
"compileKotlin2Js.kotlinOptions.sourceMapPrefix = \"prefixprefix/\"\n" +
|
||||
"compileKotlin2Js.kotlinOptions.outputFile = \"\${buildDir}/kotlin2js/main/app.js\"\n"
|
||||
}
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
val mapFilePath = "build/kotlin2js/main/app.js.map"
|
||||
assertFileExists(mapFilePath)
|
||||
val map = fileInWorkingDir(mapFilePath).readText()
|
||||
|
||||
val sourceFilePath = "prefixprefix/src/main/kotlin/example/Dummy.kt"
|
||||
assertTrue("Source map should contain reference to $sourceFilePath") { map.contains("\"$sourceFilePath\"") }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testKotlinJsSourceMapInline() {
|
||||
// TODO: Support source maps
|
||||
assumeFalse(irBackend)
|
||||
|
||||
val project = Project("kotlin2JsProjectWithSourceMapInline")
|
||||
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
|
||||
val mapFilePath = kotlinClassesDir(subproject = "app") + "app.js.map"
|
||||
assertFileExists(mapFilePath)
|
||||
val map = fileInWorkingDir(mapFilePath).readText()
|
||||
|
||||
assertTrue("Source map should contain reference to main.kt") { map.contains("\"./src/main/kotlin/main.kt\"") }
|
||||
assertTrue("Source map should contain reference to foo.kt") { map.contains("\"./src/main/kotlin/foo.kt\"") }
|
||||
assertTrue("Source map should contain source of main.kt") { map.contains("\"fun main(args: Array<String>) {") }
|
||||
assertTrue("Source map should contain source of foo.kt") { map.contains("\"inline fun foo(): String {") }
|
||||
}
|
||||
}
|
||||
|
||||
/** Issue: KT-18495 */
|
||||
@Test
|
||||
@@ -312,6 +353,7 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
val project = Project("kotlin2JsProject")
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
assertNotContains("this build assumes a single directory for all classes from a source set")
|
||||
}
|
||||
}
|
||||
@@ -320,8 +362,11 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
fun testIncrementalCompilation() = Project("kotlin2JsICProject").run {
|
||||
build("build") {
|
||||
assertSuccessful()
|
||||
assertContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertCompiledKotlinSources(project.relativize(allKotlinFiles))
|
||||
checkIrCompilationMessage()
|
||||
if (!irBackend) { // TODO: Support incremental compilation
|
||||
assertContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertCompiledKotlinSources(project.relativize(allKotlinFiles))
|
||||
}
|
||||
}
|
||||
|
||||
build("build") {
|
||||
@@ -334,9 +379,13 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
}
|
||||
build("build") {
|
||||
assertSuccessful()
|
||||
assertContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
val affectedFiles = project.projectDir.getFilesByNames("A.kt", "useAInLibMain.kt", "useAInAppMain.kt", "useAInAppTest.kt")
|
||||
assertCompiledKotlinSources(project.relativize(affectedFiles))
|
||||
checkIrCompilationMessage()
|
||||
// TODO: Support incremental compilation in IR backend
|
||||
if (!irBackend) {
|
||||
assertContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
val affectedFiles = project.projectDir.getFilesByNames("A.kt", "useAInLibMain.kt", "useAInAppMain.kt", "useAInAppTest.kt")
|
||||
assertCompiledKotlinSources(project.relativize(affectedFiles))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -346,12 +395,14 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
||||
|
||||
build("build", options = options) {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
assertNotContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNewKotlinJsPlugin() = with(Project("kotlin-js-plugin-project", GradleVersionRequired.AtLeast("4.10.2"))) {
|
||||
assumeFalse(irBackend) // TODO: Support IR version of kotlinx.html
|
||||
setupWorkingDir()
|
||||
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
|
||||
gradleSettingsScript().modify(::transformBuildScriptWithPluginsDsl)
|
||||
|
||||
+6
@@ -4,3 +4,9 @@ dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
||||
compile project(":lib")
|
||||
}
|
||||
|
||||
def isIrBackend = project.findProperty("kotlin.js.useIrBackend")?.toBoolean() ?: false
|
||||
if (isIrBackend) {
|
||||
compileKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-klib-dir", "-Xir-only"]
|
||||
compileTestKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-js"]
|
||||
}
|
||||
|
||||
+6
@@ -3,3 +3,9 @@ apply plugin: 'kotlin2js'
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
||||
}
|
||||
|
||||
def isIrBackend = project.findProperty("kotlin.js.useIrBackend")?.toBoolean() ?: false
|
||||
if (isIrBackend) {
|
||||
compileKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-klib-dir", "-Xir-only"]
|
||||
compileTestKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-js"]
|
||||
}
|
||||
|
||||
+12
-1
@@ -22,11 +22,22 @@ dependencies {
|
||||
|
||||
def classesDir = "${buildDir}/classes/kotlin"
|
||||
|
||||
def isIrBackend = project.findProperty("kotlin.js.useIrBackend")?.toBoolean() ?: false
|
||||
if (isIrBackend) {
|
||||
compileKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-klib-dir", "-Xir-only"]
|
||||
compileTestKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-js"]
|
||||
}
|
||||
|
||||
task runRhino(type: JavaExec) {
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
workingDir = classesDir
|
||||
main = 'org.mozilla.javascript.tools.shell.Main'
|
||||
args = ["-opt", "-1", "-f", "kotlin.js", "-f", "main/kotlin2JsInternalTest.js", "-f", "test/kotlin2JsInternalTest_test.js", "-f", "check.js"]
|
||||
if (isIrBackend) {
|
||||
// IR backend produces a single JS file
|
||||
args = ["-opt", "-1", "test/kotlin2JsInternalTest_test.js", "-f", "check.js"]
|
||||
} else {
|
||||
args = ["-opt", "-1", "-f", "kotlin.js", "-f", "main/kotlin2JsInternalTest.js", "-f", "test/kotlin2JsInternalTest_test.js", "-f", "check.js"]
|
||||
}
|
||||
}
|
||||
|
||||
build.doLast {
|
||||
|
||||
+1
@@ -22,6 +22,7 @@ fun <T> assertEquals(e: T, a: T) {
|
||||
if (e != a) throw Exception("Expected: $e, actual: $a")
|
||||
}
|
||||
|
||||
@JsExport
|
||||
fun test() {
|
||||
assertEquals("CONST", CONST)
|
||||
|
||||
|
||||
+4
@@ -16,6 +16,10 @@ def outDir = "${buildDir}/kotlin2js/main/"
|
||||
compileKotlin2Js.kotlinOptions.moduleKind = "amd"
|
||||
compileKotlin2Js.kotlinOptions.outputFile = outDir + "app.js"
|
||||
|
||||
if (project.findProperty("kotlin.js.useIrBackend")?.toBoolean() == true) {
|
||||
compileKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-js"]
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
|
||||
+1
@@ -16,4 +16,5 @@
|
||||
|
||||
package foo
|
||||
|
||||
@JsExport
|
||||
fun bar() = "OK"
|
||||
|
||||
+5
@@ -17,4 +17,9 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
||||
}
|
||||
|
||||
if (project.findProperty("kotlin.js.useIrBackend")?.toBoolean() == true) {
|
||||
compileKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-klib-dir", "-Xir-produce-js", "-Xir-only"]
|
||||
compileTestKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-js"]
|
||||
}
|
||||
+6
-1
@@ -31,12 +31,17 @@ def outDir = "${buildDir}/kotlin2js/main/"
|
||||
|
||||
compileKotlin2Js.kotlinOptions.outputFile = outDir + "test-library.js"
|
||||
|
||||
def isIrBackend = project.findProperty("kotlin.js.useIrBackend")?.toBoolean()
|
||||
if (isIrBackend) {
|
||||
compileKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-klib-dir"]
|
||||
}
|
||||
|
||||
jar {
|
||||
from sourceSets.main.allSource
|
||||
include "**/*.kt"
|
||||
|
||||
from outDir
|
||||
include "**/*.js"
|
||||
include (isIrBackend ? "**/*" : "**/*.js")
|
||||
|
||||
manifest {
|
||||
attributes(
|
||||
|
||||
+4
@@ -25,6 +25,10 @@ compileKotlin2Js.kotlinOptions.outputFile = "${projectDir}/web/js/app.js"
|
||||
compileKotlin2Js.kotlinOptions.suppressWarnings = true
|
||||
compileKotlin2Js.kotlinOptions.verbose = true
|
||||
|
||||
if (project.findProperty("kotlin.js.useIrBackend")?.toBoolean() == true) {
|
||||
compileKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-js"]
|
||||
}
|
||||
|
||||
build.doLast {
|
||||
configurations.compile.each { File file ->
|
||||
copy {
|
||||
|
||||
+6
@@ -29,6 +29,12 @@ compileIntegrationTestKotlin2Js.dependsOn compileKotlin2Js
|
||||
compileKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/main/module.js"
|
||||
compileIntegrationTestKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/integrationTest/module-inttests.js"
|
||||
|
||||
def isIrBackend = project.findProperty("kotlin.js.useIrBackend")?.toBoolean() ?: false
|
||||
if (isIrBackend) {
|
||||
compileKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-klib-dir", "-Xir-only"]
|
||||
compileIntegrationTestKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-js"]
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
||||
integrationTestCompile files(file(compileKotlin2Js.kotlinOptions.outputFile).parent)
|
||||
|
||||
+5
@@ -30,3 +30,8 @@ artifacts {
|
||||
|
||||
compileKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/main/module.js"
|
||||
compileTestKotlin2Js.kotlinOptions.outputFile = "${buildDir}/kotlin2js/test/module-tests.js"
|
||||
|
||||
if (project.findProperty("kotlin.js.useIrBackend")?.toBoolean() == true) {
|
||||
compileKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-klib-dir", "-Xir-only"]
|
||||
compileTestKotlin2Js.kotlinOptions.freeCompilerArgs += ["-Xir-produce-js"]
|
||||
}
|
||||
+3
-2
@@ -46,6 +46,7 @@ import javax.inject.Inject
|
||||
const val KOTLIN_BUILD_DIR_NAME = "kotlin"
|
||||
const val USING_JVM_INCREMENTAL_COMPILATION_MESSAGE = "Using Kotlin/JVM incremental compilation"
|
||||
const val USING_JS_INCREMENTAL_COMPILATION_MESSAGE = "Using Kotlin/JS incremental compilation"
|
||||
const val USING_JS_IR_BACKEND_MESSAGE = "Using Kotlin/JS IR backend"
|
||||
|
||||
abstract class AbstractKotlinCompileTool<T : CommonToolArguments>
|
||||
: AbstractCompile(),
|
||||
@@ -588,8 +589,8 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
||||
logger.debug("Calling compiler")
|
||||
destinationDir.mkdirs()
|
||||
|
||||
if (args.isIrBackendEnabled()) {
|
||||
logger.kotlinDebug("Using JS IR backend")
|
||||
if (kotlinOptions.isIrBackendEnabled()) {
|
||||
logger.info(USING_JS_IR_BACKEND_MESSAGE)
|
||||
incremental = false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user