Fix bugs causing early task evaluation (#1812)

* Fix bugs causing early task evaluation

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Fix merge mistakes

Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>

* Fix another call forcing tasks evaluation  Add a test for lazy tasks
This commit is contained in:
Alex Saveau
2018-10-08 04:07:22 -07:00
committed by Sergey Igushkin
parent b7d0d20739
commit 524ae9df7d
6 changed files with 48 additions and 24 deletions
+4 -3
View File
@@ -235,8 +235,9 @@ private fun parseSourceRoots(project: Project): List<PSourceRoot> {
return emptyList()
}
val kotlinTasksBySourceSet = project.tasks
.filter { it.name.startsWith("compile") && it.name.endsWith("Kotlin") }
val kotlinTasksBySourceSet = project.tasks.names
.filter { it.startsWith("compile") && it.endsWith("Kotlin") }
.map { project.tasks.getByName(it) }
.associateBy { it.invokeInternal("getSourceSetName") }
val sourceRoots = mutableListOf<PSourceRoot>()
@@ -534,4 +535,4 @@ private val Project.sourceSets: SourceSetContainer
lateinit var result: SourceSetContainer
project.configure<JavaPluginConvention> { result = sourceSets }
return result
}
}
@@ -861,4 +861,31 @@ class KotlinGradleIT : BaseGradleIT() {
expectedKotlinDirs.forEach { assertTrue(it in reportedSrcDirs, "$it should be included into the Java source sets") }
}
}
@Test
fun testNoTaskConfigurationForcing() {
val gradleVersionRequirement = GradleVersionRequired.AtLeast("4.9")
val projects = listOf(
Project("simpleProject", gradleVersionRequirement),
Project("kotlin2JsNoOutputFileProject", gradleVersionRequirement),
Project("sample-app", gradleVersionRequirement, "new-mpp-lib-and-app")
)
projects.forEach {
it.apply {
setupWorkingDir()
val taskConfigureFlag = "Configured the task!"
gradleBuildScript().appendText("\n" + """
tasks.register("myTask") { println '$taskConfigureFlag' }
""".trimIndent())
build("help") {
assertSuccessful()
assertNotContains(taskConfigureFlag)
}
}
}
}
}
@@ -367,25 +367,21 @@ internal class GradleCompilerRunner(private val project: Project) : KotlinCompil
val jarToModule = HashMap<File, IncrementalModuleEntry>()
for (project in gradle.rootProject.allprojects) {
for (task in project.tasks) {
when (task) {
is AbstractKotlinCompile<*> -> {
val module = IncrementalModuleEntry(project.path, task.moduleName, project.buildDir, task.buildHistoryFile)
dirToModule[task.destinationDir] = module
task.javaOutputDir?.let { dirToModule[it] = module }
nameToModules.getOrPut(module.name) { HashSet() }.add(module)
project.tasks.withType(AbstractKotlinCompile::class.java).forEach { task ->
val module = IncrementalModuleEntry(project.path, task.moduleName, project.buildDir, task.buildHistoryFile)
dirToModule[task.destinationDir] = module
task.javaOutputDir?.let { dirToModule[it] = module }
nameToModules.getOrPut(module.name) { HashSet() }.add(module)
if (task is Kotlin2JsCompile) {
jarForSourceSet(project, task.sourceSetName)?.let {
jarToModule[it] = module
}
}
}
is InspectClassesForMultiModuleIC -> {
jarToClassListFile[File(task.archivePath)] = task.classesListFile
if (task is Kotlin2JsCompile) {
jarForSourceSet(project, task.sourceSetName)?.let {
jarToModule[it] = module
}
}
}
project.tasks.withType(InspectClassesForMultiModuleIC::class.java).forEach { task ->
jarToClassListFile[File(task.archivePath)] = task.classesListFile
}
}
return IncrementalModuleInfo(
@@ -161,7 +161,7 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
protected open fun addCommonSourceSetToPlatformSourceSet(commonSourceSet: Named, platformProject: Project) {
platformProject.whenEvaluated { // At the point when the source set in the platform module is created, the task does not exist
val platformTask = platformProject.tasks
.filterIsInstance<AbstractKotlinCompile<*>>()
.withType(AbstractKotlinCompile::class.java)
.singleOrNull { it.sourceSetName == commonSourceSet.name } // TODO use strict check once this code is not run in K/N
val commonSources = getKotlinSourceDirectorySetSafe(commonSourceSet)!!
@@ -243,4 +243,4 @@ open class KotlinPlatformJsPlugin : KotlinPlatformImplementationPluginBase("js")
project.applyPlugin<Kotlin2JsPluginWrapper>()
super.apply(project)
}
}
}
@@ -44,8 +44,8 @@ class ScriptingGradleSubplugin : Plugin<Project> {
val javaPluginConvention = project.convention.findPlugin(JavaPluginConvention::class.java)
if (javaPluginConvention?.sourceSets?.isEmpty() == false) {
project.tasks.all { task ->
if (task is KotlinCompile && task !is KaptGenerateStubsTask) {
project.tasks.withType(KotlinCompile::class.java) { task ->
if (task !is KaptGenerateStubsTask) {
val configuration = project.configurations.findByName(getConfigurationName(task.sourceSetName))
if (configuration?.isEmpty == false) {
javaPluginConvention.sourceSets.findByName(task.sourceSetName)?.let { sourceSet ->
@@ -423,12 +423,12 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
private fun disableMultiModuleICIfNeeded() {
if (!incremental || javaOutputDir == null) return
val illegalTask = project.tasks.firstOrNull {
val illegalTask = project.tasks.matching {
it is AbstractCompile &&
it !is JavaCompile &&
it !is AbstractKotlinCompile<*> &&
javaOutputDir!!.isParentOf(it.destinationDir)
} as? AbstractCompile
}.firstOrNull() as? AbstractCompile
if (illegalTask != null) {
project.logger.info(