gn2bp: use android proto library

Only add shared_libs to linker unit targets; proto genrules also include
a libprotobuf dependency.

Test: //net:net
Change-Id: I1e00ab74383c9bd0e71b2435e9cf3724318f8434
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 85436c1..54d8f85 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -2633,7 +2633,6 @@
         "cronet_aml_net_uri_template",
         "cronet_aml_third_party_boringssl_boringssl",
         "cronet_aml_third_party_brotli_dec",
-        "cronet_aml_third_party_protobuf_protobuf_lite",
         "cronet_aml_third_party_zlib_zlib",
         "cronet_aml_url_url",
     ],
@@ -3391,7 +3390,6 @@
         "cronet_aml_base_base",
         "cronet_aml_net_uri_template",
         "cronet_aml_third_party_boringssl_boringssl",
-        "cronet_aml_third_party_protobuf_protobuf_lite",
         "cronet_aml_third_party_zlib_zlib",
         "cronet_aml_url_url",
     ],
@@ -4933,214 +4931,11 @@
     cpp_std: "c++20",
 }
 
-// GN: //third_party/protobuf:protobuf_full
-cc_library_static {
-    name: "cronet_aml_third_party_protobuf_protobuf_full",
-    srcs: [
-        "third_party/protobuf/src/google/protobuf/any.cc",
-        "third_party/protobuf/src/google/protobuf/any.pb.cc",
-        "third_party/protobuf/src/google/protobuf/any_lite.cc",
-        "third_party/protobuf/src/google/protobuf/api.pb.cc",
-        "third_party/protobuf/src/google/protobuf/arena.cc",
-        "third_party/protobuf/src/google/protobuf/arenastring.cc",
-        "third_party/protobuf/src/google/protobuf/arenaz_sampler.cc",
-        "third_party/protobuf/src/google/protobuf/compiler/importer.cc",
-        "third_party/protobuf/src/google/protobuf/compiler/parser.cc",
-        "third_party/protobuf/src/google/protobuf/descriptor.cc",
-        "third_party/protobuf/src/google/protobuf/descriptor.pb.cc",
-        "third_party/protobuf/src/google/protobuf/descriptor_database.cc",
-        "third_party/protobuf/src/google/protobuf/duration.pb.cc",
-        "third_party/protobuf/src/google/protobuf/dynamic_message.cc",
-        "third_party/protobuf/src/google/protobuf/empty.pb.cc",
-        "third_party/protobuf/src/google/protobuf/extension_set.cc",
-        "third_party/protobuf/src/google/protobuf/extension_set_heavy.cc",
-        "third_party/protobuf/src/google/protobuf/field_mask.pb.cc",
-        "third_party/protobuf/src/google/protobuf/generated_enum_util.cc",
-        "third_party/protobuf/src/google/protobuf/generated_message_bases.cc",
-        "third_party/protobuf/src/google/protobuf/generated_message_reflection.cc",
-        "third_party/protobuf/src/google/protobuf/generated_message_tctable_full.cc",
-        "third_party/protobuf/src/google/protobuf/generated_message_tctable_lite.cc",
-        "third_party/protobuf/src/google/protobuf/generated_message_util.cc",
-        "third_party/protobuf/src/google/protobuf/implicit_weak_message.cc",
-        "third_party/protobuf/src/google/protobuf/inlined_string_field.cc",
-        "third_party/protobuf/src/google/protobuf/io/coded_stream.cc",
-        "third_party/protobuf/src/google/protobuf/io/gzip_stream.cc",
-        "third_party/protobuf/src/google/protobuf/io/io_win32.cc",
-        "third_party/protobuf/src/google/protobuf/io/printer.cc",
-        "third_party/protobuf/src/google/protobuf/io/strtod.cc",
-        "third_party/protobuf/src/google/protobuf/io/tokenizer.cc",
-        "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.cc",
-        "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc",
-        "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
-        "third_party/protobuf/src/google/protobuf/map.cc",
-        "third_party/protobuf/src/google/protobuf/map_field.cc",
-        "third_party/protobuf/src/google/protobuf/message.cc",
-        "third_party/protobuf/src/google/protobuf/message_lite.cc",
-        "third_party/protobuf/src/google/protobuf/parse_context.cc",
-        "third_party/protobuf/src/google/protobuf/reflection_ops.cc",
-        "third_party/protobuf/src/google/protobuf/repeated_field.cc",
-        "third_party/protobuf/src/google/protobuf/repeated_ptr_field.cc",
-        "third_party/protobuf/src/google/protobuf/service.cc",
-        "third_party/protobuf/src/google/protobuf/source_context.pb.cc",
-        "third_party/protobuf/src/google/protobuf/struct.pb.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/bytestream.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/common.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/int128.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/status.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/statusor.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/stringpiece.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/stringprintf.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/structurally_valid.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/strutil.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/substitute.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/time.cc",
-        "third_party/protobuf/src/google/protobuf/text_format.cc",
-        "third_party/protobuf/src/google/protobuf/timestamp.pb.cc",
-        "third_party/protobuf/src/google/protobuf/type.pb.cc",
-        "third_party/protobuf/src/google/protobuf/unknown_field_set.cc",
-        "third_party/protobuf/src/google/protobuf/util/delimited_message_util.cc",
-        "third_party/protobuf/src/google/protobuf/util/field_comparator.cc",
-        "third_party/protobuf/src/google/protobuf/util/field_mask_util.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/datapiece.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/default_value_objectwriter.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/error_listener.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/field_mask_utility.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/json_escaping.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/json_objectwriter.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/json_stream_parser.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/object_writer.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/proto_writer.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/protostream_objectsource.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/type_info.cc",
-        "third_party/protobuf/src/google/protobuf/util/internal/utility.cc",
-        "third_party/protobuf/src/google/protobuf/util/json_util.cc",
-        "third_party/protobuf/src/google/protobuf/util/message_differencer.cc",
-        "third_party/protobuf/src/google/protobuf/util/time_util.cc",
-        "third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc",
-        "third_party/protobuf/src/google/protobuf/wire_format.cc",
-        "third_party/protobuf/src/google/protobuf/wire_format_lite.cc",
-        "third_party/protobuf/src/google/protobuf/wrappers.pb.cc",
-    ],
-    static_libs: [
-        "cronet_aml_third_party_zlib_zlib",
-    ],
-    defaults: [
-        "cronet_aml_defaults",
-    ],
-    cflags: [
-        "-DCR_CLANG_REVISION=\"llvmorg-16-init-8697-g60809cd2-1\"",
-        "-DCR_LIBCXX_REVISION=47b31179d10646029c260702650a25d24f555acc",
-        "-DCR_SYSROOT_KEY=20220331T153654Z-0",
-        "-DDCHECK_ALWAYS_ON=1",
-        "-DDYNAMIC_ANNOTATIONS_ENABLED=1",
-        "-DGOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE=0",
-        "-DGOOGLE_PROTOBUF_NO_RTTI",
-        "-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
-        "-DHAVE_PTHREAD",
-        "-DHAVE_ZLIB",
-        "-DUSE_AURA=1",
-        "-DUSE_OZONE=1",
-        "-DUSE_UDEV",
-        "-D_DEBUG",
-        "-D_FILE_OFFSET_BITS=64",
-        "-D_GNU_SOURCE",
-        "-D_LARGEFILE64_SOURCE",
-        "-D_LARGEFILE_SOURCE",
-        "-D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED=1",
-        "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
-        "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-    ],
-    local_include_dirs: [
-        "./",
-        "buildtools/third_party/libc++/",
-        "buildtools/third_party/libc++/trunk/include",
-        "buildtools/third_party/libc++abi/trunk/include",
-        "third_party/protobuf/src/",
-        "third_party/zlib/",
-        "build/linux/debian_bullseye_amd64-sysroot/usr/include",
-    ],
-    cpp_std: "c++20",
-}
-
-// GN: //third_party/protobuf:protobuf_lite
-cc_library_static {
-    name: "cronet_aml_third_party_protobuf_protobuf_lite",
-    srcs: [
-        "third_party/protobuf/src/google/protobuf/any_lite.cc",
-        "third_party/protobuf/src/google/protobuf/arena.cc",
-        "third_party/protobuf/src/google/protobuf/arenastring.cc",
-        "third_party/protobuf/src/google/protobuf/arenaz_sampler.cc",
-        "third_party/protobuf/src/google/protobuf/extension_set.cc",
-        "third_party/protobuf/src/google/protobuf/generated_enum_util.cc",
-        "third_party/protobuf/src/google/protobuf/generated_message_tctable_lite.cc",
-        "third_party/protobuf/src/google/protobuf/generated_message_util.cc",
-        "third_party/protobuf/src/google/protobuf/implicit_weak_message.cc",
-        "third_party/protobuf/src/google/protobuf/inlined_string_field.cc",
-        "third_party/protobuf/src/google/protobuf/io/coded_stream.cc",
-        "third_party/protobuf/src/google/protobuf/io/io_win32.cc",
-        "third_party/protobuf/src/google/protobuf/io/strtod.cc",
-        "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.cc",
-        "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc",
-        "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc",
-        "third_party/protobuf/src/google/protobuf/map.cc",
-        "third_party/protobuf/src/google/protobuf/message_lite.cc",
-        "third_party/protobuf/src/google/protobuf/parse_context.cc",
-        "third_party/protobuf/src/google/protobuf/repeated_field.cc",
-        "third_party/protobuf/src/google/protobuf/repeated_ptr_field.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/bytestream.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/common.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/int128.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/status.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/statusor.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/stringpiece.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/stringprintf.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/structurally_valid.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/strutil.cc",
-        "third_party/protobuf/src/google/protobuf/stubs/time.cc",
-        "third_party/protobuf/src/google/protobuf/wire_format_lite.cc",
-    ],
-    shared_libs: [
-        "liblog",
-    ],
-    defaults: [
-        "cronet_aml_defaults",
-    ],
-    cflags: [
-        "-DANDROID",
-        "-DANDROID_NDK_VERSION_ROLL=r23_1",
-        "-DCR_CLANG_REVISION=\"llvmorg-16-init-8697-g60809cd2-1\"",
-        "-DCR_LIBCXX_REVISION=47b31179d10646029c260702650a25d24f555acc",
-        "-DDCHECK_ALWAYS_ON=1",
-        "-DDYNAMIC_ANNOTATIONS_ENABLED=1",
-        "-DGOOGLE_PROTOBUF_INTERNAL_DONATE_STEAL_INLINE=0",
-        "-DGOOGLE_PROTOBUF_NO_RTTI",
-        "-DGOOGLE_PROTOBUF_NO_STATIC_INITIALIZER",
-        "-DHAVE_PTHREAD",
-        "-DHAVE_SYS_UIO_H",
-        "-D_DEBUG",
-        "-D_GNU_SOURCE",
-        "-D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED=1",
-        "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
-        "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
-        "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS",
-    ],
-    local_include_dirs: [
-        "./",
-        "buildtools/third_party/libc++/",
-        "buildtools/third_party/libc++/trunk/include",
-        "buildtools/third_party/libc++abi/trunk/include",
-        "third_party/protobuf/src/",
-        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
-    ],
-    cpp_std: "c++20",
-}
-
 // GN: //third_party/zlib:zlib
 cc_library_static {
     name: "cronet_aml_third_party_zlib_zlib",
     srcs: [
+        ":cronet_aml_third_party_android_ndk_cpu_features",
         ":cronet_aml_third_party_zlib_zlib_adler32_simd",
         ":cronet_aml_third_party_zlib_zlib_common_headers",
         ":cronet_aml_third_party_zlib_zlib_crc32_simd",
@@ -5167,26 +4962,22 @@
     ],
     cflags: [
         "-DADLER32_SIMD_SSSE3",
+        "-DANDROID",
+        "-DANDROID_NDK_VERSION_ROLL=r23_1",
         "-DCRC32_SIMD_SSE42_PCLMUL",
         "-DCR_CLANG_REVISION=\"llvmorg-16-init-8697-g60809cd2-1\"",
         "-DCR_LIBCXX_REVISION=47b31179d10646029c260702650a25d24f555acc",
-        "-DCR_SYSROOT_KEY=20220331T153654Z-0",
         "-DDCHECK_ALWAYS_ON=1",
         "-DDEFLATE_SLIDE_HASH_SSE2",
         "-DDYNAMIC_ANNOTATIONS_ENABLED=1",
+        "-DHAVE_SYS_UIO_H",
         "-DINFLATE_CHUNK_READ_64LE",
         "-DINFLATE_CHUNK_SIMD_SSE2",
-        "-DUSE_AURA=1",
-        "-DUSE_OZONE=1",
-        "-DUSE_UDEV",
         "-DX86_NOT_WINDOWS",
         "-DZLIB_DEBUG",
         "-DZLIB_IMPLEMENTATION",
         "-D_DEBUG",
-        "-D_FILE_OFFSET_BITS=64",
         "-D_GNU_SOURCE",
-        "-D_LARGEFILE64_SOURCE",
-        "-D_LARGEFILE_SOURCE",
         "-D_LIBCPP_AVAILABILITY_CUSTOM_VERBOSE_ABORT_PROVIDED=1",
         "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
         "-D_LIBCPP_ENABLE_ASSERTIONS_DEFAULT=1",
@@ -5199,8 +4990,9 @@
         "buildtools/third_party/libc++/",
         "buildtools/third_party/libc++/trunk/include",
         "buildtools/third_party/libc++abi/trunk/include",
+        "third_party/android_ndk/sources/android/cpufeatures/",
         "third_party/zlib/",
-        "build/linux/debian_bullseye_amd64-sysroot/usr/include",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
     ],
     cpp_std: "c++20",
 }
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index db2691d..539817b 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -119,12 +119,13 @@
   elif module.host_supported:
     module.host.static_libs.add('libprotobuf-cpp-full')
     module.android.shared_libs.add('libprotobuf-cpp-full')
-  else:
+  elif module.type not in ['genrule', 'filegroup']:
     module.shared_libs.add('libprotobuf-cpp-full')
 
 
 def enable_protobuf_lite(module):
-  module.shared_libs.add('libprotobuf-cpp-lite')
+  if module.type not in ['genrule', 'filegroup']:
+    module.shared_libs.add('libprotobuf-cpp-lite')
 
 
 def enable_protoc_lib(module):
@@ -199,18 +200,10 @@
         lambda x: None,
     '//gn:gtest_main':
         lambda x: None,
-    '//gn:protoc':
-        lambda x: None,
     '//gn:gtest_and_gmock':
         enable_gtest_and_gmock,
     '//gn:libunwind':
         enable_libunwind,
-    '//gn:protobuf_full':
-        enable_protobuf_full,
-    '//gn:protobuf_lite':
-        enable_protobuf_lite,
-    '//gn:protoc_lib':
-        enable_protoc_lib,
     '//gn:libunwindstack':
         enable_libunwindstack,
     '//gn:sqlite':
@@ -223,6 +216,12 @@
         enable_bionic_libc_platform_headers_on_android,
     '//third_party/protobuf:protoc':
       lambda x: None,
+    '//third_party/protobuf:protobuf_full':
+        enable_protobuf_full,
+    '//third_party/protobuf:protobuf_lite':
+        enable_protobuf_lite,
+    '//third_party/protobuf:protoc_lib':
+        enable_protoc_lib,
 }
 
 # ----------------------------------------------------------------------------