Skip to content

Commit 4942eda

Browse files
committed
build(protocol): harden proto lint buf config
1 parent 4722d29 commit 4942eda

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

protocol/protoLint.gradle

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Except for legacy enums in the 'legacyEnums' whitelist, all newly defined Enums MUST reserve index 0 for a field starting with 'UNKNOWN_'.
1212
* This ensures robust forward/backward compatibility during proto3 JSON serialization.
1313
*/
14+
import groovy.json.JsonBuilder
1415
import groovy.json.JsonSlurper
1516
import org.gradle.internal.os.OperatingSystem
1617

@@ -39,10 +40,18 @@ task protoLint {
3940
// 2. generateProto: fix Gradle implicit dependency warning due to output directory overlap.
4041
dependsOn 'extractIncludeProto', 'generateProto'
4142

42-
// Incremental build support: Only run if proto files or the script itself changes
43+
// Wire the include proto directory from the extractIncludeProto task's actual output
44+
def extractTask = tasks.named('extractIncludeProto').get()
45+
def includeProtoDir = extractTask.destDir.get().asFile
46+
def includeProtoDirRel = projectDir.toPath().relativize(includeProtoDir.toPath()).toString()
47+
48+
// Incremental build support: re-run when any file buf physically reads changes.
49+
// Include protos are not lint targets, but buf reads them for import resolution,
50+
// so they must be declared as inputs to keep the task cache hermetic.
4351
inputs.dir('src/main/protos')
52+
inputs.dir(includeProtoDir)
4453
inputs.file('protoLint.gradle')
45-
54+
4655
def markerFile = file("${buildDir}/tmp/protoLint.done")
4756
outputs.file(markerFile)
4857

@@ -86,7 +95,7 @@ task protoLint {
8695

8796
println "🔍 Generating Proto AST image using buf CLI..."
8897

89-
def bufConfig = '{"version":"v1beta1","build":{"roots":["src/main/protos","build/extracted-include-protos/main"]}}'
98+
def bufConfig = new JsonBuilder([version: "v1beta1", build: [roots: ["src/main/protos", includeProtoDirRel]]]).toString()
9099

91100
def execResult = exec {
92101
commandLine bufExe.absolutePath, 'build', '.', '--config', bufConfig, '-o', "${imageFile.absolutePath}#format=json"

0 commit comments

Comments
 (0)