diff options
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/cpp_generator.cc | 7 | ||||
-rw-r--r-- | src/compiler/generator_helpers.h | 3 | ||||
-rw-r--r-- | src/compiler/node_generator.cc | 14 |
3 files changed, 17 insertions, 7 deletions
diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index e2f127094a..2288ba4163 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -73,9 +73,10 @@ void PrintIncludes(Printer *printer, const std::vector<grpc::string>& headers, c vars["l"] = params.use_system_headers ? '<' : '"'; vars["r"] = params.use_system_headers ? '>' : '"'; - if (!params.grpc_search_path.empty()) { - vars["l"] += params.grpc_search_path; - if (params.grpc_search_path.back() != '/') { + auto& s = params.grpc_search_path; + if (!s.empty()) { + vars["l"] += s; + if (s[s.size()-1] != '/') { vars["l"] += '/'; } } diff --git a/src/compiler/generator_helpers.h b/src/compiler/generator_helpers.h index 53391bc41a..9a88c2bfcc 100644 --- a/src/compiler/generator_helpers.h +++ b/src/compiler/generator_helpers.h @@ -253,7 +253,8 @@ inline void GetComment(const grpc::protobuf::FileDescriptor *desc, inline grpc::string GenerateCommentsWithPrefix( const std::vector<grpc::string> &in, const grpc::string &prefix) { std::ostringstream oss; - for (const grpc::string &elem : in) { + for (auto it = in.begin(); it != in.end(); it++) { + const grpc::string& elem = *it; if (elem.empty()) { oss << prefix << "\n"; } else if (elem[0] == ' ') { diff --git a/src/compiler/node_generator.cc b/src/compiler/node_generator.cc index 986b97c26e..1fe090d17a 100644 --- a/src/compiler/node_generator.cc +++ b/src/compiler/node_generator.cc @@ -74,8 +74,16 @@ grpc::string GetJSMessageFilename(const grpc::string& filename) { // Given a filename like foo/bar/baz.proto, returns the root directory // path ../../ -grpc::string GetRootPath(const grpc::string& filename) { - size_t slashes = std::count(filename.begin(), filename.end(), '/'); +grpc::string GetRootPath(const grpc::string& from_filename, + const grpc::string& to_filename) { + if (to_filename.find("google/protobuf") == 0) { + // Well-known types (.proto files in the google/protobuf directory) are + // assumed to come from the 'google-protobuf' npm package. We may want to + // generalize this exception later by letting others put generated code in + // their own npm packages. + return "google-protobuf/"; + } + size_t slashes = std::count(from_filename.begin(), from_filename.end(), '/'); if (slashes == 0) { return "./"; } @@ -90,7 +98,7 @@ grpc::string GetRootPath(const grpc::string& filename) { // from_file, assuming that both paths are relative to the same directory grpc::string GetRelativePath(const grpc::string& from_file, const grpc::string& to_file) { - return GetRootPath(from_file) + to_file; + return GetRootPath(from_file, to_file) + to_file; } /* Finds all message types used in all services in the file, and returns them |