aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tools/proto_text
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <nobody@tensorflow.org>2016-04-19 16:36:49 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-04-19 17:44:41 -0700
commit43fc42b7052b2bc47040ad85049290387d6dc2e8 (patch)
tree255bbaeff0be22e1ab8acf17c78de923d9ef3cd0 /tensorflow/tools/proto_text
parente8beb7e6436c2d8f511f53749733b7762ae3d896 (diff)
Rollback of "Change tensorflow code to use proto_text for DebugString andS hortDebugString"
calls, for call sites that are needed on android. Also changed protobuf.h to use MessageLite. Change: 120289807
Diffstat (limited to 'tensorflow/tools/proto_text')
-rw-r--r--tensorflow/tools/proto_text/BUILD16
-rw-r--r--tensorflow/tools/proto_text/gen_proto_text_functions.cc17
-rw-r--r--tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc27
3 files changed, 36 insertions, 24 deletions
diff --git a/tensorflow/tools/proto_text/BUILD b/tensorflow/tools/proto_text/BUILD
index 5c185e54e5..c677721672 100644
--- a/tensorflow/tools/proto_text/BUILD
+++ b/tensorflow/tools/proto_text/BUILD
@@ -14,11 +14,6 @@ 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",
@@ -49,10 +44,17 @@ tf_proto_library_cc(
srcs = ["test.proto"],
)
-tf_generate_proto_text_sources(
+genrule(
name = "test_proto_text_srcs",
srcs = ["test.proto"],
- srcs_relative_dir = "tensorflow/tools/proto_text/",
+ 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"],
)
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 ce8e2bcd3e..604ae432cf 100644
--- a/tensorflow/tools/proto_text/gen_proto_text_functions.cc
+++ b/tensorflow/tools/proto_text/gen_proto_text_functions.cc
@@ -53,13 +53,12 @@ static const char kTensorflowHeaderPrefix[] = "";
int MainImpl(int argc, char** argv) {
tensorflow::port::InitMain(argv[0], &argc, &argv);
- if (argc < 4) {
- LOG(ERROR) << "Pass output path, relative path, and at least proto file";
+ if (argc < 3) {
+ LOG(ERROR) << "Pass output 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;
@@ -71,14 +70,16 @@ int MainImpl(int argc, char** argv) {
tensorflow::protobuf::compiler::Importer importer(&source_tree,
&crash_on_error);
- for (int i = 3; i < argc; i++) {
+ for (int i = 2; i < argc; i++) {
const string proto_path = argv[i];
const tensorflow::protobuf::FileDescriptor* fd =
importer.Import(proto_path);
- 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());
+ 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 auto code =
tensorflow::GetProtoTextFunctionCode(*fd, kTensorflowHeaderPrefix);
@@ -98,7 +99,7 @@ int MainImpl(int argc, char** argv) {
data = code.cc;
}
- const string path = output_root + "/" + proto_path_no_suffix + suffix;
+ const string path = output_root + "/" + proto_name + 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 f3291a6847..b196fd23f7 100644
--- a/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc
+++ b/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc
@@ -240,9 +240,12 @@ 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(), "\", ProtobufStringToString(", field_expr,
- "));");
+ "(\"", field.name(), "\", ", str_expr, ");");
break;
}
case FieldDescriptor::CPPTYPE_ENUM:
@@ -468,13 +471,19 @@ void Generator::AppendParseMessageFunction(const Descriptor& md) {
Print(" scanner, true, open_char == '{', ", mutable_value_expr,
")) return false;");
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING) {
- Print("string str_value;");
- Print(
- "if (!parsed_colon || "
- "!::tensorflow::strings::ProtoParseStringLiteralFromScanner(");
- Print(" scanner, &str_value)) return false;");
- Print("SetProtobufStringSwapAllowed(&str_value, ", mutable_value_expr,
- ");");
+ 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;");
+ }
} else if (field->cpp_type() == FieldDescriptor::CPPTYPE_ENUM) {
Print("StringPiece value;");
Print(