ADD: added new version of protobuf

This commit is contained in:
Henry Winkel
2022-12-20 10:09:28 +01:00
parent 4a79559129
commit 1e2b3dda7b
1513 changed files with 123720 additions and 83381 deletions

View File

@@ -2,127 +2,22 @@
#
# See also code generation logic under /src/google/protobuf/compiler/php.
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@upb//cmake:build_defs.bzl", "staleness_test")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load("//conformance:defs.bzl", "conformance_test")
filegroup(
name = "source_files",
visibility = [
"//conformance:__pkg__",
"//php:__pkg__",
],
srcs = glob([
"ext/google/protobuf/*.h",
"ext/google/protobuf/*.c",
"src/GPBMetadata/Google/Protobuf/**/*.php",
"src/Google/Protobuf/**/*.php",
]) + [
"composer.json",
"ext/google/protobuf/wkt.inc",
"ext/google/protobuf/config.m4",
"ext/google/protobuf/package.xml",
],
)
################################################################################
# PHP Extension
################################################################################
inline_sh_binary(
name = "build_extension",
cmd = """
mkdir -p php/ext/google/protobuf/third_party/utf8_range
cp external/utf8_range/* php/ext/google/protobuf/third_party/utf8_range
pushd php/ext/google/protobuf
phpize
./configure --with-php-config=$$(which php-config)
make
popd
""",
)
genrule(
name = "extension",
srcs = [
":source_files",
"@utf8_range//:utf8_range_srcs",
],
tools = [":build_extension"],
outs = ["protobuf.so"],
cmd = """
./$(execpath :build_extension) $@
cp php/ext/google/protobuf/modules/protobuf.so $(OUTS)
""",
visibility = ["//visibility:public"],
)
################################################################################
# Tests
################################################################################
conformance_test(
name = "conformance_test",
failure_list = "//conformance:failure_list_php.txt",
testee = "//conformance:conformance_php",
text_format_failure_list = "//conformance:text_format_failure_list_php.txt",
target_compatible_with = select({
"@platforms//os:osx": ["@platforms//:incompatible"],
"//conditions:default": [],
}),
)
conformance_test(
name = "conformance_test_c",
failure_list = "//conformance:failure_list_php_c.txt",
testee = "//conformance:conformance_php_c",
text_format_failure_list = "//conformance:text_format_failure_list_php.txt",
target_compatible_with = select({
"@platforms//os:osx": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
genrule(
name = "copy_php_amalgamation_h",
srcs = ["@upb//:php-upb.h"],
outs = ["generated-in/ext/google/protobuf/php-upb.h"],
cmd = "cp $< $@",
)
genrule(
name = "copy_php_amalgamation_c",
srcs = ["@upb//:php-upb.c"],
outs = ["generated-in/ext/google/protobuf/php-upb.c"],
cmd = "cp $< $@",
)
staleness_test(
name = "test_amalgamation_staleness",
outs = [
"ext/google/protobuf/php-upb.h",
"ext/google/protobuf/php-upb.c",
],
generated_pattern = "generated-in/%s",
)
################################################################################
# Distribution files
################################################################################
load("@rules_pkg//:pkg.bzl", "pkg_tar")
load("@rules_pkg//:mappings.bzl", "pkg_files", "pkg_filegroup", "strip_prefix")
load("//:protobuf_version.bzl", "PROTOBUF_PHP_VERSION")
pkg_files(
name = "dist_files",
srcs = glob([
"ext/google/protobuf/**/*",
"src/GPBMetadata/Google/Protobuf/**/*.php",
"src/Google/Protobuf/**/*.php",
"tests/*.php",
"tests/*.sh",
"tests/generated_previous/**/*.php",
"tests/proto/**/*.proto",
"tests/proto_previous/*.proto",
]) + [
":source_files",
"BUILD.bazel",
"README.md",
"REFCOUNTING.md",
@@ -137,3 +32,76 @@ pkg_files(
strip_prefix = strip_prefix.from_pkg(""),
visibility = ["//pkg:__pkg__"],
)
################################################################################
# PECL .tgz Release
################################################################################
pkg_files(
name = "php_ext_source_files",
srcs = glob([
"ext/google/protobuf/*.h",
"ext/google/protobuf/*.c",
]) + [
"//:LICENSE",
"ext/google/protobuf/config.m4",
"ext/google/protobuf/wkt.inc",
],
)
pkg_files(
name = "utf8_range_files",
srcs = [
"//third_party/utf8_range:utf8_range_srcs",
"//third_party/utf8_range:LICENSE",
],
prefix = "third_party/utf8_range",
)
pkg_filegroup(
name = "pecl_release_files",
srcs = [
":php_ext_source_files",
":utf8_range_files",
],
prefix = "protobuf-%s" % PROTOBUF_PHP_VERSION,
)
# PECL .tgz without package.xml
pkg_tar(
name = "release_without_package",
extension = "tgz",
srcs = [
":pecl_release_files",
],
out = "release_without_package.tgz",
)
# Generate PECL package.xml
genrule(
name = "generate_package_xml",
srcs = [
":release_without_package",
"ext/google/protobuf/template_package.xml",
],
outs = ["package.xml"],
cmd = " ".join([
"$(location ext/google/protobuf/generate_package_xml.sh)",
"$(location ext/google/protobuf/template_package.xml)",
PROTOBUF_PHP_VERSION,
"$$(tar -tf $(location :release_without_package) | sed -z -e 's;\\n;,;g')",
"$(location package.xml)"
]),
tools = ["ext/google/protobuf/generate_package_xml.sh"],
)
pkg_tar(
name = "release",
extension = "tgz",
srcs = [
":pecl_release_files",
":generate_package_xml",
],
out = "protobuf-%s.tgz" % PROTOBUF_PHP_VERSION,
)

View File

@@ -26,6 +26,8 @@ To use PHP runtime library requires:
#### Prerequirements
To install the c extension, the following tools are needed:
* autoconf
* automake
* libtool
* make
* gcc
@@ -34,7 +36,7 @@ To install the c extension, the following tools are needed:
On Ubuntu, you can install them with:
```
sudo apt-get install -y php-pear php-dev libtool make gcc
sudo apt-get install -y php-pear php5-dev autoconf automake libtool make gcc
```
On other platforms, please use the corresponding package managing tool to
install them before proceeding.
@@ -65,8 +67,6 @@ sudo pecl install protobuf-{VERSION}
Simply add "google/protobuf" to the 'require' section of composer.json in your
project.
To use the pure PHP implementation, you need to install bcmath.
### Protoc
Once the extension or package is installed, if you wish to generate PHP code
@@ -98,18 +98,24 @@ Known Issues
## Development
### Docker Image
We provide a docker image for php development, which is also used in our automatic tests:
```
docker run --security-opt seccomp=unconfined -it protobuftesting/php_8dbe419c6df1a8b3af0ae3a267c112efb436b45c
```
### Test Native PHP
```
# Install Dependencies (Linux)
apt-get install bazel composer php-dev
# Download protobuf
git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
# Build protoc
bazel build :protoc
./autogen.sh
./configure
make -j4
# Test native php
cd php

View File

@@ -30,8 +30,5 @@
"test_valgrind": "./generate_test_protos.sh && ./tests/compile_extension.sh && ZEND_DONT_UNLOAD_MODULES=1 USE_ZEND_ALLOC=0 valgrind --leak-check=full --error-exitcode=1 php -dextension=ext/google/protobuf/modules/protobuf.so vendor/bin/phpunit --bootstrap tests/force_c_ext.php tests",
"test": "./generate_test_protos.sh && vendor/bin/phpunit tests",
"aggregate_metadata_test": "./generate_test_protos.sh --aggregate_metadata && vendor/bin/phpunit tests"
},
"config": {
"process-timeout": 1200
}
}

View File

@@ -0,0 +1,39 @@
#!/bin/bash
template_package_xml=$1
release_version=$2
release_files=$3
out=$4
date=$(date +%Y-%m-%d)
time=$(date +%H:%M:%S)
php_version_array=(${release_version//RC/ })
api_version=${php_version_array[0]}
if [ ${#php_version_array[@]} -eq 2 ]; then
rc=${php_version_array[1]}
stability='beta'
else
stability='stable'
fi
files="\\n"
for file in ${release_files//,/ }; do
name=$(echo $file | grep .*[^/]\$ | sed -e "s;protobuf-${release_version}/;;")
if [ ! -z $name ]; then
if [[ $name =~ LICENSE$ ]]; then
role='doc'
else
role='src'
fi
files+=" <file baseinstalldir=\"/\" name=\"${name}\" role=\"${role}\"/>\\n"
fi
done
cat $template_package_xml |
sed -e "s;TEMPLATE_DATE;${date};" |
sed -e "s;TEMPLATE_TIME;${time};" |
sed -e "s;TEMPLATE_PHP_RELEASE;${release_version};" |
sed -e "s;TEMPLATE_PHP_API;${api_version};" |
sed -e "s;TEMPLATE_PHP_STABILITY;${stability};g" |
sed -e "s;TEMPLATE_FILES;${files};" > $out

View File

@@ -601,7 +601,7 @@ PHP_METHOD(Message, __construct) {
//
// However, if the user created their own class derived from Message, this
// will trigger an infinite construction loop and blow the stack. We
// store this `ce` in a global variable to break the cycle (see the check in
// temporarily clear create_object to break this loop (see check in
// NameMap_GetMessage()).
NameMap_EnterConstructor(ce);
desc = Descriptor_GetFromClassEntry(ce);
@@ -646,25 +646,6 @@ PHP_METHOD(Message, clear) {
upb_Message_Clear(intern->msg, intern->desc->msgdef);
}
static bool Message_checkEncodeStatus(upb_EncodeStatus status) {
switch (status) {
case kUpb_EncodeStatus_Ok:
return true;
case kUpb_EncodeStatus_OutOfMemory:
zend_throw_exception_ex(NULL, 0, "Out of memory");
return false;
case kUpb_EncodeStatus_MaxDepthExceeded:
zend_throw_exception_ex(NULL, 0, "Max nesting exceeded");
return false;
case kUpb_EncodeStatus_MissingRequired:
zend_throw_exception_ex(NULL, 0, "Missing required field");
return false;
default:
zend_throw_exception_ex(NULL, 0, "Unknown error encoding");
return false;
}
}
/**
* Message::mergeFrom()
*
@@ -692,9 +673,14 @@ PHP_METHOD(Message, mergeFrom) {
// zend_parse_parameters().
PBPHP_ASSERT(from->desc == intern->desc);
// TODO(haberman): use a temp arena for this.
upb_EncodeStatus status = upb_Encode(from->msg, l, 0, arena, &pb, &size);
if (!Message_checkEncodeStatus(status)) return;
// TODO(haberman): use a temp arena for this once we can make upb_decode()
// copy strings.
pb = upb_Encode(from->msg, l, 0, arena, &size);
if (!pb) {
zend_throw_exception_ex(NULL, 0, "Max nesting exceeded");
return;
}
ok = upb_Decode(pb, size, intern->msg, l, NULL, 0, arena) ==
kUpb_DecodeStatus_Ok;
@@ -744,9 +730,7 @@ PHP_METHOD(Message, serializeToString) {
char *data;
size_t size;
upb_EncodeStatus status =
upb_Encode(intern->msg, l, 0, tmp_arena, &data, &size);
if (!Message_checkEncodeStatus(status)) return;
data = upb_Encode(intern->msg, l, 0, tmp_arena, &size);
if (!data) {
zend_throw_exception_ex(NULL, 0, "Error occurred during serialization");
@@ -1248,12 +1232,8 @@ PHP_METHOD(google_protobuf_Any, pack) {
msg = (Message*)Z_OBJ_P(val);
// Serialize and set value.
char* pb;
upb_EncodeStatus status =
upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->desc->msgdef), 0,
arena, &pb, &value.size);
if (!Message_checkEncodeStatus(status)) return;
value.data = pb;
value.data = upb_Encode(msg->msg, upb_MessageDef_MiniTable(msg->desc->msgdef),
0, arena, &value.size);
Message_setval(intern, "value", StringVal(value));
// Set type url: type_url_prefix + fully_qualified_name

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -127,7 +127,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_setter, 0, 0, 1)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
#define PHP_PROTOBUF_VERSION "3.21.8"
#define PHP_PROTOBUF_VERSION "3.21.12"
// ptr -> PHP object cache. This is a weak map that caches lazily-created
// wrapper objects around upb types:

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" packagerversion="1.9.5" version="2.0" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd">
<name>protobuf</name>
<channel>pecl.php.net</channel>
<summary>Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data.</summary>
<description>https://developers.google.com/protocol-buffers/</description>
<lead>
<name>Protobuf Team</name>
<user>protobufpackages</user>
<email>protobuf-packages@google.com</email>
<active>yes</active>
</lead>
<date>TEMPLATE_DATE</date>
<time>TEMPLATE_TIME</time>
<version>
<release>TEMPLATE_PHP_RELEASE</release>
<api>TEMPLATE_PHP_API</api>
</version>
<stability>
<release>TEMPLATE_PHP_STABILITY</release>
<api>TEMPLATE_PHP_STABILITY</api>
</stability>
<license uri="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</license>
<notes>
* See github.com/protocolbuffers/protobuf/releases for release notes.
</notes>
<contents>
<dir baseinstalldir="/" name="/">TEMPLATE_FILES</dir>
</contents>
<dependencies>
<required>
<php>
<min>7.0.0</min>
</php>
<pearinstaller>
<min>1.4.0</min>
</pearinstaller>
</required>
</dependencies>
<providesextension>protobuf</providesextension>
<extsrcrelease/>
</package>

View File

@@ -5,14 +5,6 @@
set -e
if [[ -z "${PROTOC}" ]]; then
PROTOC=$(realpath protoc)
fi
if [ ! -f $PROTOC ]; then
bazel build -c opt //:protoc
PROTOC=$(realpath bazel-bin/protoc)
fi
if test ! -e src/google/protobuf/stubs/common.h; then
cat >&2 << __EOF__
Could not find source code. Make sure you are running this script from the
@@ -22,8 +14,8 @@ __EOF__
fi
pushd src
$PROTOC --php_out=internal:../php/src google/protobuf/descriptor.proto
$PROTOC --php_out=internal_generate_c_wkt:../php/src \
./protoc --php_out=internal:../php/src google/protobuf/descriptor.proto
./protoc --php_out=internal_generate_c_wkt:../php/src \
google/protobuf/any.proto \
google/protobuf/api.proto \
google/protobuf/duration.proto \

View File

@@ -2,17 +2,19 @@
set -ex
cd `dirname $0`/..
cd `dirname $0`
if [[ -z "${PROTOC}" ]]; then
PROTOC=$(pwd)/protoc
fi
if [ ! -f $PROTOC ]; then
bazel build -c opt //:protoc
PROTOC=$(pwd)/bazel-bin/protoc
if ../src/protoc --help > /dev/null; then
PROTOC=src/protoc
else
# Bazel seems to be creating a problematic symlink in
# _build/out/external/com_google_protobuf, so we remove the _build directory
# before building protoc.
(cd .. && bazel build -c opt :protoc)
PROTOC=bazel-bin/protoc
fi
if [[ -d php/tmp && -z $(find php/tests/proto $PROTOC -newer php/tmp) ]]; then
if [[ -d tmp && -z $(find tests/proto ../$PROTOC -newer tmp) ]]; then
# Generated protos are already present and up to date, so we can skip protoc.
#
# Protoc is very fast, but sometimes it is not available (like if we haven't
@@ -21,9 +23,10 @@ if [[ -d php/tmp && -z $(find php/tests/proto $PROTOC -newer php/tmp) ]]; then
exit 0
fi
rm -rf php/tmp
mkdir -p php/tmp
rm -rf tmp
mkdir -p tmp
cd ..
find php/tests/proto -type f -name "*.proto"| xargs $PROTOC --php_out=php/tmp -Isrc -Iphp/tests
if [ "$1" = "--aggregate_metadata" ]; then

View File

@@ -31,7 +31,6 @@ class Descriptor
->optional('options', \Google\Protobuf\Internal\GPBType::MESSAGE, 8, 'google.protobuf.internal.FileOptions')
->optional('source_code_info', \Google\Protobuf\Internal\GPBType::MESSAGE, 9, 'google.protobuf.internal.SourceCodeInfo')
->optional('syntax', \Google\Protobuf\Internal\GPBType::STRING, 12)
->optional('edition', \Google\Protobuf\Internal\GPBType::STRING, 13)
->finalizeToPool();
$pool->addMessage('google.protobuf.internal.DescriptorProto', \Google\Protobuf\Internal\DescriptorProto::class)

View File

@@ -74,8 +74,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of May 2022, lazy verifies the contents of the byte stream during
* parsing. An invalid byte stream will cause the overall parsing to fail.
* As of 2021, lazy does no correctness checks on the byte stream during
* parsing. This may lead to crashes if and when an invalid byte stream is
* finally parsed upon access.
* TODO(b/211906113): Enable validation on lazy fields.
*
* Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code>
*/
@@ -163,8 +165,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of May 2022, lazy verifies the contents of the byte stream during
* parsing. An invalid byte stream will cause the overall parsing to fail.
* As of 2021, lazy does no correctness checks on the byte stream during
* parsing. This may lead to crashes if and when an invalid byte stream is
* finally parsed upon access.
* TODO(b/211906113): Enable validation on lazy fields.
* @type bool $unverified_lazy
* unverified_lazy does no correctness checks on the byte stream. This should
* only be used where lazy with verification is prohibitive for performance
@@ -350,8 +354,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of May 2022, lazy verifies the contents of the byte stream during
* parsing. An invalid byte stream will cause the overall parsing to fail.
* As of 2021, lazy does no correctness checks on the byte stream during
* parsing. This may lead to crashes if and when an invalid byte stream is
* finally parsed upon access.
* TODO(b/211906113): Enable validation on lazy fields.
*
* Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code>
* @return bool
@@ -396,8 +402,10 @@ class FieldOptions extends \Google\Protobuf\Internal\Message
* implementation must either *always* check its required fields, or *never*
* check its required fields, regardless of whether or not the message has
* been parsed.
* As of May 2022, lazy verifies the contents of the byte stream during
* parsing. An invalid byte stream will cause the overall parsing to fail.
* As of 2021, lazy does no correctness checks on the byte stream during
* parsing. This may lead to crashes if and when an invalid byte stream is
* finally parsed upon access.
* TODO(b/211906113): Enable validation on lazy fields.
*
* Generated from protobuf field <code>optional bool lazy = 5 [default = false];</code>
* @param bool $var

View File

@@ -81,18 +81,11 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
protected $source_code_info = null;
/**
* The syntax of the proto file.
* The supported values are "proto2", "proto3", and "editions".
* If `edition` is present, this value must be "editions".
* The supported values are "proto2" and "proto3".
*
* Generated from protobuf field <code>optional string syntax = 12;</code>
*/
protected $syntax = null;
/**
* The edition of the proto file, which is an opaque string.
*
* Generated from protobuf field <code>optional string edition = 13;</code>
*/
protected $edition = null;
/**
* Constructor.
@@ -124,10 +117,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
* development tools.
* @type string $syntax
* The syntax of the proto file.
* The supported values are "proto2", "proto3", and "editions".
* If `edition` is present, this value must be "editions".
* @type string $edition
* The edition of the proto file, which is an opaque string.
* The supported values are "proto2" and "proto3".
* }
*/
public function __construct($data = NULL) {
@@ -455,8 +445,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
/**
* The syntax of the proto file.
* The supported values are "proto2", "proto3", and "editions".
* If `edition` is present, this value must be "editions".
* The supported values are "proto2" and "proto3".
*
* Generated from protobuf field <code>optional string syntax = 12;</code>
* @return string
@@ -478,8 +467,7 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
/**
* The syntax of the proto file.
* The supported values are "proto2", "proto3", and "editions".
* If `edition` is present, this value must be "editions".
* The supported values are "proto2" and "proto3".
*
* Generated from protobuf field <code>optional string syntax = 12;</code>
* @param string $var
@@ -493,41 +481,5 @@ class FileDescriptorProto extends \Google\Protobuf\Internal\Message
return $this;
}
/**
* The edition of the proto file, which is an opaque string.
*
* Generated from protobuf field <code>optional string edition = 13;</code>
* @return string
*/
public function getEdition()
{
return isset($this->edition) ? $this->edition : '';
}
public function hasEdition()
{
return isset($this->edition);
}
public function clearEdition()
{
unset($this->edition);
}
/**
* The edition of the proto file, which is an opaque string.
*
* Generated from protobuf field <code>optional string edition = 13;</code>
* @param string $var
* @return $this
*/
public function setEdition($var)
{
GPBUtil::checkString($var, True);
$this->edition = $var;
return $this;
}
}

View File

@@ -54,7 +54,6 @@ use Google\Protobuf\NullValue;
* or extend this class or its child classes by their own. See the comment of
* specific functions for more details.
*/
#[\AllowDynamicProperties]
class Message
{
@@ -1981,12 +1980,8 @@ class Message
$size += 9;
$size += $value_msg->jsonByteSize();
} else {
$value_size = $value_msg->jsonByteSize();
// size === 2 it's empty message {} which is not serialized inside any
if ($value_size !== 2) {
// Size for value. +1 for comma, -2 for "{}".
$size += $value_size -1;
}
// Size for value. +1 for comma, -2 for "{}".
$size += $value_msg->jsonByteSize() -1;
}
} elseif (get_class($this) === 'Google\Protobuf\FieldMask') {
$field_mask = GPBUtil::formatFieldMask($this);

View File

@@ -53,9 +53,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
*/
protected $deprecated = null;
/**
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* Whether the message is an automatically generated map entry type for the
* maps field.
* For maps fields:
@@ -71,6 +68,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as
* if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
*
* Generated from protobuf field <code>optional bool map_entry = 7;</code>
*/
@@ -114,9 +114,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* for the message, or it will be completely ignored; in the very least,
* this is a formalization for deprecating messages.
* @type bool $map_entry
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* Whether the message is an automatically generated map entry type for the
* maps field.
* For maps fields:
@@ -132,6 +129,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as
* if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* @type array<\Google\Protobuf\Internal\UninterpretedOption>|\Google\Protobuf\Internal\RepeatedField $uninterpreted_option
* The parser stores options it doesn't recognize here. See above.
* }
@@ -288,9 +288,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
}
/**
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* Whether the message is an automatically generated map entry type for the
* maps field.
* For maps fields:
@@ -306,6 +303,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as
* if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
*
* Generated from protobuf field <code>optional bool map_entry = 7;</code>
* @return bool
@@ -326,9 +326,6 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
}
/**
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
* Whether the message is an automatically generated map entry type for the
* maps field.
* For maps fields:
@@ -344,6 +341,9 @@ class MessageOptions extends \Google\Protobuf\Internal\Message
* use a native map in the target language to hold the keys and values.
* The reflection APIs in such implementations still need to work as
* if the field is a repeated message field.
* NOTE: Do not set the option in .proto files. Always use the maps syntax
* instead. The option should only be implicitly set by the proto compiler
* parser.
*
* Generated from protobuf field <code>optional bool map_entry = 7;</code>
* @param bool $var

View File

@@ -5,7 +5,6 @@ require_once('test_util.php');
use Google\Protobuf\RepeatedField;
use Google\Protobuf\GPBType;
use Foo\EmptyAnySerialization;
use Foo\TestInt32Value;
use Foo\TestInt64Value;
use Foo\TestUInt32Value;
@@ -1514,22 +1513,4 @@ class EncodeDecodeTest extends TestBase
[TestStringValue::class, "a", "\"a\"", "", "\"\""],
];
}
public function testEmptyAnySerialization()
{
$m = new EmptyAnySerialization();
$any = new Any();
$any->pack($m);
$data = $any->serializeToJsonString();
$this->assertEquals('{"@type":"type.googleapis.com/foo.EmptyAnySerialization"}', $data);
$any = new Any();
$any->mergeFromJsonString($data);
$m = $any->unpack();
$this->assertInstanceOf(EmptyAnySerialization::class, $m);
$this->assertEquals('', $m->getA());
}
}

View File

@@ -275,13 +275,13 @@ class PhpImplementationTest extends TestBase
$this->assertSame(0x7FFFFFFE, GPBWire::zigZagEncode64(0x3FFFFFFF));
$this->assertSame(
0x7FFFFFFF,
GPBWire::zigZagEncode64(-1073741824)); // 0xFFFFFFFFC0000000
GPBWire::zigZagEncode64(0xFFFFFFFFC0000000));
$this->assertSame(
0xFFFFFFFE,
GPBWire::zigZagEncode64(0x7FFFFFFF));
$this->assertSame(
0xFFFFFFFF,
GPBWire::zigZagEncode64(-2147483648)); // 0xFFFFFFFF80000000
GPBWire::zigZagEncode64(0xFFFFFFFF80000000));
$this->assertSame(
-2, // 0xFFFFFFFFFFFFFFFE
GPBWire::zigZagEncode64(0x7FFFFFFFFFFFFFFF));

View File

@@ -0,0 +1,152 @@
#!/bin/bash
function generate_proto() {
PROTOC1=$1
PROTOC2=$2
rm -rf generated
mkdir generated
$PROTOC1 --php_out=generated proto/test_include.proto
$PROTOC2 --php_out=generated \
-I../../src -I. \
proto/empty/echo.proto \
proto/test.proto \
proto/test_no_namespace.proto \
proto/test_prefix.proto \
proto/test_php_namespace.proto \
proto/test_empty_php_namespace.proto \
proto/test_reserved_enum_lower.proto \
proto/test_reserved_enum_upper.proto \
proto/test_reserved_enum_value_lower.proto \
proto/test_reserved_enum_value_upper.proto \
proto/test_reserved_message_lower.proto \
proto/test_reserved_message_upper.proto \
proto/test_service.proto \
proto/test_service_namespace.proto \
proto/test_wrapper_type_setters.proto \
proto/test_descriptors.proto
pushd ../../src
$PROTOC2 --php_out=../php/tests/generated -I../php/tests -I. ../php/tests/proto/test_import_descriptor_proto.proto
popd
}
# Remove tests to expect error. These were added to API tests by mistake.
function remove_error_test() {
local TEMPFILE=`tempfile`
cat $1 | \
awk -v file=`basename $1` -v dir=`basename $(dirname $1)` '
BEGIN {
show = 1
}
/@expectedException PHPUnit_Framework_Error/ { show = 0; next; }
/ *\*\// { print; next; }
/ *}/ {
if (!show) {
show = 1;
next;
}
}
show { print }
' > $TEMPFILE
cp $TEMPFILE $1
}
set -ex
# Change to the script's directory.
cd $(dirname $0)
OLD_VERSION=$1
OLD_VERSION_PROTOC=https://repo1.maven.org/maven2/com/google/protobuf/protoc/$OLD_VERSION/protoc-$OLD_VERSION-linux-x86_64.exe
# Extract the latest protobuf version number.
VERSION_NUMBER=`grep "PHP_PROTOBUF_VERSION" ../ext/google/protobuf/protobuf.h | sed "s|#define PHP_PROTOBUF_VERSION \"\(.*\)\"|\1|"`
echo "Running compatibility tests between current $VERSION_NUMBER and released $OLD_VERSION"
# Check protoc
[ -f ../../src/protoc ] || {
echo "[ERROR]: Please build protoc first."
exit 1
}
# Download old test.
rm -rf protobuf
git clone https://github.com/protocolbuffers/protobuf.git
pushd protobuf
git checkout v$OLD_VERSION
popd
# Build and copy the new runtime
pushd ../ext/google/protobuf
make clean || true
phpize && ./configure && make
popd
rm -rf protobuf/php/ext
rm -rf protobuf/php/src
cp -r ../ext protobuf/php/ext/
cp -r ../src protobuf/php/src/
# Download old version protoc compiler (for linux)
wget $OLD_VERSION_PROTOC -O old_protoc
chmod +x old_protoc
NEW_PROTOC=`pwd`/../../src/protoc
OLD_PROTOC=`pwd`/old_protoc
cd protobuf/php
composer install
# Remove implementation detail tests.
# TODO(teboring): Temporarily disable encode_decode_test.php. In 3.13.0-rc1,
# repeated primitive field encoding is changed to packed, which is a bug fix.
# However, this fails the compatibility test which hard coded old encoding.
# Will re-enable the test after making a release. After the version bump, the
# compatibility test will use the updated test code.
tests=( array_test.php generated_class_test.php map_field_test.php well_known_test.php )
sed -i.bak '/php_implementation_test.php/d' phpunit.xml
sed -i.bak '/generated_phpdoc_test.php/d' phpunit.xml
sed -i.bak '/encode_decode_test.php/d' phpunit.xml
sed -i.bak 's/generated_phpdoc_test.php//g' tests/test.sh
sed -i.bak 's/generated_service_test.php//g' tests/test.sh
sed -i.bak 's/encode_decode_test.php//g' tests/test.sh
sed -i.bak '/memory_leak_test.php/d' tests/test.sh
sed -i.bak '/^ public function testTimestamp()$/,/^ }$/d' tests/well_known_test.php
sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/array_test.php
sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/map_field_test.php
sed -i.bak 's/PHPUnit_Framework_TestCase/\\PHPUnit\\Framework\\TestCase/g' tests/test_base.php
for t in "${tests[@]}"
do
remove_error_test tests/$t
done
cd tests
# Test A.1:
# proto set 1: use old version
# proto set 2 which may import protos in set 1: use old version
generate_proto $OLD_PROTOC $OLD_PROTOC
./test.sh
pushd ..
./vendor/bin/phpunit
popd
# Test A.2:
# proto set 1: use new version
# proto set 2 which may import protos in set 1: use old version
generate_proto $NEW_PROTOC $OLD_PROTOC
./test.sh
pushd ..
./vendor/bin/phpunit
popd
# Test A.3:
# proto set 1: use old version
# proto set 2 which may import protos in set 1: use new version
generate_proto $OLD_PROTOC $NEW_PROTOC
./test.sh
pushd ..
./vendor/bin/phpunit
popd

View File

@@ -1,18 +1,15 @@
#!/bin/bash
set -ex
set -e
cd $(dirname $0)/..
# Pull in dependencies.
git submodule update --init --recursive
# utf8_range has to live in the base third_party directory.
# We copy it into the ext/google/protobuf directory for the build
# (and for the release to PECL).
rm -rf ext/google/protobuf/third_party
mkdir -p ext/google/protobuf/third_party/utf8_range
cp -r ../third_party/utf8_range/* ext/google/protobuf/third_party/utf8_range
cp ../third_party/utf8_range/* ext/google/protobuf/third_party/utf8_range
echo "Copied utf8_range from ../third_party -> ext/google/protobuf/third_party"

View File

@@ -168,10 +168,6 @@ message ARRAY {
int32 a = 1;
}
message EmptyAnySerialization {
string a = 1;
}
message TestPackedMessage {
repeated int32 repeated_int32 = 90 [packed = true];
repeated int64 repeated_int64 = 91 [packed = true];