diff options
-rw-r--r-- | tensorflow/core/BUILD | 19 | ||||
-rw-r--r-- | tensorflow/core/platform/default/build_config.bzl | 6 | ||||
-rw-r--r-- | tensorflow/core/platform/default/build_config/BUILD | 10 | ||||
-rw-r--r-- | tensorflow/tools/proto_text/BUILD | 4 | ||||
-rw-r--r-- | tensorflow/tools/proto_text/gen_proto_text_functions.cc | 3 | ||||
-rw-r--r-- | tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc | 40 |
6 files changed, 70 insertions, 12 deletions
diff --git a/tensorflow/core/BUILD b/tensorflow/core/BUILD index 8eb38d2104..75ec3135c8 100644 --- a/tensorflow/core/BUILD +++ b/tensorflow/core/BUILD @@ -73,6 +73,7 @@ load( "tf_proto_library", "tf_proto_library_cc", "tf_additional_lib_srcs", + "tf_additional_proto_srcs", "tf_additional_lib_deps", "tf_additional_stream_executor_srcs", "tf_additional_cupti_wrapper_deps", @@ -105,6 +106,24 @@ tf_proto_library( visibility = ["//visibility:public"], ) +# Minimal lib so that tools used for mobile compilation +# don't have to depend on lib/platformlib. +cc_library( + name = "lib_proto_parsing", + srcs = glob(tf_additional_proto_srcs()), + hdrs = [ + "platform/init_main.h", + "platform/logging.h", + "platform/macros.h", + "platform/platform.h", + "platform/protobuf.h", + "platform/types.h", + ], + deps = [ + "//tensorflow/core/platform/default/build_config:proto_parsing", + ], +) + cc_library( name = "lib", hdrs = [ diff --git a/tensorflow/core/platform/default/build_config.bzl b/tensorflow/core/platform/default/build_config.bzl index 515444d5d7..0459200858 100644 --- a/tensorflow/core/platform/default/build_config.bzl +++ b/tensorflow/core/platform/default/build_config.bzl @@ -97,6 +97,12 @@ def tf_additional_lib_srcs(): "platform/posix/*.cc", ] +def tf_additional_proto_srcs(): + return ["platform/default/integral_types.h", + "platform/default/logging.h", + "platform/default/logging.cc", + "platform/default/protobuf.h",] + def tf_additional_stream_executor_srcs(): return ["platform/default/stream_executor.h"] diff --git a/tensorflow/core/platform/default/build_config/BUILD b/tensorflow/core/platform/default/build_config/BUILD index 66e2c75934..1619be9201 100644 --- a/tensorflow/core/platform/default/build_config/BUILD +++ b/tensorflow/core/platform/default/build_config/BUILD @@ -43,6 +43,16 @@ cc_library( linkopts = ["-framework IOKit"], ) +# Minimal lib so that tools used for mobile compilation +# don't have to depend on platformlib. +cc_library( + name = "proto_parsing", + copts = tf_copts(), + deps = [ + "//tensorflow/core:protos_cc", + ], +) + cc_library( name = "platformlib", copts = tf_copts(), diff --git a/tensorflow/tools/proto_text/BUILD b/tensorflow/tools/proto_text/BUILD index 980a6d651e..af80d3a441 100644 --- a/tensorflow/tools/proto_text/BUILD +++ b/tensorflow/tools/proto_text/BUILD @@ -34,7 +34,7 @@ cc_binary( visibility = ["//tensorflow:internal"], deps = [ ":gen_proto_text_functions_lib", - "//tensorflow/core:lib", + "//tensorflow/core:lib_proto_parsing", ], ) @@ -50,7 +50,7 @@ cc_library( "//conditions:default": ["-lrt"], }), deps = [ - "//tensorflow/core:lib", + "//tensorflow/core:lib_proto_parsing", ], ) diff --git a/tensorflow/tools/proto_text/gen_proto_text_functions.cc b/tensorflow/tools/proto_text/gen_proto_text_functions.cc index cc664bb90b..17ab542a59 100644 --- a/tensorflow/tools/proto_text/gen_proto_text_functions.cc +++ b/tensorflow/tools/proto_text/gen_proto_text_functions.cc @@ -16,7 +16,6 @@ limitations under the License. #include <stdio.h> #include <set> -#include "tensorflow/core/platform/init_main.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/types.h" @@ -69,8 +68,6 @@ bool IsPlaceholderFile(const char* s) { // // This is meant to be invoked by a genrule. See BUILD for more information. 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"; 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 877269410f..ac5df77460 100644 --- a/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc +++ b/tensorflow/tools/proto_text/gen_proto_text_functions_lib.cc @@ -19,8 +19,7 @@ limitations under the License. #include <set> #include <unordered_set> -#include "tensorflow/core/lib/strings/str_util.h" -#include "tensorflow/core/lib/strings/strcat.h" +#include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/types.h" @@ -30,13 +29,24 @@ using ::tensorflow::protobuf::FieldDescriptor; using ::tensorflow::protobuf::FieldOptions; using ::tensorflow::protobuf::FileDescriptor; using ::tensorflow::protobuf::OneofDescriptor; -using ::tensorflow::strings::StrAppend; -using ::tensorflow::strings::StrCat; namespace tensorflow { namespace { +template <typename... Args> +string StrCat(const Args&... args) { + std::ostringstream s; + std::vector<int>{((s << args), 0)...}; + return s.str(); +} + +template <typename... Args> +string StrAppend(string* to_append, const Args&... args) { + *to_append += StrCat(args...); + return *to_append; +} + // Class used to generate the code for proto text functions. One of these should // be created for each FileDescriptor whose code should be generated. // @@ -142,8 +152,17 @@ class Generator { // Returns the prefix needed to reference objects defined in <fd>. E.g. // "::tensorflow::test". string GetPackageReferencePrefix(const FileDescriptor* fd) { - return StrCat("::", str_util::Join(str_util::Split(fd->package(), '.'), "::"), - "::"); + string result = "::"; + const string& package = fd->package(); + for (int i = 0; i < package.size(); ++i) { + if (package[i] == '.') { + result += "::"; + } else { + result += package[i]; + } + } + result += "::"; + return result; } // Returns the name of the class generated by proto to represent <d>. @@ -646,7 +665,14 @@ void Generator::AppendMessageFunctions(const Descriptor& md) { void Generator::AddNamespaceToCurrentSection(const string& package, bool open) { Print(); - const std::vector<string> parts = str_util::Split(package, '.'); + std::vector<string> parts = {""}; + for (int i = 0; i < package.size(); ++i) { + if (package[i] == '.') { + parts.resize(parts.size() + 1); + } else { + parts.back() += package[i]; + } + } if (open) { for (const auto& p : parts) { Print("namespace ", p, " {"); |