Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc

Issue 2201393002: Tracing V2: Import support for protobuf plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc
diff --git a/components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc b/components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc
index 12a32ab3783581e3665d5da37145670dc847255d..fd034b6285609834dc8b7c79c8e8bb29ae051094 100644
--- a/components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc
+++ b/components/tracing/tools/proto_zero_plugin/proto_zero_generator.cc
@@ -33,6 +33,10 @@ using google::protobuf::UpperString;
namespace {
+inline std::string ProtoStubName(const FileDescriptor* proto) {
+ return StripSuffixString(proto->name(), ".proto") + ".pbzero";
+}
+
class GeneratorJob {
public:
GeneratorJob(const FileDescriptor *file,
@@ -151,7 +155,7 @@ class GeneratorJob {
"#define $guard$\n\n"
"#include <stddef.h>\n"
"#include <stdint.h>\n\n"
- "#include \"components/tracing/core/proto_zero_message.h\"\n\n",
+ "#include \"components/tracing/core/proto_zero_message.h\"\n",
"greeting", greeting,
"guard", guard);
stub_cc_->Print(
@@ -159,6 +163,29 @@ class GeneratorJob {
"// This file intentionally left blank.\n",
"greeting", greeting);
+ // Print dependencies.
+ if (source_->weak_dependency_count() > 0)
+ Abort("Weak imports are not supported.");
+ for (int i = 0; i < source_->dependency_count(); ++i) {
+ const FileDescriptor* dependency = source_->dependency(i);
+ if (dependency->package() != package_)
+ Abort("Imported proto must be in the same package.");
Primiano Tucci (use gerrit) 2016/08/03 15:36:28 out of curiosity, why?
kraynov 2016/08/04 12:03:54 It would be complex to deal with namespaces in thi
+
+ // Dependency name could contatin slashes but importing from upper-level
+ // directories is not possible anyway since build system process each
+ // proto file individually. Hence proto lookup path always equal to the
+ // directory where particular proto file is located and protoc does not
+ // allow reference to upper directory (aka ..) in import path.
+ //
+ // Laconiacally said:
Primiano Tucci (use gerrit) 2016/08/03 15:36:28 nit: s/Laconiacally/Laconically/
+ // - source_->name() may never have slashes,
+ // - dependency->name() may have slashes but always reffers to inner path.
+ stub_h_->Print(
+ "#include \"$name$.h\"\n",
+ "name", ProtoStubName(dependency));
+ }
+ stub_h_->Print("\n");
+
// Print namespaces.
for (const std::string& ns : namespaces_)
stub_h_->Print("namespace $ns$ {\n", "ns", ns);
@@ -402,13 +429,10 @@ bool ProtoZeroGenerator::Generate(const FileDescriptor* file,
GeneratorContext* context,
std::string* error) const {
- const std::string proto_stubs_name =
- StripSuffixString(file->name(), ".proto") + ".pbzero";
-
const std::unique_ptr<ZeroCopyOutputStream> stub_h_file_stream(
- context->Open(proto_stubs_name + ".h"));
+ context->Open(ProtoStubName(file) + ".h"));
const std::unique_ptr<ZeroCopyOutputStream> stub_cc_file_stream(
- context->Open(proto_stubs_name + ".cc"));
+ context->Open(ProtoStubName(file) + ".cc"));
// Variables are delimited by $.
Printer stub_h_printer(stub_h_file_stream.get(), '$');

Powered by Google App Engine
This is Rietveld 408576698