Split executables and introduce common shared library

[Splitting this CL off https://android-review.googlesource.com/c/platform/external/perfetto/+/575382]
This CL turns the perfetto daemons into two standalone
executables. Given the amount of shared code between the
two (traced and traced_probes) the code is shared in a
.so library.

Change-Id: I370a536ed3576e991e01032c183f7cdf61a4b7d3
diff --git a/tools/gen_android_bp b/tools/gen_android_bp
index bcc0f43..3c7b96b 100755
--- a/tools/gen_android_bp
+++ b/tools/gen_android_bp
@@ -37,9 +37,15 @@
 default_targets = [
     '//:perfetto_tests',
     '//:traced',
+    '//:traced_probes',
+    '//:libtraced_shared',
     '//src/tracing:consumer_cmd',
 ]
 
+# Defines a custom init_rc argument to be applied to the corresponding output
+# blueprint target.
+target_initrc = {}  # TODO(primiano): populate in upcoming CLs.
+
 # Arguments for the GN output directory.
 gn_args = 'target_os="android" target_cpu="arm" is_debug=false'
 
@@ -132,6 +138,7 @@
         self.static_libs = []
         self.tools = []
         self.cmd = None
+        self.init_rc = []
         self.out = []
         self.export_include_dirs = []
         self.generated_headers = []
@@ -149,6 +156,7 @@
         self._output_field(output, 'static_libs')
         self._output_field(output, 'tools')
         self._output_field(output, 'cmd', sort=False)
+        self._output_field(output, 'init_rc')
         self._output_field(output, 'out')
         self._output_field(output, 'export_include_dirs')
         self._output_field(output, 'generated_headers')
@@ -272,6 +280,9 @@
             dep_name) != module.name:
         create_modules_from_target(blueprint, desc, dep_name)
         module.static_libs.append(label_to_module_name(dep_name))
+    elif type == 'shared_library' and label_to_module_name(
+            dep_name) != module.name:
+        module.shared_libs.append(label_to_module_name(dep_name))
     elif type in ['group', 'source_set', 'executable', 'static_library'
                   ] and 'sources' in target:
         # Ignore source files that are generated by actions since they will be
@@ -410,11 +421,18 @@
         modules = [
             Module('cc_library_static', label_to_module_name(target_name))
         ]
+    elif target['type'] == 'shared_library':
+        modules = [
+            Module('cc_library_shared', label_to_module_name(target_name))
+        ]
     else:
         raise Error('Unknown target type: %s' % target['type'])
 
     for module in modules:
         module.comment = 'GN target: %s' % target_name
+        if target_name in target_initrc:
+          module.init_rc = [target_initrc[target_name]]
+
         # Don't try to inject library/source dependencies into genrules because
         # they are not compiled in the traditional sense.
         if module.type != 'genrule':
@@ -447,6 +465,10 @@
         # explicitly converted to genrules.
         if desc[dep]['type'] == 'action':
             continue
+        # Dependencies on shared libraries shouldn't propagate any transitive
+        # dependencies but only depend on the shared library target
+        if desc[dep]['type'] == 'shared_library':
+            continue
         resolved_deps.update(resolve_dependencies(desc, dep))
     return resolved_deps