MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / MainImpl

Function MainImpl

tensorflow/tools/proto_text/gen_proto_text_functions.cc:71–149  ·  view source on GitHub ↗

Main program to take input protos and write output pb_text source files that contain generated proto text input and output functions. Main expects: - First argument is output path - Second argument is the relative path of the protos to the root. E.g., for protos built by a rule in tensorflow/core, this will be tensorflow/core. - Then any number of source proto file names, plus one source name mus

Source from the content-addressed store, hash-verified

69//
70// This is meant to be invoked by a genrule. See BUILD for more information.
71int MainImpl(int argc, char** argv) {
72 if (argc < 4) {
73 LOG(ERROR) << "Pass output path, relative path, and at least proto file";
74 return -1;
75 }
76
77 const string output_root = argv[1];
78 const string output_relative_path = kTensorFlowHeaderPrefix + string(argv[2]);
79
80 string src_relative_path;
81 bool has_placeholder = false;
82 for (int i = 3; i < argc; ++i) {
83 if (IsPlaceholderFile(argv[i])) {
84 const string s(argv[i]);
85 src_relative_path = s.substr(0, s.size() - strlen(kPlaceholderFile));
86 has_placeholder = true;
87 }
88 }
89 if (!has_placeholder) {
90 LOG(ERROR) << kPlaceholderFile << " must be passed";
91 return -1;
92 }
93
94 tensorflow::protobuf::compiler::DiskSourceTree source_tree;
95
96 source_tree.MapPath("", src_relative_path.empty() ? "." : src_relative_path);
97 CrashOnErrorCollector crash_on_error;
98 tensorflow::protobuf::compiler::Importer importer(&source_tree,
99 &crash_on_error);
100
101 for (int i = 3; i < argc; i++) {
102 if (IsPlaceholderFile(argv[i])) continue;
103 const string proto_path = string(argv[i]).substr(src_relative_path.size());
104
105 const tensorflow::protobuf::FileDescriptor* fd =
106 importer.Import(proto_path);
107
108 const int index = proto_path.find_last_of(".");
109 string proto_path_no_suffix = proto_path.substr(0, index);
110
111 proto_path_no_suffix =
112 proto_path_no_suffix.substr(output_relative_path.size());
113
114 const auto code =
115 tensorflow::GetProtoTextFunctionCode(*fd, kTensorFlowHeaderPrefix);
116
117 // Three passes, one for each output file.
118 for (int pass = 0; pass < 3; ++pass) {
119 string suffix;
120 string data;
121 if (pass == 0) {
122 suffix = ".pb_text.h";
123 data = code.header;
124 } else if (pass == 1) {
125 suffix = ".pb_text-impl.h";
126 data = code.header_impl;
127 } else {
128 suffix = ".pb_text.cc";

Callers 1

mainFunction · 0.85

Calls 7

IsPlaceholderFileFunction · 0.85
GetProtoTextFunctionCodeFunction · 0.85
c_strMethod · 0.80
fopenFunction · 0.50
sizeMethod · 0.45
emptyMethod · 0.45
ImportMethod · 0.45

Tested by

no test coverage detected