Skip to content

Commit

Permalink
Revert JVM tasks configuration changes introduced in Kotlin#200 (Kotl…
Browse files Browse the repository at this point in the history
…in#212)

* Rollback task skipping logic based on srcset emptyness check for JVM tasks
  • Loading branch information
fzhinkin authored Apr 3, 2024
1 parent f3b53bb commit 4de530a
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/functionalTest/kotlin/kotlinx/validation/api/Assert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ internal fun BuildResult.assertTaskSkipped(task: String) {
assertTaskOutcome(TaskOutcome.SKIPPED, task)
}

/**
* Helper `fun` for asserting a [TaskOutcome] to be equal to [TaskOutcome.UP_TO_DATE]
*/
internal fun BuildResult.assertTaskUpToDate(task: String) {
assertTaskOutcome(TaskOutcome.UP_TO_DATE, task)
}

private fun BuildResult.assertTaskOutcome(taskOutcome: TaskOutcome, taskName: String) {
assertEquals(taskOutcome, task(taskName)?.outcome)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2016-2024 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

package kotlinx.validation.test

import kotlinx.validation.api.*
import kotlinx.validation.api.resolve
import kotlinx.validation.api.test
import org.assertj.core.api.Assertions
import org.junit.Test

class JvmProjectTests : BaseKotlinGradleTest() {
@Test
fun `apiDump for a project with generated sources only`() {
val runner = test {
buildGradleKts {
resolve("/examples/gradle/base/withPlugin.gradle.kts")
resolve("/examples/gradle/configuration/generatedSources/generatedJvmSources.gradle.kts")
}
// TODO: enable configuration cache back when we start skipping tasks correctly
runner(withConfigurationCache = false) {
arguments.add(":apiDump")
}
}
runner.build().apply {
assertTaskSuccess(":apiDump")

val expectedApi = readFileList("/examples/classes/GeneratedSources.dump")
Assertions.assertThat(rootProjectApiDump.readText()).isEqualToIgnoringNewLines(expectedApi)
}
}

@Test
fun `apiCheck for a project with generated sources only`() {
val runner = test {
buildGradleKts {
resolve("/examples/gradle/base/withPlugin.gradle.kts")
resolve("/examples/gradle/configuration/generatedSources/generatedJvmSources.gradle.kts")
}
apiFile(projectName = rootProjectDir.name) {
resolve("/examples/classes/GeneratedSources.dump")
}
// TODO: enable configuration cache back when we start skipping tasks correctly
runner(withConfigurationCache = false) {
arguments.add(":apiCheck")
}
}
runner.build().apply {
assertTaskSuccess(":apiCheck")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/*
* Copyright 2016-2021 JetBrains s.r.o.
* Copyright 2016-2024 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

package kotlinx.validation.test

import kotlinx.validation.api.*
import org.assertj.core.api.Assertions.assertThat
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Test
import java.io.File

internal class MultiPlatformSingleJvmKlibTargetTest : BaseKotlinGradleTest() {
internal class MultiPlatformSingleJvmTargetTest : BaseKotlinGradleTest() {
private fun BaseKotlinScope.createProjectHierarchyWithPluginOnRoot() {
settingsGradleKts {
resolve("/examples/gradle/settings/settings-name-testproject.gradle.kts")
Expand Down Expand Up @@ -116,6 +117,45 @@ internal class MultiPlatformSingleJvmKlibTargetTest : BaseKotlinGradleTest() {
}
}

@Test
fun testApiDumpPassesForEmptyProject() {
val runner = test {
buildGradleKts {
resolve("/examples/gradle/base/multiplatformWithSingleJvmTarget.gradle.kts")
}

runner {
arguments.add(":apiDump")
}
}

runner.build().apply {
assertTaskSkipped(":jvmApiDump")
assertTaskUpToDate(":apiDump")
}
}

@Test
fun testApiCheckPassesForEmptyProject() {
val runner = test {
buildGradleKts {
resolve("/examples/gradle/base/multiplatformWithSingleJvmTarget.gradle.kts")
}

emptyApiFile(projectName = rootProjectDir.name)

runner {
arguments.add(":apiCheck")
}
}

runner.build().apply {
assertTaskSkipped(":jvmApiCheck")
assertTaskUpToDate(":apiCheck")

}
}

private val jvmApiDump: File get() = rootProjectDir.resolve("$API_DIR/testproject.api")

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public final class Generated {
public fun <init> ()V
public final fun helloCreator ()I
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
abstract class GenerateSourcesTask : org.gradle.api.DefaultTask() {
@get:org.gradle.api.tasks.OutputDirectory
abstract val outputDirectory: org.gradle.api.file.DirectoryProperty

@org.gradle.api.tasks.TaskAction
fun generate() {
outputDirectory.asFile.get().mkdirs()
outputDirectory.file("Generated.kt").get().asFile.writeText("""
public class Generated { public fun helloCreator(): Int = 42 }
""".trimIndent())
}
}

val srcgen = project.tasks.register("generateSources", GenerateSourcesTask::class.java)
srcgen.configure {
outputDirectory.set(project.layout.buildDirectory.get().dir("generated").dir("kotlin"))
}

project.sourceSets.getByName("main") {
kotlin.srcDir(srcgen)
}
4 changes: 1 addition & 3 deletions src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ private fun Project.configureKotlinCompilation(

val apiBuild = task<KotlinApiBuildTask>(targetConfig.apiTaskName("Build")) {
// Do not enable task for empty umbrella modules
isEnabled = apiCheckEnabled(projectName, extension)
val hasSourcesPredicate = compilation.hasAnySourcesPredicate()
onlyIf { hasSourcesPredicate.get() }
isEnabled = apiCheckEnabled(projectName, extension) && compilation.hasAnySources()
// 'group' is not specified deliberately, so it will be hidden from ./gradlew tasks
description =
"Builds Kotlin API for 'main' compilations of $projectName. Complementary task and shouldn't be called manually"
Expand Down

0 comments on commit 4de530a

Please sign in to comment.