[Gradle, JS] Set compiler arg ir and produce-* unconditionally
^KT-63312 fixed
This commit is contained in:
committed by
Space Team
parent
41477b25a1
commit
342c9e8c81
-12
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.gradle.targets.js.npm.fromSrcPackageJson
|
|||||||
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.STORE_YARN_LOCK_NAME
|
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.STORE_YARN_LOCK_NAME
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.UPGRADE_YARN_LOCK
|
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.UPGRADE_YARN_LOCK
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.YARN_LOCK_MISMATCH_MESSAGE
|
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask.Companion.YARN_LOCK_MISMATCH_MESSAGE
|
||||||
import org.jetbrains.kotlin.gradle.tasks.USING_JS_IR_BACKEND_MESSAGE
|
|
||||||
import org.jetbrains.kotlin.gradle.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.jetbrains.kotlin.gradle.testbase.TestVersions.Gradle.G_7_6
|
import org.jetbrains.kotlin.gradle.testbase.TestVersions.Gradle.G_7_6
|
||||||
import org.jetbrains.kotlin.gradle.util.replaceText
|
import org.jetbrains.kotlin.gradle.util.replaceText
|
||||||
@@ -40,8 +39,6 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
|||||||
fun generateDts(gradleVersion: GradleVersion) {
|
fun generateDts(gradleVersion: GradleVersion) {
|
||||||
project("kotlin2JsIrDtsGeneration", gradleVersion) {
|
project("kotlin2JsIrDtsGeneration", gradleVersion) {
|
||||||
build("build") {
|
build("build") {
|
||||||
checkIrCompilationMessage()
|
|
||||||
|
|
||||||
assertFileInProjectExists("build/js/packages/kotlin2JsIrDtsGeneration/kotlin/kotlin2JsIrDtsGeneration.js")
|
assertFileInProjectExists("build/js/packages/kotlin2JsIrDtsGeneration/kotlin/kotlin2JsIrDtsGeneration.js")
|
||||||
val dts = projectPath.resolve("build/js/packages/kotlin2JsIrDtsGeneration/kotlin/kotlin2JsIrDtsGeneration.d.ts")
|
val dts = projectPath.resolve("build/js/packages/kotlin2JsIrDtsGeneration/kotlin/kotlin2JsIrDtsGeneration.d.ts")
|
||||||
assertFileExists(dts)
|
assertFileExists(dts)
|
||||||
@@ -747,17 +744,11 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun BuildResult.checkIrCompilationMessage() {
|
|
||||||
assertOutputContains(USING_JS_IR_BACKEND_MESSAGE)
|
|
||||||
}
|
|
||||||
|
|
||||||
@DisplayName("test compilation can access main compilation")
|
@DisplayName("test compilation can access main compilation")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
fun testCompileTestCouldAccessProduction(gradleVersion: GradleVersion) {
|
fun testCompileTestCouldAccessProduction(gradleVersion: GradleVersion) {
|
||||||
project("kotlin2JsProjectWithTests", gradleVersion) {
|
project("kotlin2JsProjectWithTests", gradleVersion) {
|
||||||
build("build") {
|
build("build") {
|
||||||
checkIrCompilationMessage()
|
|
||||||
|
|
||||||
assertTasksExecuted(
|
assertTasksExecuted(
|
||||||
":compileKotlinJs",
|
":compileKotlinJs",
|
||||||
":compileTestKotlinJs"
|
":compileTestKotlinJs"
|
||||||
@@ -774,7 +765,6 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
|||||||
fun testCompilerTestAccessInternalProduction(gradleVersion: GradleVersion) {
|
fun testCompilerTestAccessInternalProduction(gradleVersion: GradleVersion) {
|
||||||
project("kotlin2JsInternalTest", gradleVersion) {
|
project("kotlin2JsInternalTest", gradleVersion) {
|
||||||
build("build") {
|
build("build") {
|
||||||
checkIrCompilationMessage()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1180,8 +1170,6 @@ class Kotlin2JsIrGradlePluginIT : KGPBaseTest() {
|
|||||||
fun testNodeJsForkOptions(gradleVersion: GradleVersion) {
|
fun testNodeJsForkOptions(gradleVersion: GradleVersion) {
|
||||||
project("kotlin-js-nodejs-custom-node-module", gradleVersion) {
|
project("kotlin-js-nodejs-custom-node-module", gradleVersion) {
|
||||||
build("build") {
|
build("build") {
|
||||||
checkIrCompilationMessage()
|
|
||||||
|
|
||||||
// It makes sense only since Tests will be run on Gradle 7.2
|
// It makes sense only since Tests will be run on Gradle 7.2
|
||||||
assertOutputDoesNotContain("Execution optimizations have been disabled for task ':nodeTest'")
|
assertOutputDoesNotContain("Execution optimizations have been disabled for task ':nodeTest'")
|
||||||
|
|
||||||
|
|||||||
+1
-15
@@ -9,7 +9,6 @@ import org.gradle.api.logging.LogLevel
|
|||||||
import org.gradle.testkit.runner.BuildResult
|
import org.gradle.testkit.runner.BuildResult
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import org.jetbrains.kotlin.gradle.tasks.USING_JS_INCREMENTAL_COMPILATION_MESSAGE
|
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.testbase.*
|
import org.jetbrains.kotlin.gradle.testbase.*
|
||||||
import org.junit.jupiter.api.DisplayName
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
|
||||||
@@ -36,21 +35,12 @@ abstract class AbstractKotlinJsIncrementalGradlePluginIT(
|
|||||||
jsOptions = defaultJsOptions,
|
jsOptions = defaultJsOptions,
|
||||||
)
|
)
|
||||||
|
|
||||||
protected fun BuildResult.checkIrCompilationMessage() {
|
|
||||||
if (irBackend) {
|
|
||||||
assertOutputContains(USING_JS_IR_BACKEND_MESSAGE)
|
|
||||||
} else {
|
|
||||||
assertOutputDoesNotContain(USING_JS_IR_BACKEND_MESSAGE)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@DisplayName("incremental compilation for js works")
|
@DisplayName("incremental compilation for js works")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
fun testIncrementalCompilation(gradleVersion: GradleVersion) {
|
fun testIncrementalCompilation(gradleVersion: GradleVersion) {
|
||||||
val buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
val buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)
|
||||||
project("kotlin2JsICProject", gradleVersion, buildOptions = buildOptions) {
|
project("kotlin2JsICProject", gradleVersion, buildOptions = buildOptions) {
|
||||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||||
checkIrCompilationMessage()
|
|
||||||
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||||
assertCompiledKotlinSources(projectPath.allKotlinFiles.relativizeTo(projectPath), output)
|
assertCompiledKotlinSources(projectPath.allKotlinFiles.relativizeTo(projectPath), output)
|
||||||
}
|
}
|
||||||
@@ -64,7 +54,6 @@ abstract class AbstractKotlinJsIncrementalGradlePluginIT(
|
|||||||
it.replace("val x = 0", "val x = \"a\"")
|
it.replace("val x = 0", "val x = \"a\"")
|
||||||
}
|
}
|
||||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||||
checkIrCompilationMessage()
|
|
||||||
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
assertOutputContains(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||||
val affectedFiles = listOf("A.kt", "useAInLibMain.kt", "useAInAppMain.kt", "useAInAppTest.kt").mapNotNull {
|
val affectedFiles = listOf("A.kt", "useAInLibMain.kt", "useAInAppMain.kt", "useAInAppTest.kt").mapNotNull {
|
||||||
projectPath.findInPath(it)
|
projectPath.findInPath(it)
|
||||||
@@ -77,13 +66,10 @@ abstract class AbstractKotlinJsIncrementalGradlePluginIT(
|
|||||||
@DisplayName("non-incremental compilation works")
|
@DisplayName("non-incremental compilation works")
|
||||||
@GradleTest
|
@GradleTest
|
||||||
fun testIncrementalCompilationDisabled(gradleVersion: GradleVersion) {
|
fun testIncrementalCompilationDisabled(gradleVersion: GradleVersion) {
|
||||||
val jsOptions = defaultJsOptions.run {
|
val jsOptions = defaultJsOptions.copy(incrementalJsKlib = false, incrementalJs = false)
|
||||||
if (irBackend) copy(incrementalJsKlib = false) else copy(incrementalJs = false)
|
|
||||||
}
|
|
||||||
val options = defaultBuildOptions.copy(jsOptions = jsOptions)
|
val options = defaultBuildOptions.copy(jsOptions = jsOptions)
|
||||||
project("kotlin2JsICProject", gradleVersion, buildOptions = options) {
|
project("kotlin2JsICProject", gradleVersion, buildOptions = options) {
|
||||||
build("compileKotlinJs", "compileTestKotlinJs") {
|
build("compileKotlinJs", "compileTestKotlinJs") {
|
||||||
checkIrCompilationMessage()
|
|
||||||
assertOutputDoesNotContain(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
assertOutputDoesNotContain(USING_JS_INCREMENTAL_COMPILATION_MESSAGE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ internal interface UsesLibraryFilterCachingService : Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal abstract class LibraryFilterCachingService : BuildService<BuildServiceParameters.None>, AutoCloseable {
|
internal abstract class LibraryFilterCachingService : BuildService<BuildServiceParameters.None>, AutoCloseable {
|
||||||
internal data class LibraryFilterCacheKey(val dependency: File, val irEnabled: Boolean, val preIrDisabled: Boolean)
|
internal data class LibraryFilterCacheKey(val dependency: File)
|
||||||
|
|
||||||
private val cache = ConcurrentHashMap<LibraryFilterCacheKey, Boolean>()
|
private val cache = ConcurrentHashMap<LibraryFilterCacheKey, Boolean>()
|
||||||
|
|
||||||
|
|||||||
-5
@@ -9,16 +9,11 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
|||||||
* @see [compiler/testData/cli/js/jsExtraHelp.out]
|
* @see [compiler/testData/cli/js/jsExtraHelp.out]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
internal const val ENTRY_IR_MODULE = "-Xinclude"
|
|
||||||
|
|
||||||
internal const val DISABLE_PRE_IR = "-Xir-only"
|
|
||||||
internal const val ENABLE_DCE = "-Xir-dce"
|
internal const val ENABLE_DCE = "-Xir-dce"
|
||||||
|
|
||||||
internal const val GENERATE_D_TS = "-Xgenerate-dts"
|
internal const val GENERATE_D_TS = "-Xgenerate-dts"
|
||||||
|
|
||||||
internal const val PRODUCE_JS = "-Xir-produce-js"
|
|
||||||
internal const val PRODUCE_UNZIPPED_KLIB = "-Xir-produce-klib-dir"
|
internal const val PRODUCE_UNZIPPED_KLIB = "-Xir-produce-klib-dir"
|
||||||
internal const val PRODUCE_ZIPPED_KLIB = "-Xir-produce-klib-file"
|
|
||||||
|
|
||||||
internal const val MINIMIZED_MEMBER_NAMES = "-Xir-minimized-member-names"
|
internal const val MINIMIZED_MEMBER_NAMES = "-Xir-minimized-member-names"
|
||||||
|
|
||||||
|
|||||||
+6
-3
@@ -58,7 +58,7 @@ abstract class KotlinJsIrLink @Inject constructor(
|
|||||||
internal val propertiesProvider = PropertiesProvider(project)
|
internal val propertiesProvider = PropertiesProvider(project)
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
internal val incrementalJsIr: Boolean = propertiesProvider.incrementalJsIr
|
var incrementalJsIr: Boolean = propertiesProvider.incrementalJsIr
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
val outputGranularity: KotlinJsIrOutputGranularity = propertiesProvider.jsIrOutputGranularity
|
val outputGranularity: KotlinJsIrOutputGranularity = propertiesProvider.jsIrOutputGranularity
|
||||||
@@ -96,10 +96,13 @@ abstract class KotlinJsIrLink @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun contributeAdditionalCompilerArguments(context: ContributeCompilerArgumentsContext<K2JSCompilerArguments>) {
|
override fun isIncrementalCompilationEnabled(): Boolean = false
|
||||||
super.contributeAdditionalCompilerArguments(context)
|
|
||||||
|
|
||||||
|
override fun contributeAdditionalCompilerArguments(context: ContributeCompilerArgumentsContext<K2JSCompilerArguments>) {
|
||||||
context.primitive { args ->
|
context.primitive { args ->
|
||||||
|
args.irOnly = true
|
||||||
|
args.irProduceJs = true
|
||||||
|
|
||||||
// moduleName can start with @ for group of NPM packages
|
// moduleName can start with @ for group of NPM packages
|
||||||
// but args parsing @ as start of argfile
|
// but args parsing @ as start of argfile
|
||||||
// so WA we provide moduleName as one parameter
|
// so WA we provide moduleName as one parameter
|
||||||
|
|||||||
+1
-3
@@ -464,9 +464,7 @@ constructor(
|
|||||||
internal override val compilerOptions: KotlinJsCompilerOptions = project.objects
|
internal override val compilerOptions: KotlinJsCompilerOptions = project.objects
|
||||||
.newInstance<KotlinJsCompilerOptionsDefault>()
|
.newInstance<KotlinJsCompilerOptionsDefault>()
|
||||||
.apply {
|
.apply {
|
||||||
configureJsDefaultOptions(platformType)
|
configureJsDefaultOptions()
|
||||||
|
|
||||||
freeCompilerArgs.add(DISABLE_PRE_IR)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-11
@@ -9,22 +9,15 @@ import org.jetbrains.kotlin.gradle.dsl.JsModuleKind
|
|||||||
import org.jetbrains.kotlin.gradle.dsl.JsSourceMapEmbedMode
|
import org.jetbrains.kotlin.gradle.dsl.JsSourceMapEmbedMode
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
|
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompilerOptions
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinOnlyTargetConfigurator
|
import org.jetbrains.kotlin.gradle.plugin.KotlinOnlyTargetConfigurator
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
|
||||||
|
|
||||||
open class KotlinJsIrTargetConfigurator :
|
open class KotlinJsIrTargetConfigurator :
|
||||||
KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget>(true) {
|
KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget>(true) {
|
||||||
|
|
||||||
internal companion object {
|
internal companion object {
|
||||||
internal fun KotlinJsCompilerOptions.configureJsDefaultOptions(
|
internal fun KotlinJsCompilerOptions.configureJsDefaultOptions() {
|
||||||
platformType: KotlinPlatformType,
|
moduleKind.convention(JsModuleKind.MODULE_UMD)
|
||||||
) {
|
sourceMap.convention(true)
|
||||||
moduleKind.set(JsModuleKind.MODULE_UMD)
|
sourceMapEmbedSources.convention(JsSourceMapEmbedMode.SOURCE_MAP_SOURCE_CONTENT_NEVER)
|
||||||
sourceMap.set(true)
|
|
||||||
sourceMapEmbedSources.set(JsSourceMapEmbedMode.SOURCE_MAP_SOURCE_CONTENT_NEVER)
|
|
||||||
|
|
||||||
if (platformType == KotlinPlatformType.wasm) {
|
|
||||||
freeCompilerArgs.add(WASM_BACKEND)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-86
@@ -35,10 +35,6 @@ import org.jetbrains.kotlin.gradle.plugin.statistics.UsesBuildFusService
|
|||||||
import org.jetbrains.kotlin.gradle.report.BuildReportMode
|
import org.jetbrains.kotlin.gradle.report.BuildReportMode
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.internal.LibraryFilterCachingService
|
import org.jetbrains.kotlin.gradle.targets.js.internal.LibraryFilterCachingService
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.internal.UsesLibraryFilterCachingService
|
import org.jetbrains.kotlin.gradle.targets.js.internal.UsesLibraryFilterCachingService
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.DISABLE_PRE_IR
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.PRODUCE_JS
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.PRODUCE_UNZIPPED_KLIB
|
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.ir.PRODUCE_ZIPPED_KLIB
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.internal.KotlinJsOptionsCompat
|
import org.jetbrains.kotlin.gradle.tasks.internal.KotlinJsOptionsCompat
|
||||||
import org.jetbrains.kotlin.gradle.utils.getFile
|
import org.jetbrains.kotlin.gradle.utils.getFile
|
||||||
import org.jetbrains.kotlin.gradle.utils.isParentOf
|
import org.jetbrains.kotlin.gradle.utils.isParentOf
|
||||||
@@ -47,7 +43,6 @@ import org.jetbrains.kotlin.gradle.utils.toPathsArray
|
|||||||
import org.jetbrains.kotlin.incremental.ClasspathChanges
|
import org.jetbrains.kotlin.incremental.ClasspathChanges
|
||||||
import org.jetbrains.kotlin.library.impl.isKotlinLibrary
|
import org.jetbrains.kotlin.library.impl.isKotlinLibrary
|
||||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||||
import org.jetbrains.kotlin.utils.JsLibraryUtils
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -77,26 +72,11 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
|||||||
internal var incrementalJsKlib: Boolean = true
|
internal var incrementalJsKlib: Boolean = true
|
||||||
|
|
||||||
override fun isIncrementalCompilationEnabled(): Boolean {
|
override fun isIncrementalCompilationEnabled(): Boolean {
|
||||||
val freeArgs = enhancedFreeCompilerArgs.get()
|
val result = incrementalJsKlib || incremental
|
||||||
return when {
|
buildFusService.orNull?.reportFusMetrics {
|
||||||
PRODUCE_JS in freeArgs -> false
|
it.report(BooleanMetrics.JS_KLIB_INCREMENTAL, result)
|
||||||
|
|
||||||
PRODUCE_UNZIPPED_KLIB in freeArgs -> {
|
|
||||||
buildFusService.orNull?.reportFusMetrics {
|
|
||||||
it.report(BooleanMetrics.JS_KLIB_INCREMENTAL, incrementalJsKlib)
|
|
||||||
}
|
|
||||||
incrementalJsKlib
|
|
||||||
}
|
|
||||||
|
|
||||||
PRODUCE_ZIPPED_KLIB in freeArgs -> {
|
|
||||||
buildFusService.orNull?.reportFusMetrics {
|
|
||||||
it.report(BooleanMetrics.JS_KLIB_INCREMENTAL, incrementalJsKlib)
|
|
||||||
}
|
|
||||||
incrementalJsKlib
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> incremental
|
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround to be able to use default value and change it later based on external input
|
// Workaround to be able to use default value and change it later based on external input
|
||||||
@@ -148,18 +128,14 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
|||||||
|
|
||||||
KotlinJsCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args)
|
KotlinJsCompilerOptionsHelper.fillCompilerArguments(compilerOptions, args)
|
||||||
|
|
||||||
if (isIrBackendEnabled()) {
|
val outputFilePath: String? = compilerOptions.outputFile.orNull
|
||||||
val outputFilePath: String? = compilerOptions.outputFile.orNull
|
if (outputFilePath != null) {
|
||||||
if (outputFilePath != null) {
|
val outputFile = File(outputFilePath)
|
||||||
val outputFile = File(outputFilePath)
|
args.outputDir = (if (outputFile.extension == "") outputFile else outputFile.parentFile).normalize().absolutePath
|
||||||
args.outputDir = (if (outputFile.extension == "") outputFile else outputFile.parentFile).normalize().absolutePath
|
args.moduleName = outputFile.nameWithoutExtension
|
||||||
args.moduleName = outputFile.nameWithoutExtension
|
|
||||||
} else {
|
|
||||||
args.outputDir = destinationDirectory.get().asFile.normalize().absolutePath
|
|
||||||
args.moduleName = compilerOptions.moduleName.get()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
args.outputFile = outputFileProperty.get().absoluteFile.normalize().absolutePath
|
args.outputDir = destinationDirectory.get().asFile.normalize().absolutePath
|
||||||
|
args.moduleName = compilerOptions.moduleName.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compilerOptions.usesK2.get()) {
|
if (compilerOptions.usesK2.get()) {
|
||||||
@@ -228,58 +204,15 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
|||||||
.directoryProperty()
|
.directoryProperty()
|
||||||
.value(project.layout.projectDirectory)
|
.value(project.layout.projectDirectory)
|
||||||
|
|
||||||
private fun isHybridKotlinJsLibrary(file: File): Boolean =
|
|
||||||
JsLibraryUtils.isKotlinJavascriptLibrary(file) && isKotlinLibrary(file)
|
|
||||||
|
|
||||||
private val preIrBackendCompilerFlags = listOf(
|
|
||||||
DISABLE_PRE_IR,
|
|
||||||
PRODUCE_JS,
|
|
||||||
PRODUCE_ZIPPED_KLIB
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun isPreIrBackendDisabled(): Boolean = enhancedFreeCompilerArgs
|
|
||||||
.get()
|
|
||||||
.any { preIrBackendCompilerFlags.contains(it) }
|
|
||||||
|
|
||||||
// see also isIncrementalCompilationEnabled
|
|
||||||
private val irBackendCompilerFlags = listOf(
|
|
||||||
PRODUCE_UNZIPPED_KLIB,
|
|
||||||
PRODUCE_JS,
|
|
||||||
PRODUCE_ZIPPED_KLIB
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun isIrBackendEnabled(): Boolean = enhancedFreeCompilerArgs
|
|
||||||
.get()
|
|
||||||
.any { irBackendCompilerFlags.contains(it) }
|
|
||||||
|
|
||||||
private val File.asLibraryFilterCacheKey: LibraryFilterCachingService.LibraryFilterCacheKey
|
private val File.asLibraryFilterCacheKey: LibraryFilterCachingService.LibraryFilterCacheKey
|
||||||
get() = LibraryFilterCachingService.LibraryFilterCacheKey(
|
get() = LibraryFilterCachingService.LibraryFilterCacheKey(
|
||||||
this,
|
this
|
||||||
irEnabled = isIrBackendEnabled(),
|
|
||||||
preIrDisabled = isPreIrBackendDisabled()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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 libraryFilterBody: (File) -> Boolean
|
|
||||||
get() = if (isIrBackendEnabled()) {
|
|
||||||
if (isPreIrBackendDisabled()) {
|
|
||||||
//::isKotlinLibrary
|
|
||||||
// Workaround for KT-47797
|
|
||||||
{ isKotlinLibrary(it) }
|
|
||||||
} else {
|
|
||||||
::isHybridKotlinJsLibrary
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
JsLibraryUtils::isKotlinJavascriptLibrary
|
|
||||||
}
|
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
protected val libraryFilter: (File) -> Boolean
|
protected val libraryFilter: (File) -> Boolean
|
||||||
get() = { file ->
|
get() = { file ->
|
||||||
libraryFilterCacheService.get().getOrCompute(file.asLibraryFilterCacheKey, libraryFilterBody)
|
libraryFilterCacheService.get().getOrCompute(file.asLibraryFilterCacheKey, ::isKotlinLibrary)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val incrementalProps: List<FileCollection>
|
override val incrementalProps: List<FileCollection>
|
||||||
@@ -287,21 +220,22 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
|||||||
|
|
||||||
protected open fun processArgsBeforeCompile(args: K2JSCompilerArguments) = Unit
|
protected open fun processArgsBeforeCompile(args: K2JSCompilerArguments) = Unit
|
||||||
|
|
||||||
protected open fun contributeAdditionalCompilerArguments(context: ContributeCompilerArgumentsContext<K2JSCompilerArguments>) = Unit
|
protected open fun contributeAdditionalCompilerArguments(context: ContributeCompilerArgumentsContext<K2JSCompilerArguments>) {
|
||||||
|
context.primitive { args ->
|
||||||
|
args.irOnly = true
|
||||||
|
args.irProduceKlibDir = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun callCompilerAsync(
|
override fun callCompilerAsync(
|
||||||
args: K2JSCompilerArguments,
|
args: K2JSCompilerArguments,
|
||||||
inputChanges: InputChanges,
|
inputChanges: InputChanges,
|
||||||
taskOutputsBackup: TaskOutputsBackup?
|
taskOutputsBackup: TaskOutputsBackup?,
|
||||||
) {
|
) {
|
||||||
logger.debug("Calling compiler")
|
logger.debug("Calling compiler")
|
||||||
|
|
||||||
validateOutputDirectory()
|
validateOutputDirectory()
|
||||||
|
|
||||||
if (isIrBackendEnabled()) {
|
|
||||||
logger.info(USING_JS_IR_BACKEND_MESSAGE)
|
|
||||||
}
|
|
||||||
|
|
||||||
val dependencies = libraries
|
val dependencies = libraries
|
||||||
.filter { it.exists() && libraryFilter(it) }
|
.filter { it.exists() && libraryFilter(it) }
|
||||||
.map { it.normalize().absolutePath }
|
.map { it.normalize().absolutePath }
|
||||||
|
|||||||
-1
@@ -11,7 +11,6 @@ import org.gradle.api.tasks.TaskProvider
|
|||||||
const val KOTLIN_BUILD_DIR_NAME = "kotlin"
|
const val KOTLIN_BUILD_DIR_NAME = "kotlin"
|
||||||
const val USING_JVM_INCREMENTAL_COMPILATION_MESSAGE = "Using Kotlin/JVM incremental compilation"
|
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_INCREMENTAL_COMPILATION_MESSAGE = "Using Kotlin/JS incremental compilation"
|
||||||
const val USING_JS_IR_BACKEND_MESSAGE = "Using Kotlin/JS IR backend"
|
|
||||||
|
|
||||||
internal inline val <reified T : Task> T.thisTaskProvider: TaskProvider<out T>
|
internal inline val <reified T : Task> T.thisTaskProvider: TaskProvider<out T>
|
||||||
get() = checkNotNull(project.locateTask<T>(name))
|
get() = checkNotNull(project.locateTask<T>(name))
|
||||||
+10
-22
@@ -23,7 +23,7 @@ import java.io.File
|
|||||||
internal typealias Kotlin2JsCompileConfig = BaseKotlin2JsCompileConfig<Kotlin2JsCompile>
|
internal typealias Kotlin2JsCompileConfig = BaseKotlin2JsCompileConfig<Kotlin2JsCompile>
|
||||||
|
|
||||||
internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
||||||
compilation: KotlinCompilationInfo
|
compilation: KotlinCompilationInfo,
|
||||||
) : AbstractKotlinCompileConfig<TASK>(compilation) {
|
) : AbstractKotlinCompileConfig<TASK>(compilation) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
@@ -90,7 +90,7 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
|||||||
|
|
||||||
protected open fun configureAdditionalFreeCompilerArguments(
|
protected open fun configureAdditionalFreeCompilerArguments(
|
||||||
task: TASK,
|
task: TASK,
|
||||||
compilation: KotlinCompilationInfo
|
compilation: KotlinCompilationInfo,
|
||||||
) {
|
) {
|
||||||
task.enhancedFreeCompilerArgs.value(
|
task.enhancedFreeCompilerArgs.value(
|
||||||
task.compilerOptions.freeCompilerArgs.map { freeArgs ->
|
task.compilerOptions.freeCompilerArgs.map { freeArgs ->
|
||||||
@@ -102,28 +102,16 @@ internal open class BaseKotlin2JsCompileConfig<TASK : Kotlin2JsCompile>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun MutableList<String>.commonJsAdditionalCompilerFlags(
|
protected fun MutableList<String>.commonJsAdditionalCompilerFlags(
|
||||||
compilation: KotlinCompilationInfo
|
compilation: KotlinCompilationInfo,
|
||||||
) {
|
) {
|
||||||
if (contains(DISABLE_PRE_IR) &&
|
// Configure FQ module name to avoid cyclic dependencies in klib manifests (see KT-36721).
|
||||||
!contains(PRODUCE_UNZIPPED_KLIB) &&
|
val baseName = if (compilation.isMain) {
|
||||||
!contains(PRODUCE_ZIPPED_KLIB)
|
project.name
|
||||||
) {
|
} else {
|
||||||
add(PRODUCE_UNZIPPED_KLIB)
|
"${project.name}_${compilation.compilationName}"
|
||||||
}
|
}
|
||||||
|
if (none { it.startsWith(KLIB_MODULE_NAME) }) {
|
||||||
if (contains(PRODUCE_JS) ||
|
add("$KLIB_MODULE_NAME=${project.klibModuleName(baseName)}")
|
||||||
contains(PRODUCE_UNZIPPED_KLIB) ||
|
|
||||||
contains(PRODUCE_ZIPPED_KLIB)
|
|
||||||
) {
|
|
||||||
// Configure FQ module name to avoid cyclic dependencies in klib manifests (see KT-36721).
|
|
||||||
val baseName = if (compilation.isMain) {
|
|
||||||
project.name
|
|
||||||
} else {
|
|
||||||
"${project.name}_${compilation.compilationName}"
|
|
||||||
}
|
|
||||||
if (none { it.startsWith(KLIB_MODULE_NAME) }) {
|
|
||||||
add("$KLIB_MODULE_NAME=${project.klibModuleName(baseName)}")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compilation.platformType == KotlinPlatformType.wasm) {
|
if (compilation.platformType == KotlinPlatformType.wasm) {
|
||||||
|
|||||||
-2
@@ -95,8 +95,6 @@ internal open class KotlinJsIrLinkConfig(
|
|||||||
if (none { it.startsWith(arg) }) add(arg)
|
if (none { it.startsWith(arg) }) add(arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
add(PRODUCE_JS)
|
|
||||||
|
|
||||||
if (compilation.platformType == KotlinPlatformType.wasm) {
|
if (compilation.platformType == KotlinPlatformType.wasm) {
|
||||||
add(WASM_BACKEND)
|
add(WASM_BACKEND)
|
||||||
val wasmTargetType = ((compilation.origin as KotlinJsIrCompilation).target as KotlinJsIrTarget).wasmTargetType!!
|
val wasmTargetType = ((compilation.origin as KotlinJsIrCompilation).target as KotlinJsIrTarget).wasmTargetType!!
|
||||||
|
|||||||
Reference in New Issue
Block a user