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

Fix StoneTask cache misses #530

Merged
merged 3 commits into from
Mar 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,7 +57,7 @@ class StonePlugin : Plugin<Project> {
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}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -21,44 +22,56 @@ abstract class StoneTask : DefaultTask() {
@get:Input
abstract val stoneConfigs: ListProperty<StoneConfig>

@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<String>

@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."
}

val outputDirectory = outputDir.asFile.get()
outputDirectory.deleteRecursively()
outputDirectory.mkdirs()

val generatorFile = generatorDir.asFileTree.matching {
exclude("**/*.pyc")
}.singleFile

val specFiles = specDir.asFileTree.matching {
include("**/*.stone")
}.files
Expand All @@ -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,
Expand Down Expand Up @@ -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})" }
}
}
Loading