Enable embedders to include Perfetto protos

This meant:
* Generating pbzero and pblite in the same paths,
  to avoid search path magic or having to specify
  "pbzero" or "pblite" in the include path.
* (From Primiano) Prevent generation of all Perfetto .py proto files to avoid naming conflicts.
* Adding the root of the perfetto generated files to the search path to
  let Perfetto protos include headers from other protos.


Change-Id: Ie90cbbf6cf8233d94abd324e3c07f15a0987d047
diff --git a/BUILD.gn b/BUILD.gn
index 782f9a5..a64b365 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -28,7 +28,6 @@
     ":perfetto_tests",
     "src/ipc/protoc_plugin:ipc_plugin($host_toolchain)",
     "src/protozero/protoc_plugin($host_toolchain)",
-    "tools:protoc_helper",
     "tools/ftrace_proto_gen:ftrace_proto_gen",
     "tools/proto_to_cpp",
     "tools/trace_to_text",
@@ -41,6 +40,7 @@
       ":traced_probes",
       "src/ftrace_reader:ftrace_reader_integrationtests",
       "test/configs",
+      "tools:protoc_helper",
     ]
   }
 }
@@ -141,7 +141,10 @@
   }
 } else {
   group("lib") {
-    public_configs = [ "gn:public_config" ]
+    public_configs = [
+      "gn:public_config",
+      "protos:public_config",
+    ]
     deps = [
       "src/tracing",
     ]
diff --git a/gn/ipc_library.gni b/gn/ipc_library.gni
index db4d72c..c555dd4 100644
--- a/gn/ipc_library.gni
+++ b/gn/ipc_library.gni
@@ -25,6 +25,7 @@
   proto_library(target_name) {
     perfetto_root_path = invoker.perfetto_root_path
 
+    generate_python = false
     generator_plugin_label =
         perfetto_root_path + "src/ipc/protoc_plugin:ipc_plugin"
     generator_plugin_suffix = ".ipc"
@@ -35,7 +36,7 @@
       deps += invoker.deps
     }
 
-    proto_out_dir = "protos_lite"
+    proto_out_dir = perfetto_root_path
     forward_variables_from(invoker,
                            [
                              "defines",
diff --git a/gn/standalone/proto_library.gni b/gn/standalone/proto_library.gni
index d02f7be..1401cc9 100644
--- a/gn/standalone/proto_library.gni
+++ b/gn/standalone/proto_library.gni
@@ -24,9 +24,12 @@
   assert(defined(invoker.proto_out_dir),
          "proto_out_dir must be explicitly defined")
   proto_out_dir = invoker.proto_out_dir
-  assert(proto_out_dir == "protos_zero" || proto_out_dir == "protos_lite" ||
-             proto_out_dir == "protos_full",
-         "proto_out must be either 'proto_zero', 'proto_lite' or 'proto_full'")
+
+  # We don't support generate_python in the standalone build, but still must
+  # check that the caller sets this to false. This is because when building in
+  # the chromium tree, chromium's proto_library.gni in chrome (!= this) defaults
+  # generate_python = true.
+  assert(defined(invoker.generate_python) && !invoker.generate_python)
 
   # If false will not generate the default .pb.{cc,h} files. Used for custom
   # codegen plugins.
diff --git a/protos/BUILD.gn b/protos/BUILD.gn
index 36c3d58..3d5323f 100644
--- a/protos/BUILD.gn
+++ b/protos/BUILD.gn
@@ -16,6 +16,14 @@
 import("../gn/perfetto.gni")
 import("../gn/proto_library.gni")
 
+config("public_config") {
+  include_dirs = [
+    # The below are needed due to generated protobuf headers including other
+    # headers with a path relative to the perfetto root.
+    "${root_gen_dir}/${perfetto_root_path}",
+  ]
+}
+
 proto_sources = [
   "test_event.proto",
   "trace_packet.proto",
@@ -29,7 +37,7 @@
   ]
   sources = proto_sources
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_zero"
+  proto_out_dir = perfetto_root_path
   generator_plugin_options = "wrapper_namespace=pbzero"
 }
 
@@ -41,5 +49,6 @@
   ]
   sources = proto_sources
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_lite"
+  proto_out_dir = perfetto_root_path
+  generate_python = false
 }
diff --git a/protos/ftrace/BUILD.gn b/protos/ftrace/BUILD.gn
index 8104f51..23538fd 100644
--- a/protos/ftrace/BUILD.gn
+++ b/protos/ftrace/BUILD.gn
@@ -19,12 +19,13 @@
 proto_library("lite") {
   sources = ftrace_proto_names
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_lite"
+  proto_out_dir = perfetto_root_path
+  generate_python = false
 }
 
 protozero_library("zero") {
   sources = ftrace_proto_names
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_zero"
+  proto_out_dir = perfetto_root_path
   generator_plugin_options = "wrapper_namespace=pbzero"
 }
diff --git a/protos/tracing_service/BUILD.gn b/protos/tracing_service/BUILD.gn
index da47ab8..c570e3f 100644
--- a/protos/tracing_service/BUILD.gn
+++ b/protos/tracing_service/BUILD.gn
@@ -29,7 +29,8 @@
 
 proto_library("lite") {
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_lite"
+  proto_out_dir = perfetto_root_path
+  generate_python = false
   sources = [
     "data_source_config.proto",
     "data_source_descriptor.proto",
diff --git a/src/ftrace_reader/BUILD.gn b/src/ftrace_reader/BUILD.gn
index b8b8cea..c4c45d1 100644
--- a/src/ftrace_reader/BUILD.gn
+++ b/src/ftrace_reader/BUILD.gn
@@ -53,14 +53,15 @@
 protozero_library("ftrace_reader_test_messages_zero") {
   sources = ftrace_reader_test_proto_sources
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_zero"
+  proto_out_dir = perfetto_root_path
   generator_plugin_options = "wrapper_namespace=pbzero"
 }
 
 proto_library("ftrace_reader_test_messages_lite") {
   sources = ftrace_reader_test_proto_sources
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_lite"
+  proto_out_dir = perfetto_root_path
+  generate_python = false
 }
 
 # These tests require access to a real ftrace implementation and must
diff --git a/src/ipc/BUILD.gn b/src/ipc/BUILD.gn
index c65e270..bb6ad6a 100644
--- a/src/ipc/BUILD.gn
+++ b/src/ipc/BUILD.gn
@@ -64,8 +64,9 @@
   sources = [
     "wire_protocol.proto",
   ]
+  generate_python = false
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_lite"
+  proto_out_dir = perfetto_root_path
 }
 
 ipc_library("test_messages") {
diff --git a/src/protozero/BUILD.gn b/src/protozero/BUILD.gn
index 067b7a1..1bf0cb9 100644
--- a/src/protozero/BUILD.gn
+++ b/src/protozero/BUILD.gn
@@ -67,12 +67,13 @@
 protozero_library("testing_messages_zero") {
   sources = testing_proto_sources
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_zero"
+  proto_out_dir = perfetto_root_path
   generator_plugin_options = "wrapper_namespace=pbzero"
 }
 
 proto_library("testing_messages_lite") {
   sources = testing_proto_sources
   proto_in_dir = perfetto_root_path
-  proto_out_dir = "protos_lite"
+  proto_out_dir = perfetto_root_path
+  generate_python = false
 }
diff --git a/src/protozero/protozero_library.gni b/src/protozero/protozero_library.gni
index 2894490..df140f7 100644
--- a/src/protozero/protozero_library.gni
+++ b/src/protozero/protozero_library.gni
@@ -31,6 +31,7 @@
     generate_cc = false
     generator_plugin_label = perfetto_root_path + "src/protozero/protoc_plugin"
     generator_plugin_suffix = ".pbzero"
+    generate_python = false
 
     if (defined(invoker.deps)) {
       deps = invoker.deps
diff --git a/src/traced/perfetto_cmd/BUILD.gn b/src/traced/perfetto_cmd/BUILD.gn
index 832526c..8474a3b 100644
--- a/src/traced/perfetto_cmd/BUILD.gn
+++ b/src/traced/perfetto_cmd/BUILD.gn
@@ -19,6 +19,7 @@
   deps = [
     "../../../gn:default_deps",
     "../../../protos:lite",
+    "../../../protos/tracing_service:lite",
     "../../base",
     "../../protozero",
     "../../tracing:ipc",
diff --git a/src/tracing/BUILD.gn b/src/tracing/BUILD.gn
index 988d829..78c446d 100644
--- a/src/tracing/BUILD.gn
+++ b/src/tracing/BUILD.gn
@@ -19,11 +19,12 @@
 source_set("tracing") {
   public_deps = [
     "../../include/perfetto/tracing/core",
+    "../../protos:lite",
+    "../../protos:zero",
   ]
   deps = [
     "../../gn:default_deps",
-    "../../protos:lite",
-    "../../protos:zero",
+    "../../protos/tracing_service:lite",
     "../base",
   ]
   sources = [