Skip to content

Commit

Permalink
Fix lexer and parser build cache misses
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Jul 15, 2024
1 parent c58995f commit 9987156
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
9 changes: 8 additions & 1 deletion buildSrc/src/main/kotlin/JFlexExec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,29 @@ import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileCollection
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity

@CacheableTask
abstract class JFlexExec : JavaExec() {

@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val sourceFile: RegularFileProperty

@get:InputFiles
@get:Classpath
abstract val jflex: ConfigurableFileCollection

@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val skeletonFile: RegularFileProperty

@get:OutputDirectory
Expand Down
13 changes: 8 additions & 5 deletions buildSrc/src/main/kotlin/ParserExec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,29 @@ import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Classpath
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity

@CacheableTask
abstract class ParserExec : JavaExec() {

@get:InputFile
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val sourceFile: RegularFileProperty

@get:InputFiles
@get:Classpath
abstract val grammarKit: ConfigurableFileCollection

@get:OutputDirectory
@get:Internal
abstract val destinationRootDirectory: DirectoryProperty

@get:OutputDirectory
abstract val destinationDirectory: DirectoryProperty

@get:OutputDirectory
abstract val psiDirectory: DirectoryProperty

Expand Down
6 changes: 3 additions & 3 deletions buildSrc/src/main/kotlin/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.RegisteringDomainObjectDelegateProviderWithTypeAndAction
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.provideDelegate
Expand All @@ -39,8 +40,8 @@ fun Project.lexer(flex: String, pack: String): TaskDelegate<JFlexExec> {

return tasks.registering(JFlexExec::class) {
sourceFile.set(layout.projectDirectory.file("src/main/grammars/$flex.flex"))
destinationDirectory.set(layout.buildDirectory.dir("gen/$pack"))
destinationFile.set(layout.buildDirectory.file("gen/$pack/$flex.java"))
destinationDirectory.set(layout.buildDirectory.dir("gen/$pack/lexer"))
destinationFile.set(layout.buildDirectory.file("gen/$pack/lexer/$flex.java"))
logFile.set(layout.buildDirectory.file("logs/generate$flex.log"))

val jflex by project.configurations
Expand All @@ -61,7 +62,6 @@ fun Project.parser(bnf: String, pack: String): TaskDelegate<ParserExec> {
val dest = destRoot.map { it.dir(pack) }
sourceFile.set(project.layout.projectDirectory.file("src/main/grammars/$bnf.bnf"))
destinationRootDirectory.set(destRoot)
destinationDirectory.set(dest)
psiDirectory.set(dest.map { it.dir("psi") })
parserDirectory.set(dest.map { it.dir("parser") })
logFile.set(layout.buildDirectory.file("logs/generate$bnf.log"))
Expand Down

0 comments on commit 9987156

Please sign in to comment.