Skip to content
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
61 changes: 60 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,66 @@ tasks.register<Exec>("generateTestSourcesNoImports") {
commandLine(buf.asPath, "generate", "--template", "src/test/resources/proto/buf.gen.noimports.yaml")
}

tasks.register<Exec>("generateCelConformance") {
dependsOn("generateCelConformanceTestTypes")
description = "Generates CEL conformance code with buf generate for unit tests."
commandLine(
buf.asPath,
"generate",
"--template",
"src/test/resources/proto/buf.gen.cel.yaml",
"buf.build/google/cel-spec:${project.findProperty("cel.spec.version")}",
"--exclude-path",
"cel/expr/conformance/proto2",
"--exclude-path",
"cel/expr/conformance/proto3",
)
}

// The conformance tests use the Protobuf package path for tests that use these types.
// i.e. cel.expr.conformance.proto3.TestAllTypes. But, if we use managed mode it adds 'com'
// to the prefix. Additionally, we can't disable managed mode because the java_package option
// specified in these proto files is "dev.cel.expr.conformance.proto3". So, to get around this,
// we're generating these separately and specifying a java_package override of the package we need.
Copy link
Contributor Author

@smaye81 smaye81 May 28, 2025

Choose a reason for hiding this comment

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

We could just use one buf.gen.yaml for both cel generation steps, but then we'd have to specify the conformance version there also when we generate. Then we'd have the version in a 3rd place, which doesn't seem ideal.

Also, if there is an easier way to override the java_package with a blank value, that would also work here but I don't think there is.

tasks.register<Exec>("generateCelConformanceTestTypes") {
dependsOn("exportProtovalidateModule")
description = "Generates CEL conformance test types with buf generate for unit tests using a Java package override."
commandLine(
buf.asPath,
"generate",
"--template",
"src/test/resources/proto/buf.gen.cel.testtypes.yaml",
"buf.build/google/cel-spec:${project.findProperty("cel.spec.version")}",
"--path",
"cel/expr/conformance/proto3",
)
}

var getCelTestData =
tasks.register<Exec>("getCelTestData") {
val celVersion = project.findProperty("cel.spec.version")
val fileUrl = "https://raw.githubusercontent.com/google/cel-spec/refs/tags/$celVersion/tests/simple/testdata/string_ext.textproto"
val targetDir = File("${project.projectDir}/src/test/resources/testdata")
val file = File(targetDir, "string_ext_$celVersion.textproto")

onlyIf {
// Only run curl if file doesn't exist
!file.exists()
}
doFirst {
file.parentFile.mkdirs()
commandLine(
"curl",
"-fsSL",
"-o",
file.absolutePath,
fileUrl,
)
}
}

tasks.register("generateTestSources") {
dependsOn("generateTestSourcesImports", "generateTestSourcesNoImports")
dependsOn("generateTestSourcesImports", "generateTestSourcesNoImports", "generateCelConformance")
description = "Generates code with buf generate for unit tests"
}

Expand Down Expand Up @@ -206,6 +264,7 @@ allprojects {
}
}
tasks.withType<Test>().configureEach {
dependsOn(getCelTestData)
useJUnitPlatform()
this.testLogging {
events("failed")
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ protovalidate.conformance.args = --strict_message --strict_error --expected_fail

# Argument to the license-header CLI
license-header.years = 2023-2024

# Version of the cel-spec that this implementation is conformant with
cel.spec.version = v0.24.0
Loading