[Gradle, JS] Prod and dev compile tasks depends on klib compile task

This commit is contained in:
Ilya Goncharov
2019-12-26 18:55:55 +03:00
parent 3ee7e9272b
commit c043fc2272
3 changed files with 21 additions and 12 deletions
@@ -86,7 +86,7 @@ internal abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
protected val sourceSetName: String = kotlinCompilation.compilationName protected val sourceSetName: String = kotlinCompilation.compilationName
override val kotlinTask: TaskProvider<out T> = registerKotlinCompileTask() override val kotlinTask: TaskProvider<out T> = registerKotlinCompileTask(kotlinCompilation.compileKotlinTaskName)
protected val javaSourceSet: SourceSet? protected val javaSourceSet: SourceSet?
get() = get() =
@@ -97,7 +97,18 @@ internal abstract class KotlinSourceSetProcessor<T : AbstractKotlinCompile<*>>(
else null else null
} }
private fun registerKotlinCompileTask(): TaskProvider<out T> { private val defaultKotlinDestinationDir: File
get() {
val kotlinExt = project.kotlinExtension
val targetSubDirectory =
if (kotlinExt is KotlinSingleJavaTargetExtension)
"" // In single-target projects, don't add the target name part to this path
else
kotlinCompilation.target.disambiguationClassifier?.let { "$it/" }.orEmpty()
return File(project.buildDir, "classes/kotlin/$targetSubDirectory${kotlinCompilation.compilationName}")
}
protected fun registerKotlinCompileTask(): TaskProvider<out T> {
val name = kotlinCompilation.compileKotlinTaskName val name = kotlinCompilation.compileKotlinTaskName
logger.kotlinDebug("Creating kotlin compile task $name") logger.kotlinDebug("Creating kotlin compile task $name")
@@ -347,18 +358,18 @@ internal class KotlinJsIrSourceSetProcessor(
listOf( listOf(
compilation.productionCompileTaskName, compilation.productionCompileTaskName,
compilation.developmentCompileTaskName compilation.developmentCompileTaskName
).forEach { taskName -> ).map { taskName ->
doRegisterTask( registerKotlinCompileTask(
project,
taskName taskName
) { )
it.description = taskDescription }.forEach { task ->
it.mapClasspath { kotlinCompilation.compileDependencyFiles } task.configure {
it.dependsOn(kotlinTask)
} }
} }
// outputFile can be set later during the configuration phase, get it only after the phase: // outputFile can be set later during the configuration phase, get it only after the phase:
project.runOnceAfterEvaluated("Kotlin2JsSourceSetProcessor.doTargetSpecificProcessing", kotlinTask) { project.runOnceAfterEvaluated("KotlinJsIrSourceSetProcessor.doTargetSpecificProcessing", kotlinTask) {
val kotlinTaskInstance = kotlinTask.get() val kotlinTaskInstance = kotlinTask.get()
kotlinTaskInstance.kotlinOptions.outputFile = kotlinTaskInstance.outputFile.absolutePath kotlinTaskInstance.kotlinOptions.outputFile = kotlinTaskInstance.outputFile.absolutePath
val outputDir = kotlinTaskInstance.outputFile.parentFile val outputDir = kotlinTaskInstance.outputFile.parentFile
@@ -151,7 +151,6 @@ open class KotlinBrowserJsIr @Inject constructor(target: KotlinJsIrTarget) :
disambiguateCamelCased( disambiguateCamelCased(
buildVariant.name, buildVariant.name,
WEBPACK_TASK_NAME WEBPACK_TASK_NAME
) )
) { ) {
it.dependsOn( it.dependsOn(
@@ -58,7 +58,7 @@ abstract class KotlinJsIrSubTarget(
} }
override fun produceJs() { override fun produceJs() {
produceByFlags(PRODUCE_UNZIPPED_KLIB, PRODUCE_JS) produceByFlags(PRODUCE_UNZIPPED_KLIB)
configureMain() configureMain()
} }
@@ -66,7 +66,6 @@ abstract class KotlinJsIrSubTarget(
private fun produceByFlags(vararg flags: String) { private fun produceByFlags(vararg flags: String) {
configure() configure()
target.compilations target.compilations
.matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME } .matching { it.name == KotlinCompilation.TEST_COMPILATION_NAME }
.all { .all {