[Gradle][Minor] Move JsCompilationDetails into separate source file
KT-54312
This commit is contained in:
committed by
Space Team
parent
d08bd626a6
commit
72e20967dd
+1
-66
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
@@ -55,72 +56,6 @@ internal val CompilationDetails<*>.associateCompilationsClosure: Iterable<Compil
|
||||
get() = closure { it.associateCompilations }
|
||||
|
||||
|
||||
internal open class JsCompilationDetails(
|
||||
target: KotlinTarget,
|
||||
compilationPurpose: String,
|
||||
defaultSourceSet: KotlinSourceSet,
|
||||
) : DefaultCompilationDetailsWithRuntime<KotlinJsOptions, KotlinJsCompilerOptions>(
|
||||
target,
|
||||
compilationPurpose,
|
||||
defaultSourceSet,
|
||||
{
|
||||
object : HasCompilerOptions<KotlinJsCompilerOptions> {
|
||||
override val options: KotlinJsCompilerOptions =
|
||||
target.project.objects.newInstance(KotlinJsCompilerOptionsDefault::class.java)
|
||||
}
|
||||
},
|
||||
{
|
||||
object : KotlinJsOptions {
|
||||
override val options: KotlinJsCompilerOptions
|
||||
get() = compilerOptions.options
|
||||
}
|
||||
}
|
||||
) {
|
||||
|
||||
internal abstract class JsCompilationDependenciesHolder @Inject constructor(
|
||||
val target: KotlinTarget,
|
||||
val compilationPurpose: String
|
||||
) : HasKotlinDependencies {
|
||||
override val apiConfigurationName: String
|
||||
get() = disambiguateNameInPlatform(API)
|
||||
|
||||
override val implementationConfigurationName: String
|
||||
get() = disambiguateNameInPlatform(IMPLEMENTATION)
|
||||
|
||||
override val compileOnlyConfigurationName: String
|
||||
get() = disambiguateNameInPlatform(COMPILE_ONLY)
|
||||
|
||||
override val runtimeOnlyConfigurationName: String
|
||||
get() = disambiguateNameInPlatform(RUNTIME_ONLY)
|
||||
|
||||
protected open val disambiguationClassifierInPlatform: String?
|
||||
get() = when (target) {
|
||||
is KotlinJsTarget -> target.disambiguationClassifierInPlatform
|
||||
is KotlinJsIrTarget -> target.disambiguationClassifierInPlatform
|
||||
else -> error("Unexpected target type of $target")
|
||||
}
|
||||
|
||||
private fun disambiguateNameInPlatform(simpleName: String): String {
|
||||
return lowerCamelCaseName(
|
||||
disambiguationClassifierInPlatform,
|
||||
compilationPurpose.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
||||
"compilation",
|
||||
simpleName
|
||||
)
|
||||
}
|
||||
|
||||
override fun dependencies(configure: KotlinDependencyHandler.() -> Unit): Unit =
|
||||
DefaultKotlinDependencyHandler(this, target.project).run(configure)
|
||||
|
||||
override fun dependencies(configure: Action<KotlinDependencyHandler>) =
|
||||
dependencies { configure.execute(this) }
|
||||
}
|
||||
|
||||
override val kotlinDependenciesHolder: HasKotlinDependencies
|
||||
get() = target.project.objects.newInstance(JsCompilationDependenciesHolder::class.java, target, compilationPurpose)
|
||||
|
||||
}
|
||||
|
||||
internal class JsIrCompilationDetails(
|
||||
target: KotlinTarget, compilationPurpose: String, defaultSourceSet: KotlinSourceSet
|
||||
) : JsCompilationDetails(target, compilationPurpose, defaultSourceSet) {
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.plugin.mpp
|
||||
|
||||
import org.gradle.api.Action
|
||||
import org.jetbrains.kotlin.gradle.dsl.CompilerJsOptions
|
||||
import org.jetbrains.kotlin.gradle.dsl.CompilerJsOptionsDefault
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.*
|
||||
import org.jetbrains.kotlin.gradle.targets.js.KotlinJsTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.utils.*
|
||||
import javax.inject.Inject
|
||||
|
||||
internal open class JsCompilationDetails(
|
||||
target: KotlinTarget,
|
||||
compilationPurpose: String,
|
||||
defaultSourceSet: KotlinSourceSet,
|
||||
) : DefaultCompilationDetailsWithRuntime<KotlinJsOptions, CompilerJsOptions>(
|
||||
target,
|
||||
compilationPurpose,
|
||||
defaultSourceSet,
|
||||
{
|
||||
object : HasCompilerOptions<CompilerJsOptions> {
|
||||
override val options: CompilerJsOptions =
|
||||
target.project.objects.newInstance(CompilerJsOptionsDefault::class.java)
|
||||
}
|
||||
},
|
||||
{
|
||||
object : KotlinJsOptions {
|
||||
override val options: CompilerJsOptions
|
||||
get() = compilerOptions.options
|
||||
}
|
||||
}
|
||||
) {
|
||||
|
||||
internal abstract class JsCompilationDependenciesHolder @Inject constructor(
|
||||
val target: KotlinTarget,
|
||||
val compilationPurpose: String
|
||||
) : HasKotlinDependencies {
|
||||
override val apiConfigurationName: String
|
||||
get() = disambiguateNameInPlatform(API)
|
||||
|
||||
override val implementationConfigurationName: String
|
||||
get() = disambiguateNameInPlatform(IMPLEMENTATION)
|
||||
|
||||
override val compileOnlyConfigurationName: String
|
||||
get() = disambiguateNameInPlatform(COMPILE_ONLY)
|
||||
|
||||
override val runtimeOnlyConfigurationName: String
|
||||
get() = disambiguateNameInPlatform(RUNTIME_ONLY)
|
||||
|
||||
protected open val disambiguationClassifierInPlatform: String?
|
||||
get() = when (target) {
|
||||
is KotlinJsTarget -> target.disambiguationClassifierInPlatform
|
||||
is KotlinJsIrTarget -> target.disambiguationClassifierInPlatform
|
||||
else -> error("Unexpected target type of $target")
|
||||
}
|
||||
|
||||
private fun disambiguateNameInPlatform(simpleName: String): String {
|
||||
return lowerCamelCaseName(
|
||||
disambiguationClassifierInPlatform,
|
||||
compilationPurpose.takeIf { it != KotlinCompilation.MAIN_COMPILATION_NAME },
|
||||
"compilation",
|
||||
simpleName
|
||||
)
|
||||
}
|
||||
|
||||
override fun dependencies(configure: KotlinDependencyHandler.() -> Unit): Unit =
|
||||
DefaultKotlinDependencyHandler(this, target.project).run(configure)
|
||||
|
||||
override fun dependencies(configure: Action<KotlinDependencyHandler>) =
|
||||
dependencies { configure.execute(this) }
|
||||
}
|
||||
|
||||
override val kotlinDependenciesHolder: HasKotlinDependencies
|
||||
get() = target.project.objects.newInstance(JsCompilationDependenciesHolder::class.java, target, compilationPurpose)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user