Revert [JS IR] commits that failed build
Revert "[JS IR] Build hybrid versions of stdlib and kotlin.test" This reverts commitb9f88350dd. Revert "[JS IR] Add gradle plugin integration tests" This reverts commitd872b27663. Revert "Update bootstrap" This reverts commitbc47594c7a. Revert "[JS IR] Support generating both IR and pre-IR libraries" This reverts commit1b8df45bfe.
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@ buildscript {
|
||||
extra["defaultSnapshotVersion"] = "1.3-SNAPSHOT"
|
||||
val cacheRedirectorEnabled = findProperty("cacheRedirectorEnabled")?.toString()?.toBoolean() == true
|
||||
|
||||
kotlinBootstrapFrom(BootstrapOption.BintrayBootstrap("1.3.70-dev-1140", cacheRedirectorEnabled))
|
||||
kotlinBootstrapFrom(BootstrapOption.BintrayBootstrap("1.3.70-dev-1070", cacheRedirectorEnabled))
|
||||
|
||||
repositories {
|
||||
bootstrapKotlinRepo?.let(::maven)
|
||||
|
||||
+12
-20
@@ -106,24 +106,22 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
|
||||
// Advanced options
|
||||
|
||||
@Argument(
|
||||
value = "-Xir-produce-klib-dir",
|
||||
description = "Generate unpacked KLIB into parent directory of output JS file.\n" +
|
||||
"In combination with -meta-info generates both IR and pre-IR versions of library."
|
||||
)
|
||||
var irProduceKlibDir: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(value = "-Xir", description = "Use IR backend")
|
||||
var irBackend: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xir-produce-klib-file",
|
||||
description = "Generate packed klib into file specified by -output. Disables pre-IR backend"
|
||||
value = "-Xir-produce-only",
|
||||
valueDescription = "{ klib, js }",
|
||||
description = "Type of output to produce. Overrides -meta-info argument."
|
||||
)
|
||||
var irProduceKlibFile: Boolean by FreezableVar(false)
|
||||
var irProduceOnly: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@Argument(value = "-Xir-produce-js", description = "Generates JS file using IR backend. Also disables pre-IR backend")
|
||||
var irProduceJs: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(value = "-Xir-only", description = "Disables pre-IR backend")
|
||||
var irOnly: Boolean by FreezableVar(false)
|
||||
@Argument(
|
||||
value = "-Xir-legacy-gradle-plugin-compatibility",
|
||||
description = "Make KLIB generation compatible with legacy gradle plugin"
|
||||
)
|
||||
var irLegacyGradlePluginCompatibility: Boolean by FreezableVar(false)
|
||||
|
||||
@GradleOption(DefaultValues.BooleanTrueDefault::class)
|
||||
@Argument(value = "-Xtyped-arrays", description = "Translate primitive arrays to JS typed arrays")
|
||||
@@ -146,9 +144,3 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
@Argument(value = "-Xenable-js-scripting", description = "Enable experimental support of .kts files using K/JS (with -Xir only)")
|
||||
var enableJsScripting: Boolean by FreezableVar(false)
|
||||
}
|
||||
|
||||
fun K2JSCompilerArguments.isPreIrBackendDisabled(): Boolean =
|
||||
irOnly || irProduceJs || irProduceKlibFile
|
||||
|
||||
fun K2JSCompilerArguments.isIrBackendEnabled(): Boolean =
|
||||
irProduceKlibDir || irProduceJs || irProduceKlibFile
|
||||
@@ -36,7 +36,6 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys;
|
||||
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager;
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArgumentsKt;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants;
|
||||
import org.jetbrains.kotlin.cli.common.config.ContentRootsKt;
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
@@ -187,13 +186,8 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
) {
|
||||
MessageCollector messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY);
|
||||
|
||||
ExitCode exitCode = OK;
|
||||
|
||||
if (K2JSCompilerArgumentsKt.isIrBackendEnabled(arguments)) {
|
||||
exitCode = getIrCompiler().doExecute(arguments, configuration.copy(), rootDisposable, paths);
|
||||
}
|
||||
if (K2JSCompilerArgumentsKt.isPreIrBackendDisabled(arguments)) {
|
||||
return exitCode;
|
||||
if (arguments.getIrBackend()) {
|
||||
return getIrCompiler().doExecute(arguments, configuration, rootDisposable, paths);
|
||||
}
|
||||
|
||||
if (arguments.getFreeArgs().isEmpty() && !IncrementalCompilation.isEnabledForJs()) {
|
||||
@@ -394,10 +388,8 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
@NotNull CompilerConfiguration configuration, @NotNull K2JSCompilerArguments arguments,
|
||||
@NotNull Services services
|
||||
) {
|
||||
if (K2JSCompilerArgumentsKt.isIrBackendEnabled(arguments)) {
|
||||
if (arguments.getIrBackend()) {
|
||||
getIrCompiler().setupPlatformSpecificArgumentsAndServices(configuration, arguments, services);
|
||||
}
|
||||
if (K2JSCompilerArgumentsKt.isPreIrBackendDisabled(arguments)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,12 +175,17 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
it.libraryFile.absolutePath in friendAbsolutePaths
|
||||
}
|
||||
|
||||
if (arguments.irProduceKlibDir || arguments.irProduceKlibFile) {
|
||||
val produceKind = produceMap[arguments.irProduceOnly]
|
||||
if (produceKind == null) {
|
||||
messageCollector.report(ERROR, "Unknown produce kind: ${arguments.irProduceOnly}. Valid values are: js, klib")
|
||||
}
|
||||
|
||||
if (produceKind == ProduceKind.KLIB || (produceKind == ProduceKind.DEFAULT && arguments.metaInfo)) {
|
||||
val outputKlibPath =
|
||||
if (arguments.irProduceKlibDir)
|
||||
if (arguments.irLegacyGradlePluginCompatibility)
|
||||
File(outputFilePath).parent
|
||||
else
|
||||
outputFilePath
|
||||
"$outputFilePath.klib"
|
||||
|
||||
generateKLib(
|
||||
project = config.project,
|
||||
@@ -189,11 +194,11 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
allDependencies = resolvedLibraries,
|
||||
friendDependencies = friendDependencies,
|
||||
outputKlibPath = outputKlibPath,
|
||||
nopack = arguments.irProduceKlibDir
|
||||
nopack = arguments.irLegacyGradlePluginCompatibility
|
||||
)
|
||||
}
|
||||
|
||||
if (arguments.irProduceJs) {
|
||||
if (produceKind == ProduceKind.JS || produceKind == ProduceKind.DEFAULT) {
|
||||
val phaseConfig = createPhaseConfig(jsPhases, arguments, messageCollector)
|
||||
|
||||
val compiledModule = compile(
|
||||
|
||||
+3
-1
@@ -10,8 +10,10 @@ abstract class AbstractIncrementalJsKlibCompilerRunnerTest : AbstractIncremental
|
||||
libraries = "build/js-ir-runtime/full-runtime.klib"
|
||||
outputFile = File(destinationDir, "${testDir.name}.klib").path
|
||||
sourceMap = true
|
||||
irBackend = true
|
||||
irProduceOnly = "klib"
|
||||
// Don't zip klib content since date on files affect the md5 checksum we compute to check whether output files identical
|
||||
irProduceKlibDir = true
|
||||
irLegacyGradlePluginCompatibility = true
|
||||
}
|
||||
|
||||
override val buildLogFinder: BuildLogFinder
|
||||
|
||||
+4
-5
@@ -3,11 +3,10 @@ where advanced options include:
|
||||
-Xenable-js-scripting Enable experimental support of .kts files using K/JS (with -Xir only)
|
||||
-Xfriend-modules=<path> Paths to friend modules
|
||||
-Xfriend-modules-disabled Disable internal declaration export
|
||||
-Xir-only Disables pre-IR backend
|
||||
-Xir-produce-js Generates JS file using IR backend. Also disables pre-IR backend
|
||||
-Xir-produce-klib-dir Generate unpacked KLIB into parent directory of output JS file.
|
||||
In combination with -meta-info generates both IR and pre-IR versions of library.
|
||||
-Xir-produce-klib-file Generate packed klib into file specified by -output. Disables pre-IR backend
|
||||
-Xir Use IR backend
|
||||
-Xir-legacy-gradle-plugin-compatibility
|
||||
Make KLIB generation compatible with legacy gradle plugin
|
||||
-Xir-produce-only={ klib, js } Type of output to produce. Overrides -meta-info argument.
|
||||
-Xmetadata-only Generate *.meta.js and *.kjsm files only
|
||||
-Xtyped-arrays Translate primitive arrays to JS typed arrays
|
||||
-Xallow-kotlin-package Allow compiling code in package 'kotlin' and allow not requiring kotlin.stdlib in module-info
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
description = 'Kotlin Test for JS IR'
|
||||
|
||||
apply plugin: 'kotlin-platform-js'
|
||||
|
||||
|
||||
dependencies {
|
||||
expectedBy project(':kotlin-test:kotlin-test-common')
|
||||
expectedBy project(':kotlin-test:kotlin-test-annotations-common')
|
||||
compile project(':kotlin-stdlib-js-ir')
|
||||
}
|
||||
|
||||
def jsCommonDir = "${buildDir}/common-js-sources"
|
||||
|
||||
task prepareCommonJsSources(type: Sync) {
|
||||
from "${projectDir}/../js/src/"
|
||||
into jsCommonDir
|
||||
}
|
||||
|
||||
compileKotlin2Js {
|
||||
dependsOn prepareCommonJsSources
|
||||
|
||||
kotlinOptions {
|
||||
moduleKind = "umd"
|
||||
freeCompilerArgs = [
|
||||
"-Xir",
|
||||
"-Xir-produce-only=klib",
|
||||
"-Xallow-kotlin-package",
|
||||
"-Xuse-experimental=kotlin.contracts.ExperimentalContracts",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
kotlin {
|
||||
srcDir jsCommonDir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileTestKotlin2Js {
|
||||
kotlinOptions.freeCompilerArgs = [
|
||||
"-Xir",
|
||||
"-Xir-produce-only=js",
|
||||
"-Xallow-kotlin-package",
|
||||
]
|
||||
kotlinOptions {
|
||||
metaInfo = false
|
||||
moduleKind = "umd"
|
||||
}
|
||||
}
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: classes) {
|
||||
classifier = 'sources'
|
||||
from(sourceSets.main.allSource)
|
||||
}
|
||||
|
||||
archivesBaseName = 'kotlin-test-js-ir'
|
||||
|
||||
jar {
|
||||
manifestAttributes(manifest, project, 'Test')
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives sourcesJar
|
||||
}
|
||||
|
||||
if (project.findProperty("kotlin.stdlib.js.ir.publish")?.toBoolean() == true) {
|
||||
configurePublishing(project)
|
||||
}
|
||||
@@ -16,11 +16,7 @@ dependencies {
|
||||
}
|
||||
|
||||
compileKotlin2Js {
|
||||
kotlinOptions.freeCompilerArgs = [
|
||||
"-Xallow-kotlin-package",
|
||||
"-Xuse-experimental=kotlin.contracts.ExperimentalContracts",
|
||||
"-Xir-produce-klib-dir"
|
||||
]
|
||||
kotlinOptions.freeCompilerArgs = ["-Xallow-kotlin-package", "-Xuse-experimental=kotlin.contracts.ExperimentalContracts"]
|
||||
kotlinOptions {
|
||||
moduleKind = "umd"
|
||||
outputFile = "${buildDir}/classes/main/kotlin-test.js"
|
||||
|
||||
@@ -92,7 +92,7 @@ configurations {
|
||||
dependencies {
|
||||
expectedBy project(":kotlin-stdlib-common")
|
||||
commonSources project(path: ":kotlin-stdlib-common", configuration: "sources")
|
||||
testCompile project(':kotlin-test:kotlin-test-js')
|
||||
testCompile project(':kotlin-test:kotlin-test-js-ir')
|
||||
}
|
||||
|
||||
|
||||
@@ -107,8 +107,8 @@ compileKotlin2Js {
|
||||
main = "noCall"
|
||||
verbose = true
|
||||
freeCompilerArgs += [
|
||||
"-Xir-produce-klib-dir",
|
||||
"-Xir-only",
|
||||
"-Xir",
|
||||
"-Xir-produce-only=klib",
|
||||
"-Xallow-kotlin-package",
|
||||
"-Xallow-result-return-type",
|
||||
"-Xuse-experimental=kotlin.Experimental",
|
||||
@@ -120,7 +120,7 @@ compileKotlin2Js {
|
||||
}
|
||||
|
||||
def testOutputFile = "${buildDir}/classes/kotlin/test/kotlin-stdlib-js-ir_test.js"
|
||||
def kotlinTestTestOutputFile = "${project(':kotlin-test:kotlin-test-js').buildDir}/classes/kotlin/test/kotlin-test-js-ir_test.js"
|
||||
def kotlinTestTestOutputFile = "${project(':kotlin-test:kotlin-test-js-ir').buildDir}/classes/kotlin/test/kotlin-test-js-ir_test.js"
|
||||
|
||||
compileTestKotlin2Js {
|
||||
kotlinOptions {
|
||||
@@ -128,7 +128,8 @@ compileTestKotlin2Js {
|
||||
verbose = true
|
||||
outputFile = testOutputFile
|
||||
freeCompilerArgs += [
|
||||
"-Xir-produce-js",
|
||||
"-Xir",
|
||||
"-Xir-produce-only=js",
|
||||
"-verbose",
|
||||
"-Xuse-experimental=kotlin.Experimental",
|
||||
"-Xuse-experimental=kotlin.ExperimentalUnsignedTypes",
|
||||
@@ -154,6 +155,11 @@ artifacts {
|
||||
archives sourcesJar
|
||||
}
|
||||
|
||||
|
||||
if (project.findProperty("kotlin.stdlib.js.ir.publish")?.toBoolean() == true) {
|
||||
configurePublishing(project)
|
||||
}
|
||||
|
||||
node {
|
||||
download = true
|
||||
version = '8.9.4' // The default 6.9.1 has buggy hyperbolic functions implementation
|
||||
@@ -171,7 +177,7 @@ task installTeamcityReporter(type: NpmTask) {
|
||||
task runMocha(type: NodeTask) {
|
||||
dependsOn compileTestKotlin2Js
|
||||
dependsOn installMocha
|
||||
dependsOn ':kotlin-test:kotlin-test-js:testClasses'
|
||||
dependsOn ':kotlin-test:kotlin-test-js-ir:testClasses'
|
||||
|
||||
script = file("${buildDir}/node_modules/mocha/bin/mocha")
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@ configurations {
|
||||
commonSources
|
||||
distSources
|
||||
distJs
|
||||
distLibrary
|
||||
}
|
||||
|
||||
def builtinsSrcDir = "${buildDir}/builtin-sources"
|
||||
@@ -284,10 +283,9 @@ jar {
|
||||
enabled false
|
||||
}
|
||||
|
||||
task libraryJarWithoutIr(type: Jar, dependsOn: compileJs) {
|
||||
task mergedJar(type: Jar, dependsOn: compileJs) {
|
||||
classifier = null
|
||||
manifestAttributes(manifest, project, 'Main')
|
||||
destinationDirectory = file("$buildDir/lib/dist")
|
||||
|
||||
// TODO: Use standard implementation title after js stdlib detector becomes more flexible (KT-17655)
|
||||
Properties properties = new Properties()
|
||||
@@ -309,22 +307,6 @@ task libraryJarWithoutIr(type: Jar, dependsOn: compileJs) {
|
||||
exclude "${experimentalJsModuleName}.*"
|
||||
}
|
||||
|
||||
task libraryJarWithIr(type: Zip, dependsOn: libraryJarWithoutIr) {
|
||||
def irStdlibJar = tasks.getByPath(":kotlin-stdlib-js-ir:jar")
|
||||
dependsOn(irStdlibJar)
|
||||
|
||||
archiveExtension = "jar"
|
||||
destinationDirectory = file("$buildDir/libs")
|
||||
|
||||
duplicatesStrategy DuplicatesStrategy.FAIL
|
||||
|
||||
from zipTree(libraryJarWithoutIr.archiveFile)
|
||||
from(zipTree(irStdlibJar.archiveFile)) {
|
||||
exclude 'META-INF/*'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task sourcesJar(type: Jar, dependsOn: compileJs) {
|
||||
classifier = 'sources'
|
||||
includeEmptyDirs false
|
||||
@@ -370,12 +352,11 @@ task distSourcesJar(type: Jar) {
|
||||
|
||||
|
||||
artifacts {
|
||||
runtime libraryJarWithIr
|
||||
archives libraryJarWithIr
|
||||
runtime mergedJar
|
||||
archives mergedJar
|
||||
archives sourcesJar
|
||||
sources sourcesJar
|
||||
distSources distSourcesJar
|
||||
distLibrary libraryJarWithoutIr
|
||||
|
||||
compileJs.outputs.files.forEach { artifact ->
|
||||
distJs(artifact) { builtBy(compileJs) }
|
||||
|
||||
@@ -105,10 +105,8 @@ 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,7 +198,6 @@ 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,
|
||||
@@ -720,7 +719,6 @@ 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) {
|
||||
|
||||
+201
-252
@@ -2,20 +2,169 @@ 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 Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true)
|
||||
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 Kotlin2JsGradlePluginIT : AbstractKotlin2JsGradlePluginIT(false) {
|
||||
@Test
|
||||
fun testKotlinJsBuiltins() {
|
||||
val project = Project("kotlinBuiltins")
|
||||
@@ -31,6 +180,49 @@ class Kotlin2JsGradlePluginIT : AbstractKotlin2JsGradlePluginIT(false) {
|
||||
}
|
||||
}
|
||||
|
||||
@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)
|
||||
@@ -113,239 +305,6 @@ class Kotlin2JsGradlePluginIT : AbstractKotlin2JsGradlePluginIT(false) {
|
||||
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
|
||||
@@ -353,7 +312,6 @@ abstract class AbstractKotlin2JsGradlePluginIT(private val irBackend: Boolean) :
|
||||
val project = Project("kotlin2JsProject")
|
||||
project.build("build") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
assertNotContains("this build assumes a single directory for all classes from a source set")
|
||||
}
|
||||
}
|
||||
@@ -362,11 +320,8 @@ abstract class AbstractKotlin2JsGradlePluginIT(private val irBackend: Boolean) :
|
||||
fun testIncrementalCompilation() = Project("kotlin2JsICProject").run {
|
||||
build("build") {
|
||||
assertSuccessful()
|
||||
checkIrCompilationMessage()
|
||||
if (!irBackend) { // TODO: Support incremental compilation
|
||||
assertContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertCompiledKotlinSources(project.relativize(allKotlinFiles))
|
||||
}
|
||||
assertContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
assertCompiledKotlinSources(project.relativize(allKotlinFiles))
|
||||
}
|
||||
|
||||
build("build") {
|
||||
@@ -379,13 +334,9 @@ abstract class AbstractKotlin2JsGradlePluginIT(private val irBackend: Boolean) :
|
||||
}
|
||||
build("build") {
|
||||
assertSuccessful()
|
||||
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))
|
||||
}
|
||||
assertContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||
val affectedFiles = project.projectDir.getFilesByNames("A.kt", "useAInLibMain.kt", "useAInAppMain.kt", "useAInAppTest.kt")
|
||||
assertCompiledKotlinSources(project.relativize(affectedFiles))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,14 +346,12 @@ abstract class AbstractKotlin2JsGradlePluginIT(private val irBackend: Boolean) :
|
||||
|
||||
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,9 +4,3 @@ 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,9 +3,3 @@ 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"]
|
||||
}
|
||||
|
||||
+1
-12
@@ -22,22 +22,11 @@ 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'
|
||||
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"]
|
||||
}
|
||||
args = ["-opt", "-1", "-f", "kotlin.js", "-f", "main/kotlin2JsInternalTest.js", "-f", "test/kotlin2JsInternalTest_test.js", "-f", "check.js"]
|
||||
}
|
||||
|
||||
build.doLast {
|
||||
|
||||
-1
@@ -22,7 +22,6 @@ fun <T> assertEquals(e: T, a: T) {
|
||||
if (e != a) throw Exception("Expected: $e, actual: $a")
|
||||
}
|
||||
|
||||
@JsExport
|
||||
fun test() {
|
||||
assertEquals("CONST", CONST)
|
||||
|
||||
|
||||
-4
@@ -16,10 +16,6 @@ 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,5 +16,4 @@
|
||||
|
||||
package foo
|
||||
|
||||
@JsExport
|
||||
fun bar() = "OK"
|
||||
|
||||
-5
@@ -17,9 +17,4 @@ 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"]
|
||||
}
|
||||
+1
-6
@@ -31,17 +31,12 @@ 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 (isIrBackend ? "**/*" : "**/*.js")
|
||||
include "**/*.js"
|
||||
|
||||
manifest {
|
||||
attributes(
|
||||
|
||||
-4
@@ -25,10 +25,6 @@ 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,12 +29,6 @@ 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,8 +30,3 @@ 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"]
|
||||
}
|
||||
+9
-31
@@ -16,7 +16,10 @@ import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
|
||||
import org.gradle.workers.WorkerExecutor
|
||||
import org.jetbrains.kotlin.build.DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS
|
||||
import org.jetbrains.kotlin.cli.common.arguments.*
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.compilerRunner.*
|
||||
import org.jetbrains.kotlin.daemon.common.MultiModuleICSettings
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
@@ -46,7 +49,6 @@ 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(),
|
||||
@@ -551,34 +553,9 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
||||
return friendPaths.filter { filter(File(it)) }
|
||||
}
|
||||
|
||||
private fun isHybridKotlinJsLibrary(file: File): Boolean =
|
||||
LibraryUtils.isKotlinJavascriptLibrary(file) && LibraryUtils.isKotlinJavascriptIrLibrary(file)
|
||||
|
||||
private fun KotlinJsOptions.isPreIrBackendDisabled(): Boolean =
|
||||
listOf(
|
||||
"-Xir-only",
|
||||
"-Xir-produce-js",
|
||||
"-Xir-produce-klib-file"
|
||||
).any(freeCompilerArgs::contains)
|
||||
|
||||
private fun KotlinJsOptions.isIrBackendEnabled(): Boolean =
|
||||
listOf(
|
||||
"-Xir-produce-klib-dir",
|
||||
"-Xir-produce-js",
|
||||
"-Xir-produce-klib-file"
|
||||
).any(freeCompilerArgs::contains)
|
||||
|
||||
// Kotlin/JS can operate in 3 modes:
|
||||
// 1) purely pre-IR backend
|
||||
// 2) purely IR backend
|
||||
// 3) hybrid pre-IR and IR backend. Can only accept libraries with both JS and IR parts.
|
||||
private val libraryFilter: (File) -> Boolean
|
||||
get() = if (kotlinOptions.isIrBackendEnabled()) {
|
||||
if (kotlinOptions.isPreIrBackendDisabled()) {
|
||||
LibraryUtils::isKotlinJavascriptIrLibrary
|
||||
} else {
|
||||
::isHybridKotlinJsLibrary
|
||||
}
|
||||
get() = if ("-Xir" in kotlinOptions.freeCompilerArgs) {
|
||||
LibraryUtils::isKotlinJavascriptIrLibrary
|
||||
} else {
|
||||
LibraryUtils::isKotlinJavascriptLibrary
|
||||
}
|
||||
@@ -589,9 +566,10 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
||||
logger.debug("Calling compiler")
|
||||
destinationDir.mkdirs()
|
||||
|
||||
if (kotlinOptions.isIrBackendEnabled()) {
|
||||
logger.info(USING_JS_IR_BACKEND_MESSAGE)
|
||||
if ("-Xir" in args.freeArgs) {
|
||||
logger.kotlinDebug("Using JS IR backend")
|
||||
incremental = false
|
||||
args.freeArgs += "-Xir-legacy-gradle-plugin-compatibility"
|
||||
}
|
||||
|
||||
val dependencies = compileClasspath
|
||||
|
||||
+2
-3
@@ -105,9 +105,8 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArgument
|
||||
arguments.setMetaInfo(metaInfo);
|
||||
arguments.setModuleKind(moduleKind);
|
||||
arguments.setMain(main);
|
||||
arguments.setIrOnly(useIrBackend);
|
||||
arguments.setIrProduceJs(useIrBackend);
|
||||
arguments.setIrProduceKlibDir(useIrBackend);
|
||||
arguments.setIrBackend(useIrBackend);
|
||||
arguments.setIrLegacyGradlePluginCompatibility(true);
|
||||
|
||||
List<String> libraries;
|
||||
try {
|
||||
|
||||
@@ -91,6 +91,7 @@ val distLibraryProjects = listOfNotNull(
|
||||
":kotlin-stdlib-js-ir".takeIf { kotlinBuildProperties.jsIrDist },
|
||||
":kotlin-source-sections-compiler-plugin",
|
||||
":kotlin-test:kotlin-test-js",
|
||||
":kotlin-test:kotlin-test-js-ir".takeIf { kotlinBuildProperties.jsIrDist },
|
||||
":kotlin-test:kotlin-test-junit",
|
||||
":kotlin-test:kotlin-test-junit5",
|
||||
":kotlin-test:kotlin-test-jvm",
|
||||
@@ -113,6 +114,7 @@ val distSourcesProjects = listOfNotNull(
|
||||
":kotlin-script-runtime",
|
||||
":kotlin-stdlib-js-ir".takeIf { kotlinBuildProperties.jsIrDist },
|
||||
":kotlin-test:kotlin-test-js",
|
||||
":kotlin-test:kotlin-test-js-ir".takeIf { kotlinBuildProperties.jsIrDist },
|
||||
":kotlin-test:kotlin-test-junit",
|
||||
":kotlin-test:kotlin-test-junit5",
|
||||
":kotlin-test:kotlin-test-jvm",
|
||||
@@ -147,7 +149,7 @@ dependencies {
|
||||
libraries(intellijDep()) { includeIntellijCoreJarDependencies(project) { it.startsWith("trove4j") } }
|
||||
libraries(commonDep("io.ktor", "ktor-network"))
|
||||
libraries(kotlinStdlib("jdk8"))
|
||||
libraries(kotlinStdlib("js", "distLibrary"))
|
||||
libraries(kotlinStdlib("js"))
|
||||
|
||||
distLibraryProjects.forEach {
|
||||
libraries(project(it)) { isTransitive = false }
|
||||
|
||||
@@ -274,6 +274,7 @@ if (flags.inJpsBuildIdeaSync) {
|
||||
":kotlin-stdlib-common",
|
||||
":kotlin-stdlib",
|
||||
":kotlin-stdlib-js",
|
||||
":kotlin-test:kotlin-test-js-ir",
|
||||
":kotlin-stdlib-js-ir",
|
||||
":kotlin-stdlib-jdk7",
|
||||
":kotlin-stdlib-jdk8",
|
||||
@@ -288,6 +289,7 @@ if (flags.inJpsBuildIdeaSync) {
|
||||
project(':kotlin-stdlib').projectDir = "$rootDir/libraries/stdlib/jvm" as File
|
||||
project(':kotlin-stdlib-js').projectDir = "$rootDir/libraries/stdlib/js-v1" as File
|
||||
project(':kotlin-stdlib-js-ir').projectDir = "$rootDir/libraries/stdlib/js-ir" as File
|
||||
project(':kotlin-test:kotlin-test-js-ir').projectDir = "$rootDir/libraries/kotlin.test/js-ir" as File
|
||||
project(':kotlin-stdlib-jdk7').projectDir = "$rootDir/libraries/stdlib/jdk7" as File
|
||||
project(':kotlin-stdlib-jdk8').projectDir = "$rootDir/libraries/stdlib/jdk8" as File
|
||||
project(':kotlin-stdlib:samples').projectDir = "$rootDir/libraries/stdlib/samples" as File
|
||||
|
||||
Reference in New Issue
Block a user