aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tools/proto_text
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <nobody@tensorflow.org>2016-04-21 10:08:01 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-04-21 11:13:27 -0700
commit3883578ebff0e8f901386d6f2b5870de517de4a1 (patch)
treef40fff6794ad2ddcb0e891b9965a53201feacc4c /tensorflow/tools/proto_text
parent52500e395d526ac932a6de46ecec1ad45082f43c (diff)
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: 120464266
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, 24 insertions, 36 deletions
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 1fc81b1358..880cb2efd8 100644
--- a/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc
+++ b/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc
@@ -243,12 +243,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:
@@ -490,19 +487,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(