From 50d0241b62b2dc924856248dedf00deb65728c3e Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Tue, 19 Apr 2016 08:31:43 -0800 Subject: Change tensorflow code to use proto_text for DebugString and ShortDebugString calls, for call sites that are needed on android. Also changed protobuf.h to use MessageLite. Change: 120236583 --- tensorflow/tools/proto_text/BUILD | 16 ++++++------- .../tools/proto_text/gen_proto_text_functions.cc | 17 +++++++------- .../proto_text/gen_proto_text_functions_lib.cc | 27 ++++++++-------------- 3 files changed, 24 insertions(+), 36 deletions(-) (limited to 'tensorflow/tools/proto_text') diff --git a/tensorflow/tools/proto_text/BUILD b/tensorflow/tools/proto_text/BUILD index c677721672..5c185e54e5 100644 --- a/tensorflow/tools/proto_text/BUILD +++ b/tensorflow/tools/proto_text/BUILD @@ -14,6 +14,11 @@ licenses(["notice"]) # Apache 2.0 exports_files(["LICENSE"]) +load( + "//tensorflow:tensorflow.bzl", + "tf_generate_proto_text_sources", +) + # For platform specific build config load( "//tensorflow/core:platform/default/build_config.bzl", @@ -44,17 +49,10 @@ tf_proto_library_cc( srcs = ["test.proto"], ) -genrule( +tf_generate_proto_text_sources( name = "test_proto_text_srcs", srcs = ["test.proto"], - outs = [ - "test.pb_text-impl.h", - "test.pb_text.h", - "test.pb_text.cc", - ], - cmd = "$(location :gen_proto_text_functions) " + - "$(@D) $(location test.proto)", - tools = [":gen_proto_text_functions"], + srcs_relative_dir = "tensorflow/tools/proto_text/", ) cc_test( diff --git a/tensorflow/tools/proto_text/gen_proto_text_functions.cc b/tensorflow/tools/proto_text/gen_proto_text_functions.cc index 604ae432cf..ce8e2bcd3e 100644 --- a/tensorflow/tools/proto_text/gen_proto_text_functions.cc +++ b/tensorflow/tools/proto_text/gen_proto_text_functions.cc @@ -53,12 +53,13 @@ static const char kTensorflowHeaderPrefix[] = ""; int MainImpl(int argc, char** argv) { tensorflow::port::InitMain(argv[0], &argc, &argv); - if (argc < 3) { - LOG(ERROR) << "Pass output path and at least proto file"; + if (argc < 4) { + LOG(ERROR) << "Pass output path, relative path, and at least proto file"; return -1; } const string output_root = argv[1]; + const string relative_path = kTensorflowHeaderPrefix + string(argv[2]); tensorflow::protobuf::compiler::DiskSourceTree source_tree; @@ -70,16 +71,14 @@ int MainImpl(int argc, char** argv) { tensorflow::protobuf::compiler::Importer importer(&source_tree, &crash_on_error); - for (int i = 2; i < argc; i++) { + for (int i = 3; i < argc; i++) { const string proto_path = argv[i]; const tensorflow::protobuf::FileDescriptor* fd = importer.Import(proto_path); - string proto_name = proto_path; - int index = proto_name.find_last_of("/"); - if (index != string::npos) proto_name = proto_name.substr(index + 1); - index = proto_name.find_last_of("."); - if (index != string::npos) proto_name = proto_name.substr(0, index); + const int index = proto_path.find_last_of("."); + string proto_path_no_suffix = proto_path.substr(0, index); + proto_path_no_suffix = proto_path_no_suffix.substr(relative_path.size()); const auto code = tensorflow::GetProtoTextFunctionCode(*fd, kTensorflowHeaderPrefix); @@ -99,7 +98,7 @@ int MainImpl(int argc, char** argv) { data = code.cc; } - const string path = output_root + "/" + proto_name + suffix; + const string path = output_root + "/" + proto_path_no_suffix + suffix; FILE* f = fopen(path.c_str(), "w"); if (fwrite(data.c_str(), 1, data.size(), f) != data.size()) { return -1; diff --git a/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc b/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc index b196fd23f7..f3291a6847 100644 --- a/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc +++ b/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc @@ -240,12 +240,9 @@ void Generator::AppendFieldValueAppend(const FieldDescriptor& field, CHECK(ctype == FieldOptions::CORD || ctype == FieldOptions::STRING) << "Unsupported ctype " << ctype; - string str_expr = field_expr; - if (ctype == FieldOptions::CORD) { - str_expr = StrCat("(", field_expr, ").ToString()"); - } Print("o->", omit_default ? "AppendStringIfNotEmpty" : "AppendString", - "(\"", field.name(), "\", ", str_expr, ");"); + "(\"", field.name(), "\", ProtobufStringToString(", field_expr, + "));"); break; } case FieldDescriptor::CPPTYPE_ENUM: @@ -471,19 +468,13 @@ void Generator::AppendParseMessageFunction(const Descriptor& md) { Print(" scanner, true, open_char == '{', ", mutable_value_expr, ")) return false;"); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) { - if (field->options().ctype() == FieldOptions::CORD) { - Print("string str_value;"); - Print( - "if (!parsed_colon || " - "!::tensorflow::strings::ProtoParseStringLiteralFromScanner("); - Print(" scanner, &str_value)) return false;"); - Print(mutable_value_expr, "->CopyFrom(str_value);"); - } else { - Print( - "if (!parsed_colon || " - "!::tensorflow::strings::ProtoParseStringLiteralFromScanner("); - Print(" scanner, ", mutable_value_expr, ")) return false;"); - } + Print("string str_value;"); + Print( + "if (!parsed_colon || " + "!::tensorflow::strings::ProtoParseStringLiteralFromScanner("); + Print(" scanner, &str_value)) return false;"); + Print("SetProtobufStringSwapAllowed(&str_value, ", mutable_value_expr, + ");"); } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) { Print("StringPiece value;"); Print( -- cgit v1.2.3