gn2bp: remove local protobuf includes via denylist

Adds a denylist for include dirs. The previous approach did not work as
not all targets listed protobuf as a dependency (some of them got
libprotobuf via genrule_shared_libs).

Test: //components/cronet/android:cronet
Change-Id: I05fb3f8206d5e7c904013d3da2fb7632a594177c
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 6acaee7..0a60559 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -1872,7 +1872,6 @@
         "net/third_party/quiche/src/quiche/common/platform/default/",
         "third_party/abseil-cpp/",
         "third_party/boringssl/src/include/",
-        "third_party/protobuf/src/",
         "third_party/zlib/",
         "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
     ],
@@ -4017,7 +4016,6 @@
         "buildtools/third_party/libc++abi/trunk/include",
         "third_party/abseil-cpp/",
         "third_party/boringssl/src/include/",
-        "third_party/protobuf/src/",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include",
     ],
     cpp_std: "c++20",
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 33a06c0..8237cdf 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -84,6 +84,11 @@
     'statslog_perfetto',
 ]
 
+# Include directories that will be removed from all targets.
+local_include_dirs_denylist = [
+    'third_party/protobuf/src/',
+]
+
 # Name of the module which settings such as compiler flags for all other
 # modules.
 defaults_module = module_prefix + 'defaults'
@@ -116,15 +121,7 @@
     module.whole_static_libs.add('perfetto_gtest_logcat_printer')
 
 
-def remove_local_protobuf_include(module):
-  # remove all third_party/protobuf includes as they conflict with libprotobuf
-  # in Android.
-  module.local_include_dirs = [it for it in module.local_include_dirs
-                               if not it.startswith('third_party/protobuf')]
-
-
 def enable_protobuf_full(module):
-  remove_local_protobuf_include(module)
   if module.type == 'cc_binary_host':
     module.static_libs.add('libprotobuf-cpp-full')
   elif module.host_supported:
@@ -135,13 +132,11 @@
 
 
 def enable_protobuf_lite(module):
-  remove_local_protobuf_include(module)
   if module.type not in ['genrule', 'filegroup']:
     module.shared_libs.add('libprotobuf-cpp-lite')
 
 
 def enable_protoc_lib(module):
-  remove_local_protobuf_include(module)
   if module.type == 'cc_binary_host':
     module.static_libs.add('libprotoc')
   else:
@@ -1107,6 +1102,11 @@
       if lib in static_library_allowlist:
         module.add_android_static_lib(android_lib)
 
+    # Remove prohibited include directories
+    module.local_include_dirs = [d for d in module.local_include_dirs
+                                 if d not in local_include_dirs_denylist]
+
+
   # If the module is a static library, export all the generated headers.
   if module.type == 'cc_library_static':
     module.export_generated_headers = module.generated_headers