Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore compatibility with Gradle's configuration cache #96

Merged
merged 2 commits into from Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -132,7 +132,7 @@ internal class AppendableScope(val filePath: String) {
}

internal class Runner {
val arguments: MutableList<String> = mutableListOf()
val arguments: MutableList<String> = mutableListOf("--configuration-cache")
}

internal fun readFileList(fileName: String): String {
Expand Down
15 changes: 6 additions & 9 deletions src/main/kotlin/BinaryCompatibilityValidatorPlugin.kt
Expand Up @@ -182,7 +182,7 @@ private fun Project.configureKotlinCompilation(
val apiBuild = task<KotlinApiBuildTask>(targetConfig.apiTaskName("Build"), extension) {
// Do not enable task for empty umbrella modules
isEnabled =
apiCheckEnabled(extension) && compilation.allKotlinSourceSets.any { it.kotlin.srcDirs.any { it.exists() } }
apiCheckEnabled(projectName, extension) && compilation.allKotlinSourceSets.any { it.kotlin.srcDirs.any { it.exists() } }
// '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 All @@ -206,8 +206,8 @@ private fun Project.configureKotlinCompilation(
val Project.sourceSets: SourceSetContainer
get() = convention.getPlugin(JavaPluginConvention::class.java).sourceSets

fun Project.apiCheckEnabled(extension: ApiValidationExtension): Boolean =
name !in extension.ignoredProjects && !extension.validationDisabled
fun apiCheckEnabled(projectName: String, extension: ApiValidationExtension): Boolean =
projectName !in extension.ignoredProjects && !extension.validationDisabled

private fun Project.configureApiTasks(
sourceSet: SourceSet,
Expand All @@ -217,7 +217,7 @@ private fun Project.configureApiTasks(
val projectName = project.name
val apiBuildDir = targetConfig.apiDir.map { buildDir.resolve(it) }
val apiBuild = task<KotlinApiBuildTask>(targetConfig.apiTaskName("Build"), extension) {
isEnabled = apiCheckEnabled(extension)
isEnabled = apiCheckEnabled(projectName, extension)
// '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 All @@ -244,7 +244,7 @@ private fun Project.configureCheckTasks(
}
}
val apiCheck = task<KotlinApiCompareTask>(targetConfig.apiTaskName("Check")) {
isEnabled = apiCheckEnabled(extension) && apiBuild.map { it.enabled }.getOrElse(true)
isEnabled = apiCheckEnabled(projectName, extension) && apiBuild.map { it.enabled }.getOrElse(true)
group = "verification"
description = "Checks signatures of public API against the golden value in API folder for $projectName"
run {
Expand All @@ -261,15 +261,12 @@ private fun Project.configureCheckTasks(
}

val apiDump = task<Sync>(targetConfig.apiTaskName("Dump")) {
isEnabled = apiCheckEnabled(extension) && apiBuild.map { it.enabled }.getOrElse(true)
isEnabled = apiCheckEnabled(projectName, extension) && apiBuild.map { it.enabled }.getOrElse(true)
group = "other"
description = "Syncs API from build dir to ${targetConfig.apiDir} dir for $projectName"
from(apiBuildDir)
into(apiCheckDir)
dependsOn(apiBuild)
doFirst {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate on why you removed this mkdirs call?

Does into documentation guarantees mkdir?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's odd, as this doesn't seem to violate the configuration cache contract, but it wouldn't work unless I removed it.

In any case, yes, into will create the required directories. More here: https://docs.gradle.org/current/userguide/working_with_files.html#sec:creating_directories_example

All core Gradle tasks ensure that any output directories they need are created if necessary

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me, thanks!
At least now we have a proper test coverage for that

apiCheckDir.get().mkdirs()
}
}

commonApiDump?.configure { it.dependsOn(apiDump) }
Expand Down