gn2bp: fix host and device support properties
With proper arch support, we now have all the information to do this
properly.
Test: //components/cronet/android:cronet
Change-Id: Iab86261a6a4d775ba5f3b12b2487b7c27096580d
diff --git a/tools/gn2bp/Android.bp.swp b/tools/gn2bp/Android.bp.swp
index 9e183fe..ff3fc0e 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",
@@ -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",
@@ -978,6 +976,14 @@
"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",
],
@@ -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",
],
@@ -1632,6 +1640,7 @@
srcs: [
"base/third_party/dynamic_annotations/dynamic_annotations.c",
],
+ host_supported: true,
defaults: [
"cronet_aml_defaults",
],
@@ -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",
@@ -2633,6 +2645,14 @@
"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",
],
@@ -6115,6 +6136,7 @@
static_libs: [
"cronet_aml_third_party_icu_icuuc_private",
],
+ host_supported: true,
defaults: [
"cronet_aml_defaults",
],
@@ -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",
],
@@ -6451,6 +6474,7 @@
"third_party/libevent/signal.c",
"third_party/libevent/strlcpy.c",
],
+ host_supported: true,
defaults: [
"cronet_aml_defaults",
],
@@ -6636,6 +6660,7 @@
srcs: [
"third_party/modp_b64/modp_b64.cc",
],
+ host_supported: true,
defaults: [
"cronet_aml_defaults",
],
@@ -6701,6 +6726,7 @@
"third_party/zlib/uncompr.c",
"third_party/zlib/zutil.c",
],
+ host_supported: true,
defaults: [
"cronet_aml_defaults",
],
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 32ac640..ce6d1ac 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -1073,11 +1073,10 @@
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':
@@ -1119,7 +1118,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)
@@ -1163,6 +1161,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]
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index f051421..d1d8319 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