[Gradle, JS] Add gradle property for per-module/whole-program
Merge-request: KT-MR-5200
This commit is contained in:
@@ -404,7 +404,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
fullJs = true,
|
fullJs = true,
|
||||||
dceJs = arguments.irDce,
|
dceJs = arguments.irDce,
|
||||||
multiModule = arguments.irPerModule,
|
multiModule = arguments.irPerModule,
|
||||||
relativeRequirePath = false,
|
relativeRequirePath = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
transformer.generateModule(ir.allModules)
|
transformer.generateModule(ir.allModules)
|
||||||
@@ -415,7 +415,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
fullJs = true,
|
fullJs = true,
|
||||||
dceJs = arguments.irDce,
|
dceJs = arguments.irDce,
|
||||||
multiModule = arguments.irPerModule,
|
multiModule = arguments.irPerModule,
|
||||||
relativeRequirePath = false,
|
relativeRequirePath = true,
|
||||||
)
|
)
|
||||||
|
|
||||||
transformer.generateModule(ir.allModules)
|
transformer.generateModule(ir.allModules)
|
||||||
|
|||||||
+5
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
import org.jetbrains.kotlin.gradle.plugin.statistics.KotlinBuildStatsService
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat
|
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat.Companion.externalsOutputFormatProperty
|
import org.jetbrains.kotlin.gradle.targets.js.dukat.ExternalsOutputFormat.Companion.externalsOutputFormatProperty
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrOutputGranularity
|
||||||
import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion
|
import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.DisabledNativeTargetsReporter
|
import org.jetbrains.kotlin.gradle.targets.native.DisabledNativeTargetsReporter
|
||||||
import org.jetbrains.kotlin.gradle.tasks.*
|
import org.jetbrains.kotlin.gradle.tasks.*
|
||||||
@@ -103,6 +104,10 @@ internal class PropertiesProvider private constructor(private val project: Proje
|
|||||||
val incrementalJsIr: Boolean
|
val incrementalJsIr: Boolean
|
||||||
get() = booleanProperty("kotlin.incremental.js.ir") ?: false
|
get() = booleanProperty("kotlin.incremental.js.ir") ?: false
|
||||||
|
|
||||||
|
val jsIrOutputGranularity: KotlinJsIrOutputGranularity
|
||||||
|
get() = property("kotlin.js.ir.output.granularity")?.let { KotlinJsIrOutputGranularity.byArgument(it) }
|
||||||
|
?: KotlinJsIrOutputGranularity.PER_MODULE
|
||||||
|
|
||||||
val incrementalMultiplatform: Boolean?
|
val incrementalMultiplatform: Boolean?
|
||||||
get() = booleanProperty("kotlin.incremental.multiplatform")
|
get() = booleanProperty("kotlin.incremental.multiplatform")
|
||||||
|
|
||||||
|
|||||||
+1
@@ -24,6 +24,7 @@ internal const val PRODUCE_ZIPPED_KLIB = "-Xir-produce-klib-file"
|
|||||||
|
|
||||||
internal const val MODULE_NAME = "-Xir-module-name"
|
internal const val MODULE_NAME = "-Xir-module-name"
|
||||||
|
|
||||||
|
internal const val PER_MODULE = "-Xir-per-module"
|
||||||
internal const val PER_MODULE_OUTPUT_NAME = "-Xir-per-module-output-name"
|
internal const val PER_MODULE_OUTPUT_NAME = "-Xir-per-module-output-name"
|
||||||
|
|
||||||
internal const val WASM_BACKEND = "-Xwasm"
|
internal const val WASM_BACKEND = "-Xwasm"
|
||||||
|
|||||||
+25
-1
@@ -17,6 +17,8 @@ import org.gradle.api.tasks.*
|
|||||||
import org.gradle.work.InputChanges
|
import org.gradle.work.InputChanges
|
||||||
import org.gradle.workers.WorkerExecutor
|
import org.gradle.workers.WorkerExecutor
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments
|
||||||
|
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
|
||||||
|
import org.jetbrains.kotlin.compilerRunner.ArgumentUtils
|
||||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment
|
import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment
|
||||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
||||||
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
|
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
|
||||||
@@ -41,6 +43,7 @@ import org.jetbrains.kotlin.gradle.utils.getCacheDirectory
|
|||||||
import org.jetbrains.kotlin.gradle.utils.getDependenciesCacheDirectories
|
import org.jetbrains.kotlin.gradle.utils.getDependenciesCacheDirectories
|
||||||
import org.jetbrains.kotlin.gradle.utils.getValue
|
import org.jetbrains.kotlin.gradle.utils.getValue
|
||||||
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
import org.jetbrains.kotlin.statistics.metrics.BooleanMetrics
|
||||||
|
import org.jetbrains.kotlin.statistics.metrics.StringMetrics
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@@ -70,8 +73,15 @@ abstract class KotlinJsIrLink @Inject constructor(
|
|||||||
@get:Internal
|
@get:Internal
|
||||||
internal lateinit var compilation: KotlinCompilationData<*>
|
internal lateinit var compilation: KotlinCompilationData<*>
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
@get:Internal
|
||||||
|
internal val propertiesProvider = PropertiesProvider(project)
|
||||||
|
|
||||||
@get:Input
|
@get:Input
|
||||||
internal val incrementalJsIr: Boolean = PropertiesProvider(project).incrementalJsIr
|
internal val incrementalJsIr: Boolean = propertiesProvider.incrementalJsIr
|
||||||
|
|
||||||
|
@get:Input
|
||||||
|
val outputGranularity: KotlinJsIrOutputGranularity = propertiesProvider.jsIrOutputGranularity
|
||||||
|
|
||||||
// Link tasks are not affected by compiler plugin
|
// Link tasks are not affected by compiler plugin
|
||||||
override val pluginClasspath: ConfigurableFileCollection = project.objects.fileCollection()
|
override val pluginClasspath: ConfigurableFileCollection = project.objects.fileCollection()
|
||||||
@@ -111,6 +121,15 @@ abstract class KotlinJsIrLink @Inject constructor(
|
|||||||
) {
|
) {
|
||||||
KotlinBuildStatsService.applyIfInitialised {
|
KotlinBuildStatsService.applyIfInitialised {
|
||||||
it.report(BooleanMetrics.JS_IR_INCREMENTAL, incrementalJsIr)
|
it.report(BooleanMetrics.JS_IR_INCREMENTAL, incrementalJsIr)
|
||||||
|
val newArgs = K2JSCompilerArguments()
|
||||||
|
parseCommandLineArguments(ArgumentUtils.convertArgumentsToStringList(args), newArgs)
|
||||||
|
it.report(
|
||||||
|
StringMetrics.JS_OUTPUT_GRANULARITY,
|
||||||
|
if (newArgs.irPerModule)
|
||||||
|
KotlinJsIrOutputGranularity.PER_MODULE.name.toLowerCase()
|
||||||
|
else
|
||||||
|
KotlinJsIrOutputGranularity.WHOLE_PROGRAM.name.toLowerCase()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (incrementalJsIr && mode == DEVELOPMENT) {
|
if (incrementalJsIr && mode == DEVELOPMENT) {
|
||||||
val visitedCompilations = mutableSetOf<KotlinCompilation<*>>()
|
val visitedCompilations = mutableSetOf<KotlinCompilation<*>>()
|
||||||
@@ -177,6 +196,11 @@ abstract class KotlinJsIrLink @Inject constructor(
|
|||||||
kotlinOptions.configureOptions(GENERATE_D_TS)
|
kotlinOptions.configureOptions(GENERATE_D_TS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val alreadyDefinedOutputMode = kotlinOptions.freeCompilerArgs
|
||||||
|
.any { it.startsWith(PER_MODULE) }
|
||||||
|
if (!alreadyDefinedOutputMode) {
|
||||||
|
kotlinOptions.freeCompilerArgs += outputGranularity.toCompilerArgument()
|
||||||
|
}
|
||||||
super.setupCompilerArgs(args, defaultsOnly, ignoreClasspathResolutionErrors)
|
super.setupCompilerArgs(args, defaultsOnly, ignoreClasspathResolutionErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||||
|
|
||||||
|
enum class KotlinJsIrOutputGranularity {
|
||||||
|
WHOLE_PROGRAM,
|
||||||
|
PER_MODULE;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun byArgument(argument: String): KotlinJsIrOutputGranularity? =
|
||||||
|
values()
|
||||||
|
.firstOrNull { it.name.replace("_", "-").equals(argument, ignoreCase = true) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun KotlinJsIrOutputGranularity.toCompilerArgument(): String {
|
||||||
|
val perModule = this == KotlinJsIrOutputGranularity.PER_MODULE
|
||||||
|
return "$PER_MODULE=$perModule"
|
||||||
|
}
|
||||||
+1
@@ -43,6 +43,7 @@ enum class StringMetrics(val type: StringOverridePolicy, val anonymization: Stri
|
|||||||
KOTLIN_API_VERSION(OVERRIDE, COMPONENT_VERSION),
|
KOTLIN_API_VERSION(OVERRIDE, COMPONENT_VERSION),
|
||||||
JS_GENERATE_EXECUTABLE_DEFAULT(CONCAT, SAFE),
|
JS_GENERATE_EXECUTABLE_DEFAULT(CONCAT, SAFE),
|
||||||
JS_TARGET_MODE(CONCAT, SAFE),
|
JS_TARGET_MODE(CONCAT, SAFE),
|
||||||
|
JS_OUTPUT_GRANULARITY(OVERRIDE, SAFE),
|
||||||
|
|
||||||
// Compiler parameters
|
// Compiler parameters
|
||||||
JVM_DEFAULTS(CONCAT, SAFE),
|
JVM_DEFAULTS(CONCAT, SAFE),
|
||||||
|
|||||||
Reference in New Issue
Block a user