perfetto: migrate all descriptor header generation to build time

This CL migrates all remaning descriptor.h file generation to build time
instead of checking them in which reduces the number of binary files we
have checked into the Perfetto repo.

Moreover, it also introdcues a new template to handle generation of
descriptor headers instead of copy-pasting ugly actions.

Change-Id: I70b7498a6be2d4e09429739b13014ca2969c5e1f
diff --git a/Android.bp b/Android.bp
index a89d624..2e1741c 100644
--- a/Android.bp
+++ b/Android.bp
@@ -970,6 +970,7 @@
     "perfetto_protos_perfetto_trace_track_event_cpp_gen_headers",
     "perfetto_protos_perfetto_trace_track_event_zero_gen_headers",
     "perfetto_src_base_version_gen_h",
+    "perfetto_src_perfetto_cmd_gen_cc_config_descriptor",
     "perfetto_src_perfetto_cmd_protos_gen_headers",
   ],
   defaults: [
@@ -2883,6 +2884,21 @@
   ],
 }
 
+// GN: //protos/perfetto/config:perfetto_config_descriptor
+genrule {
+  name: "perfetto_protos_perfetto_config_perfetto_config_descriptor",
+  srcs: [
+    "protos/perfetto/config/perfetto_config.proto",
+  ],
+  tools: [
+    "aprotoc",
+  ],
+  cmd: "mkdir -p $(genDir)/external/perfetto/ && $(location aprotoc) --proto_path=external/perfetto --descriptor_set_out=$(out) $(in)",
+  out: [
+    "perfetto_protos_perfetto_config_perfetto_config_descriptor.bin",
+  ],
+}
+
 // GN: //protos/perfetto/config/power:cpp
 genrule {
   name: "perfetto_protos_perfetto_config_power_cpp_gen",
@@ -6836,6 +6852,21 @@
   ],
 }
 
+// GN: //src/perfetto_cmd:gen_cc_config_descriptor
+genrule {
+  name: "perfetto_src_perfetto_cmd_gen_cc_config_descriptor",
+  srcs: [
+    ":perfetto_protos_perfetto_config_perfetto_config_descriptor",
+  ],
+  cmd: "$(location tools/gen_cc_proto_descriptor.py) --gen_dir=$(genDir) --cpp_out=$(out) $(in)",
+  out: [
+    "src/perfetto_cmd/perfetto_config.descriptor.h",
+  ],
+  tool_files: [
+    "tools/gen_cc_proto_descriptor.py",
+  ],
+}
+
 // GN: //src/perfetto_cmd:perfetto_cmd
 filegroup {
   name: "perfetto_src_perfetto_cmd_perfetto_cmd",
@@ -7236,6 +7267,25 @@
   ],
 }
 
+// GN: //src/protozero:test_messages_descriptor
+genrule {
+  name: "perfetto_src_protozero_test_messages_descriptor",
+  srcs: [
+    "src/protozero/test/example_proto/extensions.proto",
+    "src/protozero/test/example_proto/library.proto",
+    "src/protozero/test/example_proto/library_internals/galaxies.proto",
+    "src/protozero/test/example_proto/test_messages.proto",
+    "src/protozero/test/example_proto/upper_import.proto",
+  ],
+  tools: [
+    "aprotoc",
+  ],
+  cmd: "mkdir -p $(genDir)/external/perfetto/ && $(location aprotoc) --proto_path=external/perfetto --descriptor_set_out=$(out) $(in)",
+  out: [
+    "perfetto_src_protozero_test_messages_descriptor.bin",
+  ],
+}
+
 // GN: //src/protozero:testing_messages_cpp
 genrule {
   name: "perfetto_src_protozero_testing_messages_cpp_gen",
@@ -7472,6 +7522,21 @@
   ],
 }
 
+// GN: //src/trace_processor:gen_cc_test_messages_descriptor
+genrule {
+  name: "perfetto_src_trace_processor_gen_cc_test_messages_descriptor",
+  srcs: [
+    ":perfetto_src_protozero_test_messages_descriptor",
+  ],
+  cmd: "$(location tools/gen_cc_proto_descriptor.py) --gen_dir=$(genDir) --cpp_out=$(out) $(in)",
+  out: [
+    "src/trace_processor/test_messages.descriptor.h",
+  ],
+  tool_files: [
+    "tools/gen_cc_proto_descriptor.py",
+  ],
+}
+
 // GN: //src/trace_processor/importers:common
 filegroup {
   name: "perfetto_src_trace_processor_importers_common",
@@ -9068,10 +9133,12 @@
     "perfetto_src_base_version_gen_h",
     "perfetto_src_ipc_test_messages_cpp_gen_headers",
     "perfetto_src_ipc_test_messages_ipc_gen_headers",
+    "perfetto_src_perfetto_cmd_gen_cc_config_descriptor",
     "perfetto_src_perfetto_cmd_protos_gen_headers",
     "perfetto_src_protozero_testing_messages_cpp_gen_headers",
     "perfetto_src_protozero_testing_messages_lite_gen_headers",
     "perfetto_src_protozero_testing_messages_zero_gen_headers",
+    "perfetto_src_trace_processor_gen_cc_test_messages_descriptor",
     "perfetto_src_trace_processor_importers_gen_cc_chrome_track_event_descriptor",
     "perfetto_src_trace_processor_importers_gen_cc_config_descriptor",
     "perfetto_src_trace_processor_importers_gen_cc_track_event_descriptor",