From 80ae5551dcca549d7196188679c555c287048605 Mon Sep 17 00:00:00 2001 From: Jay Date: Tue, 19 Mar 2024 15:16:40 -0400 Subject: [PATCH] Fix StoneTask cache misses (#530) * fix StoneTask cacheability --- .../com/dropbox/stone/java/StonePlugin.kt | 3 +- .../com/dropbox/stone/java/StoneTask.kt | 39 ++++++++++++------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StonePlugin.kt b/stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StonePlugin.kt index 193094056..f3559e317 100644 --- a/stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StonePlugin.kt +++ b/stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StonePlugin.kt @@ -3,7 +3,6 @@ package com.dropbox.stone.java import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.tasks.PathSensitivity import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.compile.JavaCompile import org.gradle.kotlin.dsl.withType @@ -58,7 +57,7 @@ class StonePlugin : Plugin { val mySpecDir: String = specDirPropNameValue ?: "src/${sourceSet.name}/stone" specDir.set(File(mySpecDir)) - generatorDir.set(File("${project.projectDir.absoluteFile}/generator/java")) + generatorFile.set(File("${project.projectDir}/generator/java/java.stoneg.py")) stoneDir.set(File("stone")) pythonCommand.set("python") outputDir.set(File("${project.buildDir}/generated/source/stone/${sourceSet.name}")) diff --git a/stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StoneTask.kt b/stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StoneTask.kt index 89c5a6c5f..f4c6b6402 100644 --- a/stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StoneTask.kt +++ b/stone-java-gradle-plugin/src/main/kotlin/com/dropbox/stone/java/StoneTask.kt @@ -11,6 +11,7 @@ import org.gradle.process.ExecOperations import java.io.File import java.io.FileOutputStream import javax.inject.Inject +import org.gradle.api.file.ConfigurableFileCollection @CacheableTask abstract class StoneTask : DefaultTask() { @@ -21,33 +22,49 @@ abstract class StoneTask : DefaultTask() { @get:Input abstract val stoneConfigs: ListProperty - @get:InputDirectory + @get:InputFile @get:PathSensitive(PathSensitivity.RELATIVE) - abstract val generatorDir: DirectoryProperty + abstract val generatorFile: RegularFileProperty - @get:InputDirectory - @get:PathSensitive(PathSensitivity.RELATIVE) + @get:Internal abstract val specDir: DirectoryProperty + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) + abstract val specFiles: ConfigurableFileCollection + @get:Optional @get:InputFile @get:PathSensitive(PathSensitivity.RELATIVE) abstract val routeWhitelistFilter: RegularFileProperty - @get:InputDirectory - @get:PathSensitive(PathSensitivity.RELATIVE) + @get:Internal abstract val stoneDir: DirectoryProperty + @get:InputFiles + @get:PathSensitive(PathSensitivity.RELATIVE) + abstract val stoneFiles: ConfigurableFileCollection + @get:Input abstract val pythonCommand: Property @get:OutputDirectory abstract val outputDir: DirectoryProperty + init { + stoneFiles.setFrom(stoneDir.asFileTree.matching { + include("**/*.py") + }) + + specFiles.setFrom(specDir.asFileTree.matching { + include("**/*.stone") + }) + } + @TaskAction fun processStone() { check(stoneDir.get().asFile.exists()) { - "Stone directory ${stoneDir} does not exist. " + + "Stone directory $stoneDir does not exist. " + "Please run `./update-submodules` to download the stone submodule." } @@ -55,10 +72,6 @@ abstract class StoneTask : DefaultTask() { outputDirectory.deleteRecursively() outputDirectory.mkdirs() - val generatorFile = generatorDir.asFileTree.matching { - exclude("**/*.pyc") - }.singleFile - val specFiles = specDir.asFileTree.matching { include("**/*.stone") }.files @@ -83,7 +96,7 @@ abstract class StoneTask : DefaultTask() { pythonCommand.get(), "-m", "stone.cli", "--attribute", ":all", - generatorFile.absolutePath, + generatorFile.get().asFile, outputDirectory.resolve("src").absolutePath, *specFiles.map { it.absolutePath }.toTypedArray(), "--", "--package", stoneConfig.packageName, @@ -124,7 +137,7 @@ abstract class StoneTask : DefaultTask() { private fun buildRouteFilter(stoneConfig: StoneConfig): String { val client = stoneConfig.client - val routeFilters = listOf(stoneConfig.globalRouteFilter, client?.routeFilter).filterNotNull() + val routeFilters = listOfNotNull(stoneConfig.globalRouteFilter, client?.routeFilter) return routeFilters.joinToString(" and ") { "(${it})" } } } \ No newline at end of file