[Gradle, JS] Move binaries on compilation level
This commit is contained in:
+9
-9
@@ -38,8 +38,8 @@ import org.jetbrains.kotlin.gradle.model.builder.KotlinModelBuilder
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.*
|
||||
import org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
|
||||
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
@@ -350,15 +350,15 @@ internal class KotlinJsIrSourceSetProcessor(
|
||||
it.dependsOn(kotlinTask)
|
||||
}
|
||||
|
||||
(kotlinCompilation.target as KotlinJsIrTarget).binaries
|
||||
.matching { it.compilation == kotlinCompilation }
|
||||
.all { binary ->
|
||||
registerKotlinCompileTask(
|
||||
binary.linkTaskName
|
||||
) { project, name, action ->
|
||||
registerJsLink(project, name, binary.type, action)
|
||||
}
|
||||
val compilation = kotlinCompilation as KotlinJsIrCompilation
|
||||
|
||||
compilation.binaries.all { binary ->
|
||||
registerKotlinCompileTask(
|
||||
binary.linkTaskName
|
||||
) { project, name, action ->
|
||||
registerJsLink(project, name, binary.type, action)
|
||||
}
|
||||
}
|
||||
|
||||
// outputFile can be set later during the configuration phase, get it only after the phase:
|
||||
project.runOnceAfterEvaluated("KotlinJsIrSourceSetProcessor.doTargetSpecificProcessing", kotlinTask) {
|
||||
|
||||
+10
-14
@@ -8,14 +8,13 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
||||
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
|
||||
|
||||
sealed class JsBinary(
|
||||
internal val target: KotlinTarget,
|
||||
internal val name: String,
|
||||
internal val type: BuildVariantKind,
|
||||
internal val compilation: KotlinJsCompilation
|
||||
internal val type: BuildVariantKind
|
||||
) {
|
||||
val linkTaskName: String = linkTaskName()
|
||||
|
||||
@@ -33,29 +32,26 @@ sealed class JsBinary(
|
||||
target.targetName
|
||||
)
|
||||
|
||||
val target: KotlinTarget
|
||||
get() = compilation.target
|
||||
|
||||
val project: Project
|
||||
get() = target.project
|
||||
}
|
||||
|
||||
class Executable(
|
||||
target: KotlinTarget,
|
||||
name: String,
|
||||
type: BuildVariantKind,
|
||||
compilation: KotlinJsCompilation
|
||||
type: BuildVariantKind
|
||||
) : JsBinary(
|
||||
target,
|
||||
name,
|
||||
type,
|
||||
compilation
|
||||
type
|
||||
)
|
||||
|
||||
class TestExecutable(
|
||||
target: KotlinTarget,
|
||||
name: String,
|
||||
type: BuildVariantKind,
|
||||
compilation: KotlinJsCompilation
|
||||
type: BuildVariantKind
|
||||
) : JsBinary(
|
||||
target,
|
||||
name,
|
||||
type,
|
||||
compilation
|
||||
type
|
||||
)
|
||||
+7
-12
@@ -62,13 +62,12 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
override fun configureRun(
|
||||
compilation: KotlinJsIrCompilation
|
||||
) {
|
||||
|
||||
val project = compilation.target.project
|
||||
val nodeJs = NodeJsRootPlugin.apply(project.rootProject)
|
||||
|
||||
val commonRunTask = project.registerTask<Task>(disambiguateCamelCased(RUN_TASK_NAME)) {}
|
||||
|
||||
binaries.getBinaries(compilation).all { binary ->
|
||||
compilation.binaries.all { binary ->
|
||||
val type = binary.type
|
||||
|
||||
val runTask = project.registerTask<KotlinWebpack>(
|
||||
@@ -136,15 +135,7 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
||||
assembleTask.dependsOn(distributeResourcesTask)
|
||||
|
||||
val webpackCommonTask = project.registerTask<Task>(disambiguateCamelCased(WEBPACK_TASK_NAME)) {
|
||||
}
|
||||
|
||||
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
||||
it.dependsOn(webpackCommonTask)
|
||||
it.dependsOn(distributeResourcesTask)
|
||||
}
|
||||
|
||||
binaries.getBinaries(compilation).all { binary ->
|
||||
compilation.binaries.all { binary ->
|
||||
val type = binary.type
|
||||
val webpackTask = project.registerTask<KotlinWebpack>(
|
||||
disambiguateCamelCased(
|
||||
@@ -172,9 +163,13 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
|
||||
if (type == BuildVariantKind.PRODUCTION) {
|
||||
assembleTask.dependsOn(webpackTask)
|
||||
webpackCommonTask.configure {
|
||||
val webpackCommonTask = project.registerTask<Task>(disambiguateCamelCased(WEBPACK_TASK_NAME)) {
|
||||
it.dependsOn(webpackTask)
|
||||
}
|
||||
project.registerTask<Task>(disambiguateCamelCased(DISTRIBUTION_TASK_NAME)) {
|
||||
it.dependsOn(webpackCommonTask)
|
||||
it.dependsOn(distributeResourcesTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-28
@@ -9,8 +9,8 @@ import org.gradle.api.DomainObjectSet
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.ExtensionAware
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinBinaryContainer
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind.DEVELOPMENT
|
||||
import org.jetbrains.kotlin.gradle.targets.js.dsl.BuildVariantKind.PRODUCTION
|
||||
@@ -21,7 +21,7 @@ import javax.inject.Inject
|
||||
open class KotlinJsBinaryContainer
|
||||
@Inject
|
||||
constructor(
|
||||
val target: KotlinBinaryContainer<KotlinJsCompilation, KotlinJsBinaryContainer>,
|
||||
val target: KotlinBinaryContainer<KotlinJsIrCompilation, KotlinJsBinaryContainer>,
|
||||
backingContainer: DomainObjectSet<JsBinary>
|
||||
) : DomainObjectSet<JsBinary> by backingContainer {
|
||||
val project: Project
|
||||
@@ -29,46 +29,28 @@ constructor(
|
||||
|
||||
private val binaryNames = mutableSetOf<String>()
|
||||
|
||||
private val defaultCompilation: KotlinJsCompilation
|
||||
private val defaultCompilation: KotlinJsIrCompilation
|
||||
get() = target.compilations.getByName(KotlinCompilation.MAIN_COMPILATION_NAME)
|
||||
|
||||
private val defaultTestCompilation: KotlinJsCompilation
|
||||
get() = target.compilations.getByName(KotlinCompilation.TEST_COMPILATION_NAME)
|
||||
|
||||
fun executable(
|
||||
compilation: KotlinJsCompilation = defaultCompilation
|
||||
) = createBinaries(
|
||||
compilation = compilation,
|
||||
compilation: KotlinJsIrCompilation = defaultCompilation
|
||||
) = compilation.binaries.executable()
|
||||
|
||||
internal fun executable() = createBinaries(
|
||||
jsBinaryType = JsBinaryType.EXECUTABLE,
|
||||
create = ::Executable
|
||||
)
|
||||
|
||||
internal fun testExecutable() = createBinaries(
|
||||
compilation = defaultTestCompilation,
|
||||
jsBinaryType = JsBinaryType.TEST,
|
||||
create = ::TestExecutable
|
||||
)
|
||||
|
||||
internal fun getBinaries(
|
||||
compilation: KotlinJsCompilation
|
||||
): DomainObjectSet<JsBinary> =
|
||||
matching { it.compilation == compilation }
|
||||
|
||||
internal fun getBinary(
|
||||
compilation: KotlinJsCompilation,
|
||||
buildVariantKind: BuildVariantKind
|
||||
): JsBinary =
|
||||
getBinaries(
|
||||
compilation
|
||||
).matching { it.type == buildVariantKind }
|
||||
matching { it.type == buildVariantKind }
|
||||
.single()
|
||||
|
||||
|
||||
private fun <T : JsBinary> createBinaries(
|
||||
compilation: KotlinJsCompilation,
|
||||
buildVariantKinds: Collection<BuildVariantKind> = listOf(PRODUCTION, DEVELOPMENT),
|
||||
jsBinaryType: JsBinaryType,
|
||||
create: (name: String, buildVariantKind: BuildVariantKind, compilation: KotlinJsCompilation) -> T
|
||||
create: (target: KotlinTarget, name: String, buildVariantKind: BuildVariantKind) -> T
|
||||
) {
|
||||
buildVariantKinds.forEach { buildVariantKind ->
|
||||
val name = generateBinaryName(
|
||||
@@ -80,7 +62,7 @@ constructor(
|
||||
"Cannot create binary $name: binary with such a name already exists"
|
||||
}
|
||||
|
||||
val binary = create(name, buildVariantKind, compilation)
|
||||
val binary = create(target, name, buildVariantKind)
|
||||
add(binary)
|
||||
// Allow accessing binaries as properties of the container in Groovy DSL.
|
||||
if (this is ExtensionAware) {
|
||||
|
||||
+8
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.api.file.SourceDirectorySet
|
||||
import org.gradle.util.WrapUtil
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJsCompilation
|
||||
@@ -16,6 +17,13 @@ class KotlinJsIrCompilation(
|
||||
name: String
|
||||
) : KotlinJsCompilation(target, name) {
|
||||
|
||||
internal val binaries: KotlinJsBinaryContainer =
|
||||
target.project.objects.newInstance(
|
||||
KotlinJsBinaryContainer::class.java,
|
||||
this,
|
||||
WrapUtil.toDomainObjectSet(JsBinary::class.java)
|
||||
)
|
||||
|
||||
internal val allSources: MutableSet<SourceDirectorySet> = mutableSetOf()
|
||||
|
||||
override fun addSourcesToCompileTask(sourceSet: KotlinSourceSet, addAsCommonSources: Lazy<Boolean>) {
|
||||
|
||||
+8
-11
@@ -36,21 +36,18 @@ abstract class KotlinJsIrSubTarget(
|
||||
final override lateinit var testRuns: NamedDomainObjectContainer<KotlinJsPlatformTestRun>
|
||||
private set
|
||||
|
||||
protected val binaries: KotlinJsBinaryContainer
|
||||
get() = target.binaries
|
||||
|
||||
internal fun configure() {
|
||||
target.binaries.testExecutable()
|
||||
|
||||
NpmResolverPlugin.apply(project)
|
||||
|
||||
configureBuildVariants()
|
||||
configureTests()
|
||||
|
||||
binaries.all { binary ->
|
||||
val npmProject = binary.compilation.npmProject
|
||||
binary.linkTask.configure {
|
||||
it.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
||||
target.compilations.all {
|
||||
val npmProject = it.npmProject
|
||||
it.binaries.all { binary ->
|
||||
binary.linkTask.configure {
|
||||
it.kotlinOptions.outputFile = npmProject.dir.resolve(npmProject.main).canonicalPath
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,6 +76,7 @@ abstract class KotlinJsIrSubTarget(
|
||||
|
||||
protected open fun configureTestRunDefaults(testRun: KotlinJsPlatformTestRun) {
|
||||
target.compilations.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }.all { compilation ->
|
||||
compilation.binaries.executable()
|
||||
configureTestsRun(testRun, compilation)
|
||||
}
|
||||
}
|
||||
@@ -95,8 +93,7 @@ abstract class KotlinJsIrSubTarget(
|
||||
testJs.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
testJs.description = testTaskDescription
|
||||
|
||||
val testExecutableTask = binaries.getBinary(
|
||||
compilation,
|
||||
val testExecutableTask = compilation.binaries.getBinary(
|
||||
BuildVariantKind.DEVELOPMENT
|
||||
).linkTask
|
||||
|
||||
|
||||
+6
-18
@@ -8,9 +8,9 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
import org.gradle.api.NamedDomainObjectContainer
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.util.WrapUtil
|
||||
import org.jetbrains.kotlin.gradle.plugin.AbstractKotlinTargetConfigurator.Companion.runTaskNameSuffix
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation.Companion.MAIN_COMPILATION_NAME
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinBinaryContainer
|
||||
@@ -48,23 +48,11 @@ constructor(
|
||||
|
||||
var producingType: KotlinJsProducingType? = null
|
||||
|
||||
override val binaries: KotlinJsBinaryContainer =
|
||||
// Use newInstance to allow accessing binaries by their names in Groovy using the extension mechanism.
|
||||
project.objects.newInstance(
|
||||
KotlinJsBinaryContainer::class.java,
|
||||
this,
|
||||
WrapUtil.toDomainObjectSet(JsBinary::class.java).apply {
|
||||
matching { it is Executable }.all {
|
||||
whenBrowserConfigured {
|
||||
(this as KotlinJsIrSubTarget).produceExecutable()
|
||||
}
|
||||
|
||||
whenNodejsConfigured {
|
||||
(this as KotlinJsIrSubTarget).produceExecutable()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
override val binaries: KotlinJsBinaryContainer
|
||||
get() = compilations.withType(KotlinJsIrCompilation::class.java)
|
||||
.named(MAIN_COMPILATION_NAME)
|
||||
.map { it.binaries }
|
||||
.get()
|
||||
|
||||
private val runTaskName get() = lowerCamelCaseName(disambiguationClassifier, runTaskNameSuffix)
|
||||
val runTask: Task
|
||||
|
||||
+2
-2
@@ -31,7 +31,7 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
override fun configureRun(
|
||||
compilation: KotlinJsIrCompilation
|
||||
) {
|
||||
val developmentExecutable = binaries.getBinary(compilation, BuildVariantKind.DEVELOPMENT)
|
||||
val developmentExecutable = compilation.binaries.getBinary(BuildVariantKind.DEVELOPMENT)
|
||||
|
||||
val runTaskHolder = NodeJsExec.create(compilation, disambiguateCamelCased(RUN_TASK_NAME)) {
|
||||
inputFileProperty.set(developmentExecutable.linkTask.map { it.outputFileProperty.get() })
|
||||
@@ -42,7 +42,7 @@ open class KotlinNodeJsIr @Inject constructor(target: KotlinJsIrTarget) :
|
||||
override fun configureBuild(
|
||||
compilation: KotlinJsIrCompilation
|
||||
) {
|
||||
val productionExecutable = binaries.getBinary(compilation, BuildVariantKind.PRODUCTION)
|
||||
val productionExecutable = compilation.binaries.getBinary(BuildVariantKind.PRODUCTION)
|
||||
|
||||
val assembleTask = project.tasks.getByName(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
|
||||
assembleTask.dependsOn(productionExecutable.linkTask)
|
||||
|
||||
Reference in New Issue
Block a user