Add host target for perfetto protos on Android host builds
This CL introduces a "perfetto_trace_protos" static_library
target that allows to link the perfetto protobuf code on
host executable builds.
This CL also disentangles some awkward dep between proto:lite
targets and the IPC proto targets, that was indirectly causing
the core tracing target to depend on ipc.
Also fixes a small breakage on mac by removing an unnecessary
include in trace_to_text.
Sample usage:
In the .bp file:
---
cc_binary_host {
name: "perfetto_proto_test",
static_libs: [
"perfetto_trace_protos",
"libprotobuf-cpp-lite",
],
srcs: [
"host_test.cc"
],
}
---
Where host_test.cc:
---
#include "perfetto/trace/trace.pb.h"
int main(int, char** argv) {
perfetto::protos::Trace trace;
return trace.ParseFromString(std::string(argv[1]));
}
---
Bug: 73611302
Change-Id: Ie371e82941890a3a7567c30261befd756147cc1c
Test: manual. Checked that builds on mac.
diff --git a/tools/gen_android_bp b/tools/gen_android_bp
index a7dafc5..728ed23 100755
--- a/tools/gen_android_bp
+++ b/tools/gen_android_bp
@@ -38,6 +38,7 @@
default_targets = [
'//:libtraced_shared',
'//:perfetto_integrationtests',
+ '//:perfetto_trace_protos',
'//:perfetto_unittests',
'//:perfetto',
'//:traced',
@@ -50,6 +51,10 @@
'//:traced': 'perfetto.rc',
}
+target_host_supported = [
+ '//:perfetto_trace_protos',
+]
+
# Arguments for the GN output directory.
gn_args = 'target_os="android" target_cpu="arm" is_debug=false build_with_android=true'
@@ -157,6 +162,7 @@
self.static_libs = []
self.tools = []
self.cmd = None
+ self.host_supported = False
self.init_rc = []
self.out = []
self.export_include_dirs = []
@@ -176,6 +182,7 @@
self._output_field(output, 'static_libs')
self._output_field(output, 'tools')
self._output_field(output, 'cmd', sort=False)
+ self._output_field(output, 'host_supported')
self._output_field(output, 'init_rc')
self._output_field(output, 'out')
self._output_field(output, 'export_include_dirs')
@@ -204,8 +211,11 @@
for item in sorted(value) if sort else value:
output.append(' "%s",' % item)
output.append(' ],')
- else:
- output.append(' %s: "%s",' % (name, value))
+ return
+ if isinstance(value, bool):
+ output.append(' %s: true,' % name)
+ return
+ output.append(' %s: "%s",' % (name, value))
class Blueprint(object):
@@ -484,6 +494,8 @@
module.comment = 'GN target: %s' % target_name
if target_name in target_initrc:
module.init_rc = [target_initrc[target_name]]
+ if target_name in target_host_supported:
+ module.host_supported = True
# Don't try to inject library/source dependencies into genrules because
# they are not compiled in the traditional sense.