[Gradle, JS] Use include instead of sources for link stage of compiler
This commit is contained in:
+2
@@ -9,6 +9,8 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
* @see [compiler/testData/cli/js/jsExtraHelp.out]
|
||||
*/
|
||||
|
||||
const val ENTRY_IR_MODULE = "-Xinclude"
|
||||
|
||||
const val DISABLE_PRE_IR = "-Xir-only"
|
||||
const val ENABLE_DCE = "-Xir-dce"
|
||||
|
||||
|
||||
+21
-8
@@ -7,13 +7,12 @@ package org.jetbrains.kotlin.gradle.targets.js.ir
|
||||
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.file.RegularFileProperty
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.OutputFile
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinJsOptions
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrType.DEVELOPMENT
|
||||
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrType.PRODUCTION
|
||||
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.SourceRoots
|
||||
import org.jetbrains.kotlin.gradle.utils.newFileProperty
|
||||
import java.io.File
|
||||
|
||||
@@ -21,10 +20,22 @@ open class KotlinJsIrLink : Kotlin2JsCompile() {
|
||||
@Input
|
||||
lateinit var type: KotlinJsIrType
|
||||
|
||||
override fun getSourceRoots() = SourceRoots.KotlinOnly.create(
|
||||
emptyList<File>() as FileTree,
|
||||
emptyList()
|
||||
)
|
||||
@Internal
|
||||
override fun getSource(): FileTree = super.getSource()
|
||||
|
||||
@get:SkipWhenEmpty
|
||||
@get:InputDirectory
|
||||
val entryModule: File
|
||||
get() = File(
|
||||
(taskData.compilation as KotlinJsIrCompilation)
|
||||
.output
|
||||
.classesDirs
|
||||
.asPath
|
||||
)
|
||||
|
||||
override fun skipCondition(inputs: IncrementalTaskInputs): Boolean {
|
||||
return !inputs.isIncremental && !entryModule.exists()
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
val outputFileProperty: RegularFileProperty = project.newFileProperty {
|
||||
@@ -43,7 +54,9 @@ open class KotlinJsIrLink : Kotlin2JsCompile() {
|
||||
}
|
||||
|
||||
private fun KotlinJsOptions.configureOptions(vararg additionalCompilerArgs: String) {
|
||||
freeCompilerArgs += additionalCompilerArgs.toList() + PRODUCE_JS
|
||||
freeCompilerArgs += additionalCompilerArgs.toList() +
|
||||
PRODUCE_JS +
|
||||
"$ENTRY_IR_MODULE=${entryModule.canonicalPath}"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.daemon.common.MultiModuleICSettings
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.incremental.ChangedFiles
|
||||
import org.jetbrains.kotlin.gradle.internal.*
|
||||
import org.jetbrains.kotlin.gradle.internal.prepareCompilerArguments
|
||||
import org.jetbrains.kotlin.gradle.internal.tasks.TaskWithLocalState
|
||||
import org.jetbrains.kotlin.gradle.internal.tasks.allOutputFiles
|
||||
import org.jetbrains.kotlin.gradle.logging.*
|
||||
@@ -286,6 +285,10 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
||||
}
|
||||
}
|
||||
|
||||
protected open fun skipCondition(inputs: IncrementalTaskInputs): Boolean {
|
||||
return !inputs.isIncremental && getSourceRoots().kotlinSourceFiles.isEmpty()
|
||||
}
|
||||
|
||||
private fun executeImpl(inputs: IncrementalTaskInputs) {
|
||||
// Check that the JDK tools are available in Gradle (fail-fast, instead of a fail during the compiler run):
|
||||
findToolsJar()
|
||||
@@ -295,7 +298,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
||||
|
||||
logger.kotlinDebug { "All kotlin sources: ${allKotlinSources.pathsAsStringRelativeTo(project.rootProject.projectDir)}" }
|
||||
|
||||
if (!inputs.isIncremental && allKotlinSources.isEmpty()) {
|
||||
if (skipCondition(inputs)) {
|
||||
// Skip running only if non-incremental run. Otherwise, we may need to do some cleanup.
|
||||
logger.kotlinDebug { "No Kotlin files found, skipping Kotlin compiler task" }
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user