perfetto: change gen_andorid_bp to use static libs for host tools

Also add a static_executable flag for trace_processor_shell - both of
these are required for using trace processor as a standalone binary in
the Android tree.

Change-Id: Ie313b5a234e5aade94107ef9de3c17f8c4345e3c
diff --git a/Android.bp b/Android.bp
index 7991095..89931cb 100644
--- a/Android.bp
+++ b/Android.bp
@@ -245,7 +245,7 @@
     ":perfetto_src_base_base",
     "src/ipc/protoc_plugin/ipc_plugin.cc",
   ],
-  shared_libs: [
+  static_libs: [
     "libprotoc",
   ],
   defaults: [
@@ -4373,7 +4373,7 @@
     ":perfetto_src_base_base",
     "src/protozero/protoc_plugin/cppgen_plugin.cc",
   ],
-  shared_libs: [
+  static_libs: [
     "libprotoc",
   ],
   defaults: [
@@ -5551,7 +5551,7 @@
     ":perfetto_src_base_base",
     "src/protozero/protoc_plugin/protozero_plugin.cc",
   ],
-  shared_libs: [
+  static_libs: [
     "libprotoc",
   ],
   defaults: [
@@ -5611,12 +5611,10 @@
     "src/trace_processor/proto_to_json.cc",
     "src/trace_processor/trace_processor_shell.cc",
   ],
-  shared_libs: [
-    "libprotoc",
-    "libz",
-  ],
   static_libs: [
+    "libprotoc",
     "libsqlite",
+    "libz",
   ],
   generated_headers: [
     "gen_merged_sql_metrics",
@@ -5656,6 +5654,7 @@
     "-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
     "-DHAVE_HIDDEN",
   ],
+  static_executable: true,
 }
 
 // GN: //tools/trace_to_text:trace_to_text
@@ -5739,10 +5738,10 @@
   shared_libs: [
     "libprotobuf-cpp-full",
     "libprotobuf-cpp-lite",
-    "libz",
   ],
   static_libs: [
     "libsqlite",
+    "libz",
   ],
   generated_headers: [
     "gen_merged_sql_metrics",
diff --git a/tools/gen_android_bp b/tools/gen_android_bp
index 5610db4..2d1203b 100755
--- a/tools/gen_android_bp
+++ b/tools/gen_android_bp
@@ -154,6 +154,7 @@
         ('required', {'libperfetto_android_internal', 'trigger_perfetto'}),
     ],
     'libperfetto_android_internal': [('static_libs', {'libhealthhalutils'}),],
+    'trace_processor_shell': [('static_executable', True),],
 }
 
 
@@ -170,7 +171,10 @@
 
 
 def enable_protoc_lib(module):
-  module.shared_libs.add('libprotoc')
+  if module.type == 'cc_binary_host':
+    module.static_libs.add('libprotoc')
+  else:
+    module.shared_libs.add('libprotoc')
 
 
 def enable_libunwindstack(module):
@@ -197,7 +201,10 @@
 
 
 def enable_zlib(module):
-  module.shared_libs.add('libz')
+  if module.type == 'cc_binary_host':
+    module.static_libs.add('libz')
+  else:
+    module.shared_libs.add('libz')
 
 
 # Android equivalents for third-party libraries that the upstream project
@@ -312,6 +319,7 @@
     self.android = Target('android')
     self.host = Target('host')
     self.lto = None
+    self.static_executable = False
     self.data = set()
     # The genrule_XXX below are properties that must to be propagated back
     # on the module(s) that depend on the genrule.
@@ -340,6 +348,7 @@
     self._output_field(output, 'include_dirs')
     self._output_field(output, 'header_libs')
     self._output_field(output, 'required')
+    self._output_field(output, 'static_executable')
     self._output_field(output, 'tool_files')
     self._output_field(output, 'data')
 
@@ -617,6 +626,8 @@
     curr = getattr(module, key)
     if add_val and isinstance(add_val, set) and isinstance(curr, set):
       curr.update(add_val)
+    elif isinstance(add_val, bool) and isinstance(curr, bool):
+      setattr(module, key, add_val)
     else:
       raise Error('Unimplemented type of additional_args: %r' % key)