Skip to content

Commit

Permalink
Down integrate to GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Hao Nguyen committed May 3, 2019
1 parent fbe4ccc commit 1d4e959
Show file tree
Hide file tree
Showing 25 changed files with 657 additions and 289 deletions.
3 changes: 3 additions & 0 deletions cmake/libprotobuf-lite.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ set(libprotobuf_lite_files
${protobuf_source_dir}/src/google/protobuf/any_lite.cc
${protobuf_source_dir}/src/google/protobuf/arena.cc
${protobuf_source_dir}/src/google/protobuf/extension_set.cc
${protobuf_source_dir}/src/google/protobuf/generated_enum_util.cc
${protobuf_source_dir}/src/google/protobuf/generated_message_table_driven_lite.cc
${protobuf_source_dir}/src/google/protobuf/generated_message_util.cc
${protobuf_source_dir}/src/google/protobuf/implicit_weak_message.cc
${protobuf_source_dir}/src/google/protobuf/io/coded_stream.cc
${protobuf_source_dir}/src/google/protobuf/io/io_win32.cc
${protobuf_source_dir}/src/google/protobuf/io/strtod.cc
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.cc
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.cc
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.cc
${protobuf_source_dir}/src/google/protobuf/message_lite.cc
${protobuf_source_dir}/src/google/protobuf/parse_context.cc
Expand Down Expand Up @@ -36,6 +38,7 @@ set(libprotobuf_lite_includes
${protobuf_source_dir}/src/google/protobuf/io/coded_stream.h
${protobuf_source_dir}/src/google/protobuf/io/strtod.h
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream.h
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.h
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl_lite.h
${protobuf_source_dir}/src/google/protobuf/message_lite.h
${protobuf_source_dir}/src/google/protobuf/repeated_field.h
Expand Down
2 changes: 0 additions & 2 deletions cmake/libprotobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ set(libprotobuf_files
${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.cc
${protobuf_source_dir}/src/google/protobuf/io/printer.cc
${protobuf_source_dir}/src/google/protobuf/io/tokenizer.cc
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.cc
${protobuf_source_dir}/src/google/protobuf/map_field.cc
${protobuf_source_dir}/src/google/protobuf/message.cc
${protobuf_source_dir}/src/google/protobuf/reflection_ops.cc
Expand Down Expand Up @@ -72,7 +71,6 @@ set(libprotobuf_includes
${protobuf_source_dir}/src/google/protobuf/io/gzip_stream.h
${protobuf_source_dir}/src/google/protobuf/io/printer.h
${protobuf_source_dir}/src/google/protobuf/io/tokenizer.h
${protobuf_source_dir}/src/google/protobuf/io/zero_copy_stream_impl.h
${protobuf_source_dir}/src/google/protobuf/map_field.h
${protobuf_source_dir}/src/google/protobuf/message.h
${protobuf_source_dir}/src/google/protobuf/reflection_ops.h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ public void testAdd() {

assertTrue(
"Test is using a non-lite extension",
GeneratedMessage.GeneratedExtension.class.isAssignableFrom(
NonNestedExtension.nonNestedExtension.getClass()));
Extension.class.isAssignableFrom(NonNestedExtension.nonNestedExtension.getClass()));
assertNotNull(
"Extension is registered in masqueraded full registry",
fullRegistry2.findImmutableExtensionByName("protobuf_unittest.nonNestedExtension"));
Expand Down
108 changes: 67 additions & 41 deletions js/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function getClosureBuilderCommand(exportsFile, outputFile) {
exportsFile + ' > ' + outputFile;
}

gulp.task('dist', gulp.series(['genproto_wellknowntypes'], function (cb) {
gulp.task('dist', gulp.series(['genproto_wellknowntypes'], function(cb) {
// TODO(haberman): minify this more aggressively.
// Will require proper externs/exports.
exec(getClosureBuilderCommand('commonjs/export.js', 'google-protobuf.js'),
Expand Down Expand Up @@ -179,49 +179,75 @@ gulp.task('commonjs_testdeps', function (cb) {
});
});

gulp.task('make_commonjs_out', gulp.series(['dist', 'genproto_well_known_types_commonjs', 'genproto_group1_commonjs', 'genproto_group2_commonjs', 'genproto_commonjs_wellknowntypes', 'commonjs_asserts', 'commonjs_testdeps', 'genproto_group3_commonjs_strict'], function (cb) {
// TODO(haberman): minify this more aggressively.
// Will require proper externs/exports.
var cmd = "mkdir -p commonjs_out/binary && mkdir -p commonjs_out/test_node_modules && ";
function addTestFile(file) {
cmd += 'node commonjs/rewrite_tests_for_commonjs.js < ' + file +
' > commonjs_out/' + file + '&& ';
}

glob.sync('*_test.js').forEach(addTestFile);
glob.sync('binary/*_test.js').forEach(addTestFile);

exec(cmd +
'cp commonjs/jasmine.json commonjs_out/jasmine.json && ' +
'cp google-protobuf.js commonjs_out/test_node_modules && ' +
'cp commonjs/strict_test.js commonjs_out/strict_test.js &&' +
'cp commonjs/import_test.js commonjs_out/import_test.js',
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}));
gulp.task(
'make_commonjs_out',
gulp.series(
[
'dist', 'genproto_well_known_types_commonjs',
'genproto_group1_commonjs', 'genproto_group2_commonjs',
'genproto_commonjs_wellknowntypes', 'commonjs_asserts',
'commonjs_testdeps', 'genproto_group3_commonjs_strict'
],
function(cb) {
// TODO(haberman): minify this more aggressively.
// Will require proper externs/exports.
var cmd =
'mkdir -p commonjs_out/binary && mkdir -p commonjs_out/test_node_modules && ';
function addTestFile(file) {
cmd += 'node commonjs/rewrite_tests_for_commonjs.js < ' + file +
' > commonjs_out/' + file + '&& ';
}

gulp.task('deps', gulp.series(['genproto_well_known_types_closure', 'genproto_group1_closure', 'genproto_group2_closure'], function (cb) {
exec('./node_modules/google-closure-library/closure/bin/build/depswriter.py binary/arith.js binary/constants.js binary/decoder.js binary/encoder.js binary/reader.js binary/utils.js binary/writer.js debug.js map.js message.js node_loader.js test_bootstrap.js > deps.js',
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}));
glob.sync('*_test.js').forEach(addTestFile);
glob.sync('binary/*_test.js').forEach(addTestFile);

gulp.task('test_closure', gulp.series(['genproto_well_known_types_closure', 'genproto_group1_closure', 'genproto_group2_closure', 'deps'], function (cb) {
exec('JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine',
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}));
exec(
cmd + 'cp commonjs/jasmine.json commonjs_out/jasmine.json && ' +
'cp google-protobuf.js commonjs_out/test_node_modules && ' +
'cp commonjs/strict_test.js commonjs_out/strict_test.js &&' +
'cp commonjs/import_test.js commonjs_out/import_test.js',
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}));

gulp.task(
'deps',
gulp.series(
[
'genproto_well_known_types_closure', 'genproto_group1_closure',
'genproto_group2_closure'
],
function(cb) {
exec(
'./node_modules/google-closure-library/closure/bin/build/depswriter.py binary/arith.js binary/constants.js binary/decoder.js binary/encoder.js binary/reader.js binary/utils.js binary/writer.js debug.js map.js message.js node_loader.js test_bootstrap.js > deps.js',
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}));

gulp.task(
'test_closure',
gulp.series(
[
'genproto_well_known_types_closure', 'genproto_group1_closure',
'genproto_group2_closure', 'deps'
],
function(cb) {
exec(
'JASMINE_CONFIG_PATH=jasmine.json ./node_modules/.bin/jasmine',
function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
}));

gulp.task('test_commonjs', gulp.series(['make_commonjs_out'], function (cb) {
gulp.task('test_commonjs', gulp.series(['make_commonjs_out'], function(cb) {
exec('cd commonjs_out && JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=test_node_modules ../node_modules/.bin/jasmine',
function (err, stdout, stderr) {
console.log(stdout);
Expand Down
12 changes: 12 additions & 0 deletions python/google/protobuf/internal/text_format_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,18 @@ def testPrintFloatFormat(self, message_module):
'payload {{\n {0}\n {1}\n {2}\n {3}\n}}\n'.format(
*formatted_fields))

# Test default float_format has 8 valid digits.
message.payload.optional_float = 1.2345678912
message.payload.optional_double = 1.2345678912
formatted_fields = ['optional_float: 1.2345679',
'optional_double: 1.2345678912',
'repeated_float: -5642', 'repeated_double: 7.89e-5']
text_message = text_format.MessageToString(message)
self.CompareToGoldenText(
self.RemoveRedundantZeros(text_message),
'payload {{\n {0}\n {1}\n {2}\n {3}\n}}\n'.format(
*formatted_fields))

def testMessageToString(self, message_module):
message = message_module.ForeignMessage()
message.c = 123
Expand Down
43 changes: 24 additions & 19 deletions python/google/protobuf/text_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def MessageToString(message,
# type: (...) -> str
"""Convert protobuf message to text format.
Floating point values can be formatted compactly with 15 digits of
Double values can be formatted compactly with 15 digits of
precision (which is the most that IEEE 754 "double" can guarantee)
using float_format='.15g'. To ensure that converting to text and back to a
proto will result in an identical value, float_format='.17g' should be used.
using double_format='.15g'. To ensure that converting to text and back to a
proto will result in an identical value, double_format='.17g' should be used.
Args:
message: The protocol buffers message.
Expand All @@ -153,11 +153,12 @@ def MessageToString(message,
determined by the extension number. By default, use the field number
order.
float_format: If set, use this to specify float field formatting
(per the "Format Specification Mini-Language"); otherwise, str() is used.
Also affect double field if double_format is not set.
(per the "Format Specification Mini-Language"); otherwise, 8 valid digits
is used (default '.8g'). Also affect double field if double_format is
not set but float_format is set.
double_format: If set, use this to specify double field formatting
(per the "Format Specification Mini-Language"); otherwise, float_format
is used.
(per the "Format Specification Mini-Language"); if it is not set but
float_format is set, use float_format. Otherwise, use str()
use_field_number: If True, print field numbers instead of names.
descriptor_pool: A DescriptorPool used to resolve Any types.
indent: The initial indent level, in terms of spaces, for pretty print.
Expand Down Expand Up @@ -322,10 +323,10 @@ def __init__(self,
print_unknown_fields=False):
"""Initialize the Printer.
Floating point values can be formatted compactly with 15 digits of
precision (which is the most that IEEE 754 "double" can guarantee)
using float_format='.15g'. To ensure that converting to text and back to a
proto will result in an identical value, float_format='.17g' should be used.
Double values can be formatted compactly with 15 digits of precision
(which is the most that IEEE 754 "double" can guarantee) using
double_format='.15g'. To ensure that converting to text and back to a proto
will result in an identical value, double_format='.17g' should be used.
Args:
out: To record the text format result.
Expand All @@ -340,11 +341,13 @@ def __init__(self,
use_index_order: If True, print fields of a proto message using the order
defined in source code instead of the field number. By default, use the
field number order.
float_format: If set, use this to specify floating point number formatting
(per the "Format Specification Mini-Language"); otherwise, str() is
used. Also affect double field if double_format is not set.
double_format: If set, use this to specify double field formatting;
otherwise, float_format is used.
float_format: If set, use this to specify float field formatting
(per the "Format Specification Mini-Language"); otherwise, 8 valid
digits is used (default '.8g'). Also affect double field if
double_format is not set but float_format is set.
double_format: If set, use this to specify double field formatting
(per the "Format Specification Mini-Language"); if it is not set but
float_format is set, use float_format. Otherwise, str() is used.
use_field_number: If True, print field numbers instead of names.
descriptor_pool: A DescriptorPool used to resolve Any types.
message_formatter: A function(message, indent, as_one_line): unicode|None
Expand Down Expand Up @@ -589,9 +592,11 @@ def PrintFieldValue(self, field, value):
out.write('true')
else:
out.write('false')
elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT and
self.float_format is not None):
out.write('{1:{0}}'.format(self.float_format, value))
elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_FLOAT:
if self.float_format is not None:
out.write('{1:{0}}'.format(self.float_format, value))
else:
out.write(str(float(format(value, '.8g'))))
elif (field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_DOUBLE and
self.double_format is not None):
out.write('{1:{0}}'.format(self.double_format, value))
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ libprotobuf_lite_la_SOURCES = \
google/protobuf/any_lite.cc \
google/protobuf/arena.cc \
google/protobuf/extension_set.cc \
google/protobuf/generated_enum_util.cc \
google/protobuf/generated_message_util.cc \
google/protobuf/generated_message_table_driven_lite.h \
google/protobuf/generated_message_table_driven_lite.cc \
Expand All @@ -214,6 +215,7 @@ libprotobuf_lite_la_SOURCES = \
google/protobuf/io/coded_stream_inl.h \
google/protobuf/io/strtod.cc \
google/protobuf/io/zero_copy_stream.cc \
google/protobuf/io/zero_copy_stream_impl.cc \
google/protobuf/io/zero_copy_stream_impl_lite.cc

libprotobuf_la_LIBADD = $(PTHREAD_LIBS) $(LIBATOMIC_LIBS)
Expand Down Expand Up @@ -258,7 +260,6 @@ libprotobuf_la_SOURCES = \
google/protobuf/io/gzip_stream.cc \
google/protobuf/io/printer.cc \
google/protobuf/io/tokenizer.cc \
google/protobuf/io/zero_copy_stream_impl.cc \
google/protobuf/compiler/importer.cc \
google/protobuf/compiler/parser.cc \
google/protobuf/util/delimited_message_util.cc \
Expand Down
Loading

0 comments on commit 1d4e959

Please sign in to comment.