gn2bp: Convert source_set to cc_object
* Convert every source_set into a cc_object.
Test: m cronet_aml_components_cronet_android_cronet
Change-Id: Iaa123d1b348e8809fbfa4acc1d888bb6d0d0989c
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index 880a9d0..6d2bf17 100644
--- a/tools/gn2bp/gn_utils.py
+++ b/tools/gn2bp/gn_utils.py
@@ -29,7 +29,7 @@
BUILDFLAGS_TARGET = '//gn:gen_buildflags'
GEN_VERSION_TARGET = '//src/base:version_gen_h'
-LINKER_UNIT_TYPES = ('executable', 'shared_library', 'static_library')
+LINKER_UNIT_TYPES = ('executable', 'shared_library', 'static_library', 'source_set')
# TODO(primiano): investigate these, they require further componentization.
ODR_VIOLATION_IGNORE_TARGETS = {
@@ -105,6 +105,7 @@
self.include_dirs = set()
self.deps = set()
self.transitive_static_libs_deps = set()
+ self.source_set_deps = set()
def __init__(self, name, type):
@@ -181,7 +182,7 @@
'libs', 'proto_paths'):
self.__dict__[key].update(other.__dict__.get(key, []))
- for key_in_arch in ('cflags', 'defines', 'include_dirs'):
+ for key_in_arch in ('cflags', 'defines', 'include_dirs', 'source_set_deps'):
self.arch[arch].__dict__[key_in_arch].update(
other.arch[arch].__dict__.get(key_in_arch, []))
@@ -194,18 +195,13 @@
return
self.is_finalized = True
- # There are targets that depend on source_set only in specific arch.
- # Currently, source_set is converted to cc_defaults and defaults can not be target specific
- # So, skip extracting common part and keep all data for each arch
- if self.type == 'source_set':
- return
-
# Target contains the intersection of arch-dependent properties
self.sources = set.intersection(*[arch.sources for arch in self.arch.values()])
self.cflags = set.intersection(*[arch.cflags for arch in self.arch.values()])
self.defines = set.intersection(*[arch.defines for arch in self.arch.values()])
self.include_dirs = set.intersection(*[arch.include_dirs for arch in self.arch.values()])
self.deps.update(set.intersection(*[arch.deps for arch in self.arch.values()]))
+ self.source_set_deps.update(set.intersection(*[arch.source_set_deps for arch in self.arch.values()]))
# Deduplicate arch-dependent properties
for arch in self.arch.keys():
@@ -214,6 +210,7 @@
self.arch[arch].defines -= self.defines
self.arch[arch].include_dirs -= self.include_dirs
self.arch[arch].deps -= self.deps
+ self.arch[arch].source_set_deps -= self.source_set_deps
def __init__(self):
@@ -352,8 +349,7 @@
target.arch[arch].include_dirs.update(desc.get('include_dirs', []))
if "-frtti" in target.arch[arch].cflags:
target.rtti = True
- if target.type == "source_set":
- target.type = "static_library"
+
# Recurse in dependencies.
for gn_dep_name in desc.get('deps', []):
dep = self.parse_gn_desc(gn_desc, gn_dep_name)
@@ -363,11 +359,8 @@
target.proto_paths.update(dep.proto_paths)
target.transitive_proto_deps.update(dep.transitive_proto_deps)
elif dep.type == 'source_set':
- target.source_set_deps.add(dep.name)
- if "-frtti" in target.arch[arch].cflags:
- # This must not be propagated upward as it effects all of the dependencies
- target.arch[arch].cflags -= {"-frtti"}
- target.update(dep, arch) # Bubble up source set's cflags/ldflags etc.
+ target.arch[arch].source_set_deps.add(dep.name)
+ target.arch[arch].source_set_deps.update(dep.arch[arch].source_set_deps)
elif dep.type == 'group':
target.update(dep, arch) # Bubble up groups's cflags/ldflags etc.
elif dep.type in ['action', 'action_foreach', 'copy']:
@@ -382,6 +375,9 @@
#print(dep.name, target.deps)
pass
+ # Source set bubble up transitive source sets but can't be combined with this
+ # if they are combined then source sets will bubble up static libraries
+ # while we only want to have source sets bubble up only source sets.
if dep.type == 'static_library':
# Bubble up static_libs. Necessary, since soong does not propagate
# static_libs up the build tree.
@@ -403,7 +399,8 @@
log.debug('Adding java sources for %s', dep.name)
java_srcs = [src for src in dep.inputs if _is_java_source(src)]
self.java_sources.update(java_srcs)
-
+ #if target.name == "//build/config:executable_deps":
+ #print(target.name, arch, target.arch[arch].source_set_deps)
return target
def get_proto_exports(self, proto_desc):