Merge "bazel: allow overriding filegroup and genrule"
diff --git a/BUILD b/BUILD
index 2e6dab3..a68cc52 100644
--- a/BUILD
+++ b/BUILD
@@ -17,7 +17,10 @@
 load("@perfetto_cfg//:perfetto_cfg.bzl", "PERFETTO_CONFIG")
 load(
     "@perfetto//bazel:rules.bzl",
+    "perfetto_build_config_cc_library",
     "perfetto_cc_binary",
+    "perfetto_filegroup",
+    "perfetto_genrule",
     "perfetto_cc_ipc_library",
     "perfetto_cc_library",
     "perfetto_cc_proto_descriptor",
@@ -309,7 +312,7 @@
 )
 
 # GN target: //include/perfetto/base:base
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_base_base",
     srcs = [
         "include/perfetto/base/build_config.h",
@@ -328,7 +331,7 @@
 )
 
 # GN target: //include/perfetto/ext/base:base
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_ext_base_base",
     srcs = [
         "include/perfetto/ext/base/circular_queue.h",
@@ -374,7 +377,7 @@
 )
 
 # GN target: //include/perfetto/ext/ipc:ipc
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_ext_ipc_ipc",
     srcs = [
         "include/perfetto/ext/ipc/async_result.h",
@@ -391,7 +394,7 @@
 )
 
 # GN target: //include/perfetto/ext/trace_processor/importers/memory_tracker:memory_tracker
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_ext_trace_processor_importers_memory_tracker_memory_tracker",
     srcs = [
         "include/perfetto/ext/trace_processor/importers/memory_tracker/graph.h",
@@ -404,7 +407,7 @@
 )
 
 # GN target: //include/perfetto/ext/trace_processor:export_json
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_ext_trace_processor_export_json",
     srcs = [
         "include/perfetto/ext/trace_processor/export_json.h",
@@ -412,7 +415,7 @@
 )
 
 # GN target: //include/perfetto/ext/traced:sys_stats_counters
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_ext_traced_sys_stats_counters",
     srcs = [
         "include/perfetto/ext/traced/sys_stats_counters.h",
@@ -420,7 +423,7 @@
 )
 
 # GN target: //include/perfetto/ext/traced:traced
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_ext_traced_traced",
     srcs = [
         "include/perfetto/ext/traced/data_source_types.h",
@@ -429,7 +432,7 @@
 )
 
 # GN target: //include/perfetto/ext/tracing/core:core
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_ext_tracing_core_core",
     srcs = [
         "include/perfetto/ext/tracing/core/basic_types.h",
@@ -449,7 +452,7 @@
 )
 
 # GN target: //include/perfetto/ext/tracing/ipc:ipc
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_ext_tracing_ipc_ipc",
     srcs = [
         "include/perfetto/ext/tracing/ipc/consumer_ipc_client.h",
@@ -460,7 +463,7 @@
 )
 
 # GN target: //include/perfetto/profiling:pprof_builder
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_profiling_pprof_builder",
     srcs = [
         "include/perfetto/profiling/pprof_builder.h",
@@ -468,7 +471,7 @@
 )
 
 # GN target: //include/perfetto/protozero:protozero
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_protozero_protozero",
     srcs = [
         "include/perfetto/protozero/contiguous_memory_range.h",
@@ -491,7 +494,7 @@
 )
 
 # GN target: //include/perfetto/public:public
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_public_public",
     srcs = [
         "include/perfetto/public/consumer_api.h",
@@ -499,7 +502,7 @@
 )
 
 # GN target: //include/perfetto/trace_processor:basic_types
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_trace_processor_basic_types",
     srcs = [
         "include/perfetto/trace_processor/basic_types.h",
@@ -508,7 +511,7 @@
 )
 
 # GN target: //include/perfetto/trace_processor:storage
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_trace_processor_storage",
     srcs = [
         "include/perfetto/trace_processor/trace_processor_storage.h",
@@ -516,7 +519,7 @@
 )
 
 # GN target: //include/perfetto/trace_processor:trace_processor
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_trace_processor_trace_processor",
     srcs = [
         "include/perfetto/trace_processor/iterator.h",
@@ -526,7 +529,7 @@
 )
 
 # GN target: //include/perfetto/tracing/core:core
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_tracing_core_core",
     srcs = [
         "include/perfetto/tracing/core/chrome_config.h",
@@ -539,7 +542,7 @@
 )
 
 # GN target: //include/perfetto/tracing/core:forward_decls
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_tracing_core_forward_decls",
     srcs = [
         "include/perfetto/tracing/core/forward_decls.h",
@@ -547,7 +550,7 @@
 )
 
 # GN target: //include/perfetto/tracing:tracing
-filegroup(
+perfetto_filegroup(
     name = "include_perfetto_tracing_tracing",
     srcs = [
         "include/perfetto/tracing/backend_type.h",
@@ -593,7 +596,7 @@
 )
 
 # GN target: //src/android_internal:headers
-filegroup(
+perfetto_filegroup(
     name = "src_android_internal_headers",
     srcs = [
         "src/android_internal/atrace_hal.h",
@@ -606,7 +609,7 @@
 )
 
 # GN target: //src/android_internal:lazy_library_loader
-filegroup(
+perfetto_filegroup(
     name = "src_android_internal_lazy_library_loader",
     srcs = [
         "src/android_internal/lazy_library_loader.cc",
@@ -615,7 +618,7 @@
 )
 
 # GN target: //src/android_stats:android_stats
-filegroup(
+perfetto_filegroup(
     name = "src_android_stats_android_stats",
     srcs = [
         "src/android_stats/statsd_logging_helper.cc",
@@ -624,7 +627,7 @@
 )
 
 # GN target: //src/android_stats:perfetto_atoms
-filegroup(
+perfetto_filegroup(
     name = "src_android_stats_perfetto_atoms",
     srcs = [
         "src/android_stats/perfetto_atoms.h",
@@ -687,7 +690,7 @@
     linkstatic = True,
 )
 
-genrule(
+perfetto_genrule(
     name = "src_base_version_gen_h",
     srcs = [
         "CHANGELOG",
@@ -702,7 +705,7 @@
 )
 
 # GN target: //src/ipc:client
-filegroup(
+perfetto_filegroup(
     name = "src_ipc_client",
     srcs = [
         "src/ipc/client_impl.cc",
@@ -712,7 +715,7 @@
 )
 
 # GN target: //src/ipc:common
-filegroup(
+perfetto_filegroup(
     name = "src_ipc_common",
     srcs = [
         "src/ipc/buffered_frame_deserializer.cc",
@@ -723,7 +726,7 @@
 )
 
 # GN target: //src/ipc:host
-filegroup(
+perfetto_filegroup(
     name = "src_ipc_host",
     srcs = [
         "src/ipc/host_impl.cc",
@@ -732,7 +735,7 @@
 )
 
 # GN target: //src/kallsyms:kallsyms
-filegroup(
+perfetto_filegroup(
     name = "src_kallsyms_kallsyms",
     srcs = [
         "src/kallsyms/kernel_symbol_map.cc",
@@ -753,7 +756,7 @@
 )
 
 # GN target: //src/perfetto_cmd:perfetto_cmd
-filegroup(
+perfetto_filegroup(
     name = "src_perfetto_cmd_perfetto_cmd",
     srcs = [
         "src/perfetto_cmd/config.cc",
@@ -770,7 +773,7 @@
 )
 
 # GN target: //src/perfetto_cmd:trigger_producer
-filegroup(
+perfetto_filegroup(
     name = "src_perfetto_cmd_trigger_producer",
     srcs = [
         "src/perfetto_cmd/trigger_producer.cc",
@@ -779,7 +782,7 @@
 )
 
 # GN target: //src/profiling/symbolizer:symbolize_database
-filegroup(
+perfetto_filegroup(
     name = "src_profiling_symbolizer_symbolize_database",
     srcs = [
         "src/profiling/symbolizer/symbolize_database.cc",
@@ -788,7 +791,7 @@
 )
 
 # GN target: //src/profiling/symbolizer:symbolizer
-filegroup(
+perfetto_filegroup(
     name = "src_profiling_symbolizer_symbolizer",
     srcs = [
         "src/profiling/symbolizer/breakpad_parser.cc",
@@ -810,7 +813,7 @@
 )
 
 # GN target: //src/profiling:deobfuscator
-filegroup(
+perfetto_filegroup(
     name = "src_profiling_deobfuscator",
     srcs = [
         "src/profiling/deobfuscator.cc",
@@ -819,7 +822,7 @@
 )
 
 # GN target: //src/protozero/filtering:bytecode_common
-filegroup(
+perfetto_filegroup(
     name = "src_protozero_filtering_bytecode_common",
     srcs = [
         "src/protozero/filtering/filter_bytecode_common.h",
@@ -827,7 +830,7 @@
 )
 
 # GN target: //src/protozero/filtering:bytecode_generator
-filegroup(
+perfetto_filegroup(
     name = "src_protozero_filtering_bytecode_generator",
     srcs = [
         "src/protozero/filtering/filter_bytecode_generator.cc",
@@ -836,7 +839,7 @@
 )
 
 # GN target: //src/protozero/filtering:bytecode_parser
-filegroup(
+perfetto_filegroup(
     name = "src_protozero_filtering_bytecode_parser",
     srcs = [
         "src/protozero/filtering/filter_bytecode_parser.cc",
@@ -845,7 +848,7 @@
 )
 
 # GN target: //src/protozero/filtering:filter_util
-filegroup(
+perfetto_filegroup(
     name = "src_protozero_filtering_filter_util",
     srcs = [
         "src/protozero/filtering/filter_util.cc",
@@ -854,7 +857,7 @@
 )
 
 # GN target: //src/protozero/filtering:message_filter
-filegroup(
+perfetto_filegroup(
     name = "src_protozero_filtering_message_filter",
     srcs = [
         "src/protozero/filtering/message_filter.cc",
@@ -864,7 +867,7 @@
 )
 
 # GN target: //src/protozero:proto_ring_buffer
-filegroup(
+perfetto_filegroup(
     name = "src_protozero_proto_ring_buffer",
     srcs = [
         "src/protozero/proto_ring_buffer.cc",
@@ -873,7 +876,7 @@
 )
 
 # GN target: //src/trace_processor/analysis:analysis
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_analysis_analysis",
     srcs = [
         "src/trace_processor/analysis/describe_slice.cc",
@@ -908,7 +911,7 @@
 )
 
 # GN target: //src/trace_processor/db:db
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_db_db",
     srcs = [
         "src/trace_processor/db/column.cc",
@@ -922,7 +925,7 @@
 )
 
 # GN target: //src/trace_processor/importers/common:common
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_importers_common_common",
     srcs = [
         "src/trace_processor/importers/common/args_tracker.cc",
@@ -949,7 +952,7 @@
 )
 
 # GN target: //src/trace_processor/importers/memory_tracker:graph_processor
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_importers_memory_tracker_graph_processor",
     srcs = [
         "src/trace_processor/importers/memory_tracker/graph.cc",
@@ -1010,7 +1013,7 @@
     ],
 )
 
-genrule(
+perfetto_genrule(
     name = "src_trace_processor_metrics_gen_merged_sql_metrics",
     srcs = [
         "src/trace_processor/metrics/android/android_batt.sql",
@@ -1111,7 +1114,7 @@
 )
 
 # GN target: //src/trace_processor/metrics:lib
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_metrics_lib",
     srcs = [
         "src/trace_processor/metrics/metrics.cc",
@@ -1120,7 +1123,7 @@
 )
 
 # GN target: //src/trace_processor/rpc:httpd
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_rpc_httpd",
     srcs = [
         "src/trace_processor/rpc/httpd.cc",
@@ -1129,7 +1132,7 @@
 )
 
 # GN target: //src/trace_processor/rpc:rpc
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_rpc_rpc",
     srcs = [
         "src/trace_processor/rpc/query_result_serializer.cc",
@@ -1140,7 +1143,7 @@
 )
 
 # GN target: //src/trace_processor/sqlite:sqlite
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_sqlite_sqlite",
     srcs = [
         "src/trace_processor/sqlite/db_sqlite_table.cc",
@@ -1168,7 +1171,7 @@
 )
 
 # GN target: //src/trace_processor/storage:storage
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_storage_storage",
     srcs = [
         "src/trace_processor/storage/metadata.h",
@@ -1179,7 +1182,7 @@
 )
 
 # GN target: //src/trace_processor/tables:tables
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_tables_tables",
     srcs = [
         "src/trace_processor/tables/android_tables.h",
@@ -1197,7 +1200,7 @@
 )
 
 # GN target: //src/trace_processor/types:types
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_types_types",
     srcs = [
         "src/trace_processor/types/destructible.cc",
@@ -1215,7 +1218,7 @@
 )
 
 # GN target: //src/trace_processor/util:descriptors
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_util_descriptors",
     srcs = [
         "src/trace_processor/util/descriptors.cc",
@@ -1224,7 +1227,7 @@
 )
 
 # GN target: //src/trace_processor/util:gzip
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_util_gzip",
     srcs = [
         "src/trace_processor/util/gzip_utils.cc",
@@ -1233,7 +1236,7 @@
 )
 
 # GN target: //src/trace_processor/util:interned_message_view
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_util_interned_message_view",
     srcs = [
         "src/trace_processor/util/interned_message_view.h",
@@ -1241,7 +1244,7 @@
 )
 
 # GN target: //src/trace_processor/util:proto_to_args_parser
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_util_proto_to_args_parser",
     srcs = [
         "src/trace_processor/util/debug_annotation_parser.cc",
@@ -1252,7 +1255,7 @@
 )
 
 # GN target: //src/trace_processor/util:protozero_to_text
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_util_protozero_to_text",
     srcs = [
         "src/trace_processor/util/protozero_to_text.cc",
@@ -1261,7 +1264,7 @@
 )
 
 # GN target: //src/trace_processor/util:trace_blob_view
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_util_trace_blob_view",
     srcs = [
         "src/trace_processor/util/trace_blob_view.h",
@@ -1269,7 +1272,7 @@
 )
 
 # GN target: //src/trace_processor/util:util
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_util_util",
     srcs = [
         "src/trace_processor/util/status_macros.h",
@@ -1277,7 +1280,7 @@
 )
 
 # GN target: //src/trace_processor:export_json
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_export_json",
     srcs = [
         "src/trace_processor/export_json.cc",
@@ -1286,7 +1289,7 @@
 )
 
 # GN target: //src/trace_processor:ftrace_descriptors
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_ftrace_descriptors",
     srcs = [
         "src/trace_processor/importers/ftrace/ftrace_descriptors.cc",
@@ -1295,7 +1298,7 @@
 )
 
 # GN target: //src/trace_processor:lib
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_lib",
     srcs = [
         "src/trace_processor/dynamic/ancestor_generator.cc",
@@ -1330,7 +1333,7 @@
 )
 
 # GN target: //src/trace_processor:metatrace
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_metatrace",
     srcs = [
         "src/trace_processor/tp_metatrace.cc",
@@ -1339,7 +1342,7 @@
 )
 
 # GN target: //src/trace_processor:storage_full
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_storage_full",
     srcs = [
         "src/trace_processor/importers/additional_modules.cc",
@@ -1412,7 +1415,7 @@
 )
 
 # GN target: //src/trace_processor:storage_minimal
-filegroup(
+perfetto_filegroup(
     name = "src_trace_processor_storage_minimal",
     srcs = [
         "src/trace_processor/forwarding_trace_parser.cc",
@@ -1490,7 +1493,7 @@
 )
 
 # GN target: //src/traced/probes/android_log:android_log
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_android_log_android_log",
     srcs = [
         "src/traced/probes/android_log/android_log_data_source.cc",
@@ -1499,7 +1502,7 @@
 )
 
 # GN target: //src/traced/probes/common:common
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_common_common",
     srcs = [
         "src/traced/probes/common/cpu_freq_info.cc",
@@ -1508,7 +1511,7 @@
 )
 
 # GN target: //src/traced/probes/filesystem:filesystem
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_filesystem_filesystem",
     srcs = [
         "src/traced/probes/filesystem/file_scanner.cc",
@@ -1527,7 +1530,7 @@
 )
 
 # GN target: //src/traced/probes/ftrace/format_parser:format_parser
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_ftrace_format_parser_format_parser",
     srcs = [
         "src/traced/probes/ftrace/format_parser/format_parser.cc",
@@ -1536,7 +1539,7 @@
 )
 
 # GN target: //src/traced/probes/ftrace:ftrace
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_ftrace_ftrace",
     srcs = [
         "src/traced/probes/ftrace/atrace_hal_wrapper.cc",
@@ -1574,7 +1577,7 @@
 )
 
 # GN target: //src/traced/probes/ftrace:ftrace_procfs
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_ftrace_ftrace_procfs",
     srcs = [
         "src/traced/probes/ftrace/ftrace_procfs.cc",
@@ -1583,7 +1586,7 @@
 )
 
 # GN target: //src/traced/probes/initial_display_state:initial_display_state
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_initial_display_state_initial_display_state",
     srcs = [
         "src/traced/probes/initial_display_state/initial_display_state_data_source.cc",
@@ -1592,7 +1595,7 @@
 )
 
 # GN target: //src/traced/probes/metatrace:metatrace
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_metatrace_metatrace",
     srcs = [
         "src/traced/probes/metatrace/metatrace_data_source.cc",
@@ -1601,7 +1604,7 @@
 )
 
 # GN target: //src/traced/probes/packages_list:packages_list
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_packages_list_packages_list",
     srcs = [
         "src/traced/probes/packages_list/packages_list_data_source.cc",
@@ -1610,7 +1613,7 @@
 )
 
 # GN target: //src/traced/probes/packages_list:packages_list_parser
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_packages_list_packages_list_parser",
     srcs = [
         "src/traced/probes/packages_list/packages_list_parser.cc",
@@ -1619,7 +1622,7 @@
 )
 
 # GN target: //src/traced/probes/power:power
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_power_power",
     srcs = [
         "src/traced/probes/power/android_power_data_source.cc",
@@ -1628,7 +1631,7 @@
 )
 
 # GN target: //src/traced/probes/ps:ps
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_ps_ps",
     srcs = [
         "src/traced/probes/ps/process_stats_data_source.cc",
@@ -1637,7 +1640,7 @@
 )
 
 # GN target: //src/traced/probes/sys_stats:sys_stats
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_sys_stats_sys_stats",
     srcs = [
         "src/traced/probes/sys_stats/sys_stats_data_source.cc",
@@ -1646,7 +1649,7 @@
 )
 
 # GN target: //src/traced/probes/system_info:system_info
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_system_info_system_info",
     srcs = [
         "src/traced/probes/system_info/system_info_data_source.cc",
@@ -1655,7 +1658,7 @@
 )
 
 # GN target: //src/traced/probes:data_source
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_data_source",
     srcs = [
         "src/traced/probes/probes_data_source.cc",
@@ -1664,7 +1667,7 @@
 )
 
 # GN target: //src/traced/probes:probes
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_probes",
     srcs = [
         "src/traced/probes/probes.cc",
@@ -1672,7 +1675,7 @@
 )
 
 # GN target: //src/traced/probes:probes_src
-filegroup(
+perfetto_filegroup(
     name = "src_traced_probes_probes_src",
     srcs = [
         "src/traced/probes/kmem_activity_trigger.cc",
@@ -1683,7 +1686,7 @@
 )
 
 # GN target: //src/traced/service:service
-filegroup(
+perfetto_filegroup(
     name = "src_traced_service_service",
     srcs = [
         "src/traced/service/builtin_producer.cc",
@@ -1693,7 +1696,7 @@
 )
 
 # GN target: //src/tracing/consumer_api_deprecated:consumer_api_deprecated
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_consumer_api_deprecated_consumer_api_deprecated",
     srcs = [
         "src/tracing/consumer_api_deprecated/consumer_api_deprecated.cc",
@@ -1701,7 +1704,7 @@
 )
 
 # GN target: //src/tracing/core:core
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_core_core",
     srcs = [
         "src/tracing/core/id_allocator.cc",
@@ -1720,7 +1723,7 @@
 )
 
 # GN target: //src/tracing/core:service
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_core_service",
     srcs = [
         "src/tracing/core/metatrace_writer.cc",
@@ -1735,7 +1738,7 @@
 )
 
 # GN target: //src/tracing/ipc/consumer:consumer
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_ipc_consumer_consumer",
     srcs = [
         "src/tracing/ipc/consumer/consumer_ipc_client_impl.cc",
@@ -1744,7 +1747,7 @@
 )
 
 # GN target: //src/tracing/ipc/producer:producer
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_ipc_producer_producer",
     srcs = [
         "src/tracing/ipc/producer/producer_ipc_client_impl.cc",
@@ -1753,7 +1756,7 @@
 )
 
 # GN target: //src/tracing/ipc/service:service
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_ipc_service_service",
     srcs = [
         "src/tracing/ipc/service/consumer_ipc_service.cc",
@@ -1766,7 +1769,7 @@
 )
 
 # GN target: //src/tracing/ipc:common
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_ipc_common",
     srcs = [
         "src/tracing/ipc/default_socket.cc",
@@ -1780,7 +1783,7 @@
 )
 
 # GN target: //src/tracing:client_api_without_backends
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_client_api_without_backends",
     srcs = [
         "src/tracing/console_interceptor.cc",
@@ -1810,7 +1813,7 @@
 )
 
 # GN target: //src/tracing:common
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_common",
     srcs = [
         "src/tracing/trace_writer_base.cc",
@@ -1818,7 +1821,7 @@
 )
 
 # GN target: //src/tracing:in_process_backend
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_in_process_backend",
     srcs = [
         "src/tracing/internal/in_process_tracing_backend.cc",
@@ -1826,7 +1829,7 @@
 )
 
 # GN target: //src/tracing:platform_impl
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_platform_impl",
     srcs = [
         "src/tracing/platform_posix.cc",
@@ -1835,7 +1838,7 @@
 )
 
 # GN target: //src/tracing:system_backend
-filegroup(
+perfetto_filegroup(
     name = "src_tracing_system_backend",
     srcs = [
         "src/tracing/internal/system_tracing_backend.cc",
@@ -1843,7 +1846,7 @@
 )
 
 # GN target: //tools/trace_to_text:common
-filegroup(
+perfetto_filegroup(
     name = "tools_trace_to_text_common",
     srcs = [
         "tools/trace_to_text/deobfuscate_profile.cc",
@@ -1864,7 +1867,7 @@
 )
 
 # GN target: //tools/trace_to_text:full
-filegroup(
+perfetto_filegroup(
     name = "tools_trace_to_text_full",
     srcs = [
         "tools/trace_to_text/proto_full_utils.cc",
@@ -1884,7 +1887,7 @@
 )
 
 # GN target: //tools/trace_to_text:pprofbuilder
-filegroup(
+perfetto_filegroup(
     name = "tools_trace_to_text_pprofbuilder",
     srcs = [
         "tools/trace_to_text/pprof_builder.cc",
@@ -1892,7 +1895,7 @@
 )
 
 # GN target: //tools/trace_to_text:utils
-filegroup(
+perfetto_filegroup(
     name = "tools_trace_to_text_utils",
     srcs = [
         "tools/trace_to_text/utils.cc",
@@ -4038,7 +4041,7 @@
 
 # Deliberately NOT a perfetto_cc_library, to avoid cyclic deps.
 # This is pulled as a default dep by all targets.
-cc_library(
+perfetto_build_config_cc_library(
     name = "build_config_hdr",
     hdrs = [build_config_dir_ + "/perfetto_build_flags.h"],
     includes = [build_config_dir_],
diff --git a/BUILD.extras b/BUILD.extras
index be5aa90..6b31fb2 100644
--- a/BUILD.extras
+++ b/BUILD.extras
@@ -2,7 +2,7 @@
 
 # Deliberately NOT a perfetto_cc_library, to avoid cyclic deps.
 # This is pulled as a default dep by all targets.
-cc_library(
+perfetto_build_config_cc_library(
     name = "build_config_hdr",
     hdrs = [build_config_dir_ + "/perfetto_build_flags.h"],
     includes = [build_config_dir_],
diff --git a/bazel/rules.bzl b/bazel/rules.bzl
index 4503867..d191297 100644
--- a/bazel/rules.bzl
+++ b/bazel/rules.bzl
@@ -34,6 +34,18 @@
         }),
     }
 
+def perfetto_build_config_cc_library(**kwargs):
+    if not _rule_override("cc_library", **kwargs):
+        native.cc_library(**kwargs)
+
+def perfetto_filegroup(**kwargs):
+    if not _rule_override("filegroup", **kwargs):
+        native.filegroup(**kwargs)
+
+def perfetto_genrule(**kwargs):
+    if not _rule_override("genrule", **kwargs):
+        native.genrule(**kwargs)
+
 def perfetto_cc_library(**kwargs):
     args = _merge_dicts(default_cc_args(), kwargs)
     if not _rule_override("cc_library", **args):
@@ -104,17 +116,19 @@
     if len(_proto_deps) != 1:
         fail("Too many proto deps for target %s" % name)
 
-    proto_gen(
-        name = name + "_src",
-        deps = _proto_deps,
-        suffix = "pbzero",
-        plugin = PERFETTO_CONFIG.root + ":protozero_plugin",
-        wrapper_namespace = "pbzero",
-        protoc = PERFETTO_CONFIG.deps.protoc[0],
-        root = PERFETTO_CONFIG.root,
-    )
+    args = {
+        'name': name + "_src",
+        'deps': _proto_deps,
+        'suffix': "pbzero",
+        'plugin': PERFETTO_CONFIG.root + ":protozero_plugin",
+        'wrapper_namespace': "pbzero",
+        'protoc': PERFETTO_CONFIG.deps.protoc[0],
+        'root': PERFETTO_CONFIG.root,
+    }
+    if not _rule_override("proto_gen", **args):
+        proto_gen(**args)
 
-    native.filegroup(
+    perfetto_filegroup(
         name = name + "_h",
         srcs = [":" + name + "_src"],
         output_group = "h",
@@ -225,11 +239,13 @@
     )
 
 def perfetto_proto_descriptor(name, deps, outs, **kwargs):
-    proto_descriptor_gen(
-        name = name,
-        deps = deps,
-        outs = outs,
-    )
+    args = {
+        'name': name,
+        'deps': deps,
+        'outs': outs,
+    }
+    if not _rule_override("proto_descriptor_gen", **args):
+        proto_descriptor_gen(**args)
 
 # Generator .descriptor.h from protos
 def perfetto_cc_proto_descriptor(name, deps, outs, **kwargs):
@@ -239,7 +255,7 @@
         "--gen_dir=$(GENDIR)",
         "$<"
     ]
-    native.genrule(
+    perfetto_genrule(
         name = name + "_gen",
         cmd = " ".join(cmd),
         exec_tools = [
diff --git a/tools/gen_bazel b/tools/gen_bazel
index dd847ed..3a1b8ae 100755
--- a/tools/gen_bazel
+++ b/tools/gen_bazel
@@ -116,7 +116,7 @@
 
 
 def gen_sql_metrics(target):
-  label = BazelLabel(get_bazel_label_name(target.name), 'genrule')
+  label = BazelLabel(get_bazel_label_name(target.name), 'perfetto_genrule')
   label.srcs += [re.sub('^//', '', x) for x in sorted(target.inputs)]
   label.outs += target.outputs
   label.cmd = r'$(location gen_merged_sql_metrics_py) --cpp_out=$@ $(SRCS)'
@@ -125,7 +125,7 @@
 
 
 def gen_version_header(target):
-  label = BazelLabel(get_bazel_label_name(target.name), 'genrule')
+  label = BazelLabel(get_bazel_label_name(target.name), 'perfetto_genrule')
   label.srcs += [re.sub('^//', '', x) for x in sorted(target.inputs)]
   label.outs += target.outputs
   label.cmd = r'$(location gen_version_header_py)'
@@ -359,7 +359,7 @@
   elif gn_target.type == 'static_library':
     bazel_type = 'perfetto_cc_library'
   elif gn_target.type == 'source_set':
-    bazel_type = 'filegroup'
+    bazel_type = 'perfetto_filegroup'
   else:
     raise Error('target type not supported: %s' % gn_target.type)
 
@@ -448,7 +448,10 @@
 load("@perfetto_cfg//:perfetto_cfg.bzl", "PERFETTO_CONFIG")
 load(
     "@perfetto//bazel:rules.bzl",
+    "perfetto_build_config_cc_library",
     "perfetto_cc_binary",
+    "perfetto_filegroup",
+    "perfetto_genrule",
     "perfetto_cc_ipc_library",
     "perfetto_cc_library",
     "perfetto_cc_proto_descriptor",