-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17164 from protocolbuffers/cp-stubs
Backport stubs / tests for compatibility with <4.26.x gencode to 27.x
- Loading branch information
Showing
8 changed files
with
246 additions
and
4 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
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,19 @@ | ||
# 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", | ||
) |
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, | ||
) |
83 changes: 83 additions & 0 deletions
83
java/core/src/main/java/com/google/protobuf/GeneratedMessageV3.java
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,83 @@ | ||
// Protocol Buffers - Google's data interchange format | ||
// Copyright 2024 Google LLC. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file or at | ||
// https://developers.google.com/open-source/licenses/bsd | ||
|
||
package com.google.protobuf; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Stub for GeneratedMessageV3 wrapping GeneratedMessage for compatibility with older gencode. | ||
* | ||
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change | ||
* (5.x in 2025 Q1). Users should update gencode to >= 4.26.x which uses GeneratedMessage | ||
* instead of GeneratedMessageV3. | ||
*/ | ||
@Deprecated | ||
public abstract class GeneratedMessageV3 extends GeneratedMessage { | ||
private static final long serialVersionUID = 1L; | ||
|
||
protected GeneratedMessageV3() { | ||
super(); | ||
} | ||
|
||
protected GeneratedMessageV3(Builder<?> builder) { | ||
super(builder); | ||
} | ||
|
||
/** | ||
* Stub for GeneratedMessageV3.ExtendableBuilder wrapping GeneratedMessage.ExtendableBuilder for | ||
* compatibility with older gencode. | ||
* | ||
* @deprecated This class is deprecated, and slated for removal in the next Java breaking change | ||
* (5.x in 2025 Q1). Users should update gencode to >= 4.26.x which uses | ||
* GeneratedMessage.ExtendableBuilder instead of GeneratedMessageV3.ExtendableBuilder. | ||
*/ | ||
@Deprecated | ||
public abstract static class ExtendableBuilder< | ||
MessageT extends ExtendableMessage<MessageT>, | ||
BuilderT extends ExtendableBuilder<MessageT, BuilderT>> | ||
extends GeneratedMessage.ExtendableBuilder<MessageT, BuilderT> | ||
implements GeneratedMessage.ExtendableMessageOrBuilder<MessageT> { | ||
protected ExtendableBuilder() { | ||
super(); | ||
} | ||
|
||
protected ExtendableBuilder(BuilderParent parent) { | ||
super(parent); | ||
} | ||
|
||
// Support old gencode override method removed in | ||
// https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24 | ||
public <T> BuilderT setExtension( | ||
final GeneratedMessage.GeneratedExtension<MessageT, T> extension, final T value) { | ||
return setExtension((ExtensionLite<MessageT, T>) extension, value); | ||
} | ||
|
||
// Support old gencode override method removed in | ||
// https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24 | ||
public <T> BuilderT setExtension( | ||
final GeneratedMessage.GeneratedExtension<MessageT, List<T>> extension, | ||
final int index, | ||
final T value) { | ||
return setExtension((ExtensionLite<MessageT, List<T>>) extension, index, value); | ||
} | ||
|
||
// Support old gencode override method removed in | ||
// https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24 | ||
public <T> BuilderT addExtension( | ||
final GeneratedMessage.GeneratedExtension<MessageT, List<T>> extension, final T value) { | ||
return addExtension((ExtensionLite<MessageT, List<T>>) extension, value); | ||
} | ||
|
||
// Support old gencode override method removed in | ||
// https://github.com/protocolbuffers/protobuf/commit/7bff169d32710b143951ec6ce2c4ea9a56e2ad24 | ||
public <T> BuilderT clearExtension( | ||
final GeneratedMessage.GeneratedExtension<MessageT, T> extension) { | ||
return clearExtension((ExtensionLite<MessageT, T>) extension); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
java/core/src/main/java/com/google/protobuf/RepeatedFieldBuilderV3.java
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,34 @@ | ||
// Protocol Buffers - Google's data interchange format | ||
// Copyright 2024 Google LLC. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file or at | ||
// https://developers.google.com/open-source/licenses/bsd | ||
|
||
package com.google.protobuf; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Stub for RepeatedFieldBuilderV3 wrapping RepeatedFieldBuilder for compatibility with older | ||
* gencode. | ||
* | ||
* @deprecated This class is deprecated, and slated for removal in the next breaking change. Users | ||
* should update gencode to >= 4.26.x which replaces RepeatedFieldBuilderV3 with | ||
* RepeatedFieldBuilder. | ||
*/ | ||
@Deprecated | ||
public class RepeatedFieldBuilderV3< | ||
MType extends GeneratedMessage, | ||
BType extends GeneratedMessage.Builder, | ||
IType extends MessageOrBuilder> | ||
extends RepeatedFieldBuilder<MType, BType, IType> { | ||
|
||
public RepeatedFieldBuilderV3( | ||
List<MType> messages, | ||
boolean isMessagesListMutable, | ||
GeneratedMessage.BuilderParent parent, | ||
boolean isClean) { | ||
super(messages, isMessagesListMutable, parent, isClean); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
java/core/src/main/java/com/google/protobuf/SingleFieldBuilderV3.java
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,28 @@ | ||
// Protocol Buffers - Google's data interchange format | ||
// Copyright 2024 Google LLC. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file or at | ||
// https://developers.google.com/open-source/licenses/bsd | ||
|
||
package com.google.protobuf; | ||
|
||
/** | ||
* Stub for SingleFieldBuilderV3 wrapping SingleFieldBuilder for compatibility with older gencode. | ||
* | ||
* @deprecated This class is deprecated, and slated for removal in the next breaking change. Users | ||
* should update gencode to >= 4.26.x which replaces SingleFieldBuilderV3 with | ||
* SingleFieldBuilder. | ||
*/ | ||
@Deprecated | ||
public class SingleFieldBuilderV3< | ||
MType extends GeneratedMessage, | ||
BType extends GeneratedMessage.Builder, | ||
IType extends MessageOrBuilder> | ||
extends SingleFieldBuilder<MType, BType, IType> { | ||
|
||
public SingleFieldBuilderV3( | ||
MType message, GeneratedMessage.BuilderParent parent, boolean isClean) { | ||
super(message, parent, isClean); | ||
} | ||
} |
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