Merge changes Ic8ee9c87,If0193d54,Iab86261a,Ic7b7eb85,I72bbbec7, ...

* changes:
  gn2bp: target.name does not include toolchain anymore
  gn2bp: remove unused toolchain property
  gn2bp: fix host and device support properties
  gn2bp: add device_supported property
  gn2bp: use proper target annotation
  gn2bp: toolchain propery is always present
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 9e183fe..2821a8c 100644
--- a/tools/gn2bp/Android.bp.swp
+++ b/tools/gn2bp/Android.bp.swp
@@ -117,6 +117,7 @@
 // GN: //base/allocator/partition_allocator:partition_alloc
 cc_library_static {
     name: "cronet_aml_base_allocator_partition_allocator_partition_alloc",
+    host_supported: true,
     generated_headers: [
         "cronet_aml_base_allocator_partition_allocator_chromecast_buildflags",
         "cronet_aml_base_allocator_partition_allocator_chromeos_buildflags",
@@ -166,9 +167,9 @@
         "buildtools/third_party/libc++/trunk/include",
         "buildtools/third_party/libc++abi/trunk/include",
         "third_party/android_ndk/sources/android/cpufeatures/",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
     arch: {
@@ -844,10 +845,6 @@
         "base/version.cc",
         "base/vlog.cc",
     ],
-    shared_libs: [
-        "libandroid",
-        "liblog",
-    ],
     static_libs: [
         "cronet_aml_base_allocator_partition_allocator_partition_alloc",
         "cronet_aml_base_base_static",
@@ -862,6 +859,7 @@
         "cronet_aml_third_party_libevent_libevent",
         "cronet_aml_third_party_modp_b64_modp_b64",
     ],
+    host_supported: true,
     generated_headers: [
         "cronet_aml_base_allocator_buildflags",
         "cronet_aml_base_allocator_partition_allocator_chromecast_buildflags",
@@ -970,14 +968,22 @@
         "third_party/boringssl/src/include/",
         "third_party/icu/source/common/",
         "third_party/icu/source/i18n/",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include",
-        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
     ],
     header_libs: [
         "jni_headers",
     ],
     cpp_std: "c++20",
+    target: {
+        android: {
+            shared_libs: [
+                "libandroid",
+                "liblog",
+            ],
+        },
+    },
 }
 
 // GN: //base:base_jni_headers
@@ -1251,6 +1257,7 @@
     srcs: [
         "base/base_switches.cc",
     ],
+    host_supported: true,
     generated_headers: [
         "cronet_aml_build_chromeos_buildflags",
     ],
@@ -1289,9 +1296,9 @@
         "buildtools/third_party/libc++/",
         "buildtools/third_party/libc++/trunk/include",
         "buildtools/third_party/libc++abi/trunk/include",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
 }
@@ -1587,6 +1594,7 @@
         "base/third_party/double_conversion/double-conversion/string-to-double.cc",
         "base/third_party/double_conversion/double-conversion/strtod.cc",
     ],
+    host_supported: true,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -1619,9 +1627,9 @@
         "buildtools/third_party/libc++/",
         "buildtools/third_party/libc++/trunk/include",
         "buildtools/third_party/libc++abi/trunk/include",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
 }
@@ -1632,6 +1640,7 @@
     srcs: [
         "base/third_party/dynamic_annotations/dynamic_annotations.c",
     ],
+    host_supported: true,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -1662,9 +1671,9 @@
         "buildtools/third_party/libc++/",
         "buildtools/third_party/libc++/trunk/include",
         "buildtools/third_party/libc++abi/trunk/include",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
 }
@@ -1676,6 +1685,8 @@
         "base/third_party/symbolize/demangle.cc",
         "base/third_party/symbolize/symbolize.cc",
     ],
+    host_supported: true,
+    device_supported: false,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -1724,6 +1735,8 @@
         "base/third_party/xdg_mime/xdgmimemagic.c",
         "base/third_party/xdg_mime/xdgmimeparent.c",
     ],
+    host_supported: true,
+    device_supported: false,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -1764,6 +1777,8 @@
     srcs: [
         "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.cc",
     ],
+    host_supported: true,
+    device_supported: false,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -2562,10 +2577,6 @@
         "crypto/unexportable_key.cc",
         "crypto/unexportable_key_metrics.cc",
     ],
-    shared_libs: [
-        "libandroid",
-        "liblog",
-    ],
     static_libs: [
         "cronet_aml_base_allocator_partition_allocator_partition_alloc",
         "cronet_aml_base_base",
@@ -2581,6 +2592,7 @@
         "cronet_aml_third_party_libevent_libevent",
         "cronet_aml_third_party_modp_b64_modp_b64",
     ],
+    host_supported: true,
     generated_headers: [
         "cronet_aml_build_chromeos_buildflags",
         "cronet_aml_components_nacl_common_buildflags",
@@ -2628,11 +2640,19 @@
         "buildtools/third_party/libc++abi/trunk/include",
         "third_party/abseil-cpp/",
         "third_party/boringssl/src/include/",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
+    target: {
+        android: {
+            shared_libs: [
+                "libandroid",
+                "liblog",
+            ],
+        },
+    },
 }
 
 // GN: //gn:default_deps
@@ -5126,6 +5146,7 @@
 // GN: //third_party/boringssl:boringssl
 cc_library_static {
     name: "cronet_aml_third_party_boringssl_boringssl",
+    host_supported: true,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -5163,9 +5184,9 @@
         "buildtools/third_party/libc++/trunk/include",
         "buildtools/third_party/libc++abi/trunk/include",
         "third_party/boringssl/src/include/",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
     arch: {
@@ -5743,9 +5764,9 @@
     ],
 }
 
-// GN: //third_party/boringssl:boringssl_asm
+// GN: //third_party/boringssl:boringssl_asm(//build/toolchain/android:android_clang_x86)
 filegroup {
-    name: "cronet_aml_third_party_boringssl_boringssl_asm_x86",
+    name: "cronet_aml_third_party_boringssl_boringssl_asm___build_toolchain_android_android_clang_x86__x86",
     srcs: [
         "third_party/boringssl/linux-x86_64/crypto/chacha/chacha-x86_64.S",
         "third_party/boringssl/linux-x86_64/crypto/cipher_extra/aes128gcmsiv-x86_64.S",
@@ -6115,6 +6136,7 @@
     static_libs: [
         "cronet_aml_third_party_icu_icuuc_private",
     ],
+    host_supported: true,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -6159,9 +6181,9 @@
         "buildtools/third_party/libc++abi/trunk/include",
         "third_party/icu/source/common/",
         "third_party/icu/source/i18n/",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
     rtti: true,
@@ -6372,6 +6394,7 @@
         "third_party/icu/source/common/wintz.cpp",
         "third_party/icu/source/stubdata/stubdata.cpp",
     ],
+    host_supported: true,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -6419,9 +6442,9 @@
         "buildtools/third_party/libc++abi/trunk/include",
         "third_party/icu/source/common/",
         "third_party/icu/source/i18n/",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
     rtti: true,
@@ -6451,6 +6474,7 @@
         "third_party/libevent/signal.c",
         "third_party/libevent/strlcpy.c",
     ],
+    host_supported: true,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -6484,9 +6508,9 @@
         "buildtools/third_party/libc++abi/trunk/include",
         "third_party/libevent/android/",
         "third_party/libevent/linux/",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
 }
@@ -6636,6 +6660,7 @@
     srcs: [
         "third_party/modp_b64/modp_b64.cc",
     ],
+    host_supported: true,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -6668,9 +6693,9 @@
         "buildtools/third_party/libc++/",
         "buildtools/third_party/libc++/trunk/include",
         "buildtools/third_party/libc++abi/trunk/include",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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",
 }
@@ -6701,6 +6726,7 @@
         "third_party/zlib/uncompr.c",
         "third_party/zlib/zutil.c",
     ],
+    host_supported: true,
     defaults: [
         "cronet_aml_defaults",
     ],
@@ -6743,9 +6769,9 @@
         "buildtools/third_party/libc++abi/trunk/include",
         "third_party/android_ndk/sources/android/cpufeatures/",
         "third_party/zlib/",
+        "third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include",
         "build/linux/debian_bullseye_amd64-sysroot/usr/include/x86_64-linux-gnu",
         "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 eb44f72..2479813 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -339,7 +339,7 @@
     self.gn_target = gn_target
     self.name = name
     self.srcs = set()
-    self.comment = 'GN: ' + gn_utils.label_without_toolchain(gn_target)
+    self.comment = 'GN: ' + gn_target
     self.shared_libs = set()
     self.static_libs = set()
     self.whole_static_libs = set()
@@ -347,6 +347,7 @@
     self.tools = set()
     self.cmd = None
     self.host_supported = False
+    self.device_supported = True
     self.vendor_available = False
     self.init_rc = set()
     self.out = set()
@@ -400,6 +401,8 @@
     self._output_field(output, 'cmd', sort=False)
     if self.host_supported:
       self._output_field(output, 'host_supported')
+    if not self.device_supported:
+      self._output_field(output, 'device_supported')
     if self.vendor_available:
       self._output_field(output, 'vendor_available')
     self._output_field(output, 'init_rc')
@@ -488,11 +491,7 @@
 
 def label_to_module_name(label):
   """Turn a GN label (e.g., //:perfetto_tests) into a module name."""
-  # If the label is explicibly listed in the default target list, don't prefix
-  # its name and return just the target name. This is so tools like
-  # "traceconv" stay as such in the Android tree.
-  label_without_toolchain = gn_utils.label_without_toolchain(label)
-  module = re.sub(r'^//:?', '', label_without_toolchain)
+  module = re.sub(r'^//:?', '', label)
   module = re.sub(r'[^a-zA-Z0-9_]', '_', module)
 
   # If it's required to support multi toolchain for more targets, it's better to avoid hardcoding.
@@ -1068,13 +1067,11 @@
   target = gn.get_target(gn_target_name)
   log.info('create modules for %s (%s)', target.name, target.type)
 
-  name_without_toolchain = gn_utils.label_without_toolchain(target.name)
   if target.type == 'executable':
-    if target.toolchain == gn_utils.HOST_TOOLCHAIN:
-      module_type = 'cc_binary_host'
-    elif target.testonly:
+    if target.testonly:
       module_type = 'cc_test'
     else:
+      # Can be used for both host and device targets.
       module_type = 'cc_binary'
     module = Module(module_type, bp_module_name, gn_target_name)
   elif target.type == 'static_library':
@@ -1094,10 +1091,10 @@
   elif target.type == 'action':
     if 'gen_amalgamated_sql_metrics' in target.name:
       module = create_amalgamated_sql_metrics_module(blueprint, target)
-    elif re.match('.*gen_cc_.*_descriptor$', name_without_toolchain):
+    elif re.match('.*gen_cc_.*_descriptor$', target.name):
       module = create_cc_proto_descriptor_module(blueprint, target)
     elif target.type == 'action' and \
-        name_without_toolchain == gn_utils.GEN_VERSION_TARGET:
+        target.name == gn_utils.GEN_VERSION_TARGET:
       module = create_gen_version_module(blueprint, target, bp_module_name)
     else:
       module = create_action_module(blueprint, target)
@@ -1116,7 +1113,6 @@
     raise Error('Unknown target %s (%s)' % (target.name, target.type))
 
   blueprint.add_module(module)
-  module.host_supported = (name_without_toolchain in target_host_supported)
   module.init_rc = target_initrc.get(target.name, [])
   module.srcs.update(
       gn_utils.label_to_path(src)
@@ -1160,6 +1156,9 @@
 
   module_is_compiled = module.type not in ('genrule', 'filegroup')
   if module_is_compiled:
+    module.host_supported = target.host_supported()
+    module.device_supported = target.device_supported()
+
     # Don't try to inject library/source dependencies into genrules or
     # filegroups because they are not compiled in the traditional sense.
     module.defaults = [defaults_module]
@@ -1191,8 +1190,8 @@
   for dep_name in all_deps:
     # |builtin_deps| override GN deps with Android-specific ones. See the
     # config in the top of this file.
-    if gn_utils.label_without_toolchain(dep_name) in builtin_deps:
-      builtin_deps[gn_utils.label_without_toolchain(dep_name)](module)
+    if dep_name in builtin_deps:
+      builtin_deps[dep_name](module)
       continue
 
     dep_module = create_modules_from_target(blueprint, gn, dep_name)
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index b3cda41..27fbdb2 100644
--- a/tools/gn2bp/gn_utils.py
+++ b/tools/gn2bp/gn_utils.py
@@ -29,8 +29,6 @@
 
 BUILDFLAGS_TARGET = '//gn:gen_buildflags'
 GEN_VERSION_TARGET = '//src/base:version_gen_h'
-TARGET_TOOLCHAIN = '//gn/standalone/toolchain:gcc_like_host'
-HOST_TOOLCHAIN = '//gn/standalone/toolchain:gcc_like_host'
 LINKER_UNIT_TYPES = ('executable', 'shared_library', 'static_library')
 
 # TODO(primiano): investigate these, they require further componentization.
@@ -155,6 +153,12 @@
       self.is_finalized = False
       self.arch = dict()
 
+    def host_supported(self):
+      return 'host' in self.arch
+
+    def device_supported(self):
+      return any([name.startswith('android') for name in self.arch.keys()])
+
     def __lt__(self, other):
       if isinstance(other, self.__class__):
         return self.name < other.name
@@ -223,17 +227,14 @@
     return target.type == 'group' and re.match('.*_java$', target.name)
 
   def _get_arch(self, toolchain):
-    if toolchain is None:
-      # TODO: throw an exception instead of defaulting to x86_64.
-      return 'x86_64'
-    elif toolchain == '//build/toolchain/android:android_clang_x86':
-      return 'x86'
+    if toolchain == '//build/toolchain/android:android_clang_x86':
+      return 'android_x86'
     elif toolchain == '//build/toolchain/android:android_clang_x64':
-      return 'x86_64'
+      return 'android_x86_64'
     elif toolchain == '//build/toolchain/android:android_clang_arm':
-      return 'arm'
+      return 'android_arm'
     elif toolchain == '//build/toolchain/android:android_clang_arm64':
-      return 'arm64'
+      return 'android_arm64'
     else:
       return 'host'
 
@@ -259,7 +260,7 @@
     target_name = label_without_toolchain(gn_target_name)
     target = self.all_targets.get(target_name)
     desc = gn_desc[gn_target_name]
-    arch = self._get_arch(desc.get('toolchain', None))
+    arch = self._get_arch(desc['toolchain'])
     if target is None:
       target = GnParser.Target(target_name, desc['type'])
       self.all_targets[target_name] = target
@@ -270,8 +271,6 @@
       return target  # Target already processed.
 
     target.testonly = desc.get('testonly', False)
-    # TODO: remove toolchain from Target object
-    target.toolchain = desc.get('toolchain', None)
 
     proto_target_type, proto_desc = self.get_proto_target_type(gn_desc, gn_target_name)
     if proto_target_type is not None: