-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple conformance test that builds the old gencode against the c…
…urrent runtime. PiperOrigin-RevId: 631486123
- Loading branch information
1 parent
6c6f514
commit 9cfb59b
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Simple build tests for compatibility of gencode from previous major versions | ||
# with the current runtime. | ||
# | ||
# To add more test cases in Java, use java_runtime_conformance as below, and add | ||
# the corresponding http_archive in the WORKSPACE file for the version. | ||
|
||
load("//compatibility:runtime_conformance.bzl", "java_runtime_conformance") | ||
|
||
# main gencode builds with main runtime as a proof of concept. | ||
java_runtime_conformance( | ||
name = "java_conformance_main", | ||
gencode_version = "main", | ||
) | ||
|
||
# Generates a build_test named "conformance_v3.25.0" | ||
java_runtime_conformance( | ||
name = "java_conformance_v3.25.0", | ||
gencode_version = "3.25.0", | ||
tags = ["manual"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""Provides a rule to generate a conformance test for a given version of the gencode.""" | ||
|
||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
|
||
def java_runtime_conformance(name, gencode_version, tags = []): | ||
"""Generates a conformance test for the given version of the runtime. | ||
For example, runtime_conformance("3.19.4") will generate a build test named "conformance_v3.19.4" | ||
that will fail if the runtime at that version fails to compile the unittest proto. | ||
Args: | ||
name: The name of the test. | ||
gencode_version: The version of the runtime to test. | ||
tags: Any tags to apply to the generated test. | ||
""" | ||
|
||
if gencode_version == "main": | ||
protoc = "//:protoc" | ||
else: | ||
minor = gencode_version[gencode_version.find(".") + 1:] | ||
protoc = Label("@com_google_protobuf_v%s//:protoc" % minor) | ||
|
||
gencode = [ | ||
"v%s/protobuf_unittest/UnittestProto.java" % gencode_version, | ||
"v%s/com/google/protobuf/test/UnittestImport.java" % gencode_version, | ||
"v%s/com/google/protobuf/test/UnittestImportPublic.java" % gencode_version, | ||
] | ||
native.genrule( | ||
name = "unittest_proto_gencode_v" + gencode_version, | ||
srcs = [ | ||
"//src/google/protobuf:unittest_proto_srcs", | ||
], | ||
outs = gencode, | ||
cmd = "$(location %s) " % protoc + | ||
"$(locations //src/google/protobuf:unittest_proto_srcs) " + | ||
" -Isrc/ --java_out=$(@D)/v%s" % gencode_version, | ||
tools = [protoc], | ||
) | ||
|
||
conformance_name = "conformance_v" + gencode_version | ||
conformance_lib_name = conformance_name + "_lib" | ||
native.java_library( | ||
name = conformance_lib_name, | ||
srcs = gencode, | ||
deps = ["//java/core"], | ||
tags = tags, | ||
) | ||
|
||
build_test( | ||
name = name, | ||
targets = [":" + conformance_lib_name], | ||
tags = tags, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters