[Gradle] KotlinJsIrLink: Handle KotlinBuildStatsService invocation outside of creating compiler args

KTIJ-24976
This commit is contained in:
Sebastian Sellmair
2023-04-05 17:02:54 +02:00
committed by Space Team
parent fc05d001c6
commit ca84505376
2 changed files with 18 additions and 15 deletions
@@ -16,7 +16,6 @@ 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.gradle.dsl.KotlinJsCompilerOptionsDefault
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.ContributeCompilerArgumentsContext
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
@@ -98,20 +97,6 @@ abstract class KotlinJsIrLink @Inject constructor(
super.contributeAdditionalCompilerArguments(context)
context.primitive { args ->
// TODO Ilya Goncharov: This should not be part of creating compiler arguments;
KotlinBuildStatsService.applyIfInitialised {
it.report(BooleanMetrics.JS_IR_INCREMENTAL, this.incrementalJsIr)
val newArgs = K2JSCompilerArguments()
parseCommandLineArguments(ArgumentUtils.convertArgumentsToStringList(args), newArgs)
it.report(
StringMetrics.JS_OUTPUT_GRANULARITY,
if (newArgs.irPerModule)
KotlinJsIrOutputGranularity.PER_MODULE.name.toLowerCaseAsciiOnly()
else
KotlinJsIrOutputGranularity.WHOLE_PROGRAM.name.toLowerCaseAsciiOnly()
)
}
// moduleName can start with @ for group of NPM packages
// but args parsing @ as start of argfile
// so WA we provide moduleName as one parameter
@@ -128,6 +113,21 @@ abstract class KotlinJsIrLink @Inject constructor(
}
}
override fun processArgsBeforeCompile(args: K2JSCompilerArguments) {
KotlinBuildStatsService.applyIfInitialised {
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.toLowerCaseAsciiOnly()
else
KotlinJsIrOutputGranularity.WHOLE_PROGRAM.name.toLowerCaseAsciiOnly()
)
}
}
private fun usingCacheDirectory() =
incrementalJsIr && modeProperty.get() == DEVELOPMENT
}
@@ -286,6 +286,8 @@ abstract class Kotlin2JsCompile @Inject constructor(
override val incrementalProps: List<FileCollection>
get() = super.incrementalProps + listOf(friendDependencies)
protected open fun processArgsBeforeCompile(args: K2JSCompilerArguments) = Unit
protected open fun contributeAdditionalCompilerArguments(context: ContributeCompilerArgumentsContext<K2JSCompilerArguments>) = Unit
override fun callCompilerAsync(
@@ -339,6 +341,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
reportingSettings = reportingSettings(),
incrementalCompilationEnvironment = icEnv
)
processArgsBeforeCompile(args)
compilerRunner.runJsCompilerAsync(
args,
environment,