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
This commit is contained in:
Mohannad Farrag
2022-11-23 19:52:41 +00:00
parent d7e03f2ddf
commit 7f29d836a7
3 changed files with 8447 additions and 2073 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -113,6 +113,10 @@ cflag_allowlist = [
"-mpclmul", "-mpclmul",
# needed for zlib:zlib # needed for zlib:zlib
"-mssse3", "-mssse3",
# needed for zlib:zlib
"-msse3",
# needed for zlib:zlib
"-msse4.2",
] ]
# Additional arguments to apply to Android.bp rules. # Additional arguments to apply to Android.bp rules.
@@ -388,6 +392,20 @@ class Module(object):
def is_compiled(self): def is_compiled(self):
return self.type not in ('genrule', 'filegroup', 'cc_defaults') return self.type not in ('genrule', 'filegroup', 'cc_defaults')
def has_input_files(self):
for target in self.target.values():
if len(target.srcs) > 0:
return True
return len(self.srcs) > 0 or any([len(target.srcs) > 0 for target in self.target.values()])
def merge_key(self, parent_key, dep_module, archs_allowed, child_key = None):
if not child_key:
child_key = parent_key
self.__dict__[parent_key].update(dep_module.__dict__[child_key])
for arch_name, arch in dep_module.target.items():
if arch_name in archs_allowed:
self.target[arch_name].__dict__[parent_key].update(
dep_module.target[arch_name].__dict__[child_key])
class Blueprint(object): class Blueprint(object):
"""In-memory representation of an Android.bp file.""" """In-memory representation of an Android.bp file."""
@@ -838,7 +856,7 @@ def create_modules_from_target(blueprint, gn, gn_target_name):
elif target.type == 'shared_library': elif target.type == 'shared_library':
module = Module('cc_library_shared', bp_module_name, gn_target_name) module = Module('cc_library_shared', bp_module_name, gn_target_name)
elif target.type == 'source_set': elif target.type == 'source_set':
module = Module('cc_defaults', bp_module_name, gn_target_name) module = Module('cc_object', bp_module_name, gn_target_name)
elif target.type == 'group': elif target.type == 'group':
# "group" targets are resolved recursively by gn_utils.get_target(). # "group" targets are resolved recursively by gn_utils.get_target().
# There's nothing we need to do at this level for them. # There's nothing we need to do at this level for them.
@@ -923,6 +941,8 @@ def create_modules_from_target(blueprint, gn, gn_target_name):
dep_module = create_modules_from_target(blueprint, gn, dep_name) dep_module = create_modules_from_target(blueprint, gn, dep_name)
if dep_module is None:
continue
# TODO: Proper dependency check for genrule. # TODO: Proper dependency check for genrule.
# Currently, only propagating genrule dependencies. # Currently, only propagating genrule dependencies.
# Also, currently, all the dependencies are propagated upwards. # Also, currently, all the dependencies are propagated upwards.
@@ -935,19 +955,23 @@ def create_modules_from_target(blueprint, gn, gn_target_name):
module.genrule_headers.add(dep_module.name) module.genrule_headers.add(dep_module.name)
module.genrule_headers.update(dep_module.genrule_headers) module.genrule_headers.update(dep_module.genrule_headers)
# For cc_defaults, filegroups, and genrule, recurse but don't apply the # For filegroups, and genrule, recurse but don't apply the
# deps. # deps.
if not module.is_compiled(): if not module.is_compiled():
continue continue
if dep_module is None:
continue
if dep_module.type == 'cc_library_shared': if dep_module.type == 'cc_library_shared':
module.shared_libs.add(dep_module.name) module.shared_libs.add(dep_module.name)
elif dep_module.type == 'cc_library_static': elif dep_module.type == 'cc_library_static':
module.static_libs.add(dep_module.name) module.static_libs.add(dep_module.name)
elif dep_module.type == 'cc_defaults': elif dep_module.type == 'cc_object':
module.defaults.append(dep_module.name) module.merge_key('generated_headers', dep_module, target.arch.keys())
if module.type != 'cc_object':
if dep_module.has_input_files():
# Only add it as part of srcs if the dep_module has input files otherwise
# this would throw an error.
module.srcs.add(":" + dep_module.name)
module.merge_key('export_generated_headers', dep_module,
target.arch.keys(), 'generated_headers')
elif dep_module.type == 'genrule': elif dep_module.type == 'genrule':
for arch_name, arch in target.arch.items(): for arch_name, arch in target.arch.items():
if dep_module.name.endswith(arch_name): if dep_module.name.endswith(arch_name):
@@ -955,7 +979,8 @@ def create_modules_from_target(blueprint, gn, gn_target_name):
if dep_module.name.endswith("_gen"): if dep_module.name.endswith("_gen"):
module.srcs.update(dep_module.genrule_srcs) module.srcs.update(dep_module.genrule_srcs)
module.generated_headers.update(dep_module.genrule_headers) module.generated_headers.update(dep_module.genrule_headers)
module.export_generated_headers.update(dep_module.genrule_headers) if module.type != "cc_object":
module.export_generated_headers.update(dep_module.genrule_headers)
elif dep_module.type == 'cc_binary': elif dep_module.type == 'cc_binary':
continue # Ignore executables deps (used by cmdline integration tests). continue # Ignore executables deps (used by cmdline integration tests).
else: else:
@@ -972,7 +997,19 @@ def create_modules_from_target(blueprint, gn, gn_target_name):
else: else:
raise Error('Unsupported arch-specific dependency %s of target %s with type %s' % raise Error('Unsupported arch-specific dependency %s of target %s with type %s' %
(dep_module.name, target.name, dep_module.type)) (dep_module.name, target.name, dep_module.type))
for dep_name in arch.source_set_deps:
dep_module = create_modules_from_target(blueprint, gn, dep_name)
if dep_module.type == 'cc_object':
if module.type != 'cc_object':
# We only want to bubble up cc_objects for modules that are not cc_objects
# otherwise they'd be recompiled and that would cause multiple symbol redefinitions.
if dep_module.has_input_files():
# Only add it as part of srcs if the dep_module has input files otherwise
# this would throw an error.
module.target[arch_name].srcs.add(":" + dep_module.name)
else:
raise Error('Unsupported arch-specific dependency %s of target %s with type %s' %
(dep_module.name, target.name, dep_module.type))
return module return module
def create_java_module(blueprint, gn): def create_java_module(blueprint, gn):
@@ -1014,6 +1051,7 @@ def create_blueprint_for_targets(gn, targets):
'-Wno-ambiguous-reversed-operator', # needed for icui18n '-Wno-ambiguous-reversed-operator', # needed for icui18n
'-Wno-unreachable-code-loop-increment', # needed for icui18n '-Wno-unreachable-code-loop-increment', # needed for icui18n
'-O2', '-O2',
'-fPIC',
] ]
# Chromium builds do not add a dependency for headers found inside the # Chromium builds do not add a dependency for headers found inside the
# sysroot, so they are added globally via defaults. # sysroot, so they are added globally via defaults.

View File

@@ -29,7 +29,7 @@ import sys
BUILDFLAGS_TARGET = '//gn:gen_buildflags' BUILDFLAGS_TARGET = '//gn:gen_buildflags'
GEN_VERSION_TARGET = '//src/base:version_gen_h' 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. # TODO(primiano): investigate these, they require further componentization.
ODR_VIOLATION_IGNORE_TARGETS = { ODR_VIOLATION_IGNORE_TARGETS = {
@@ -105,6 +105,7 @@ class GnParser(object):
self.include_dirs = set() self.include_dirs = set()
self.deps = set() self.deps = set()
self.transitive_static_libs_deps = set() self.transitive_static_libs_deps = set()
self.source_set_deps = set()
def __init__(self, name, type): def __init__(self, name, type):
@@ -181,7 +182,7 @@ class GnParser(object):
'libs', 'proto_paths'): 'libs', 'proto_paths'):
self.__dict__[key].update(other.__dict__.get(key, [])) 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( self.arch[arch].__dict__[key_in_arch].update(
other.arch[arch].__dict__.get(key_in_arch, [])) other.arch[arch].__dict__.get(key_in_arch, []))
@@ -194,18 +195,13 @@ class GnParser(object):
return return
self.is_finalized = True 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 # Target contains the intersection of arch-dependent properties
self.sources = set.intersection(*[arch.sources for arch in self.arch.values()]) 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.cflags = set.intersection(*[arch.cflags for arch in self.arch.values()])
self.defines = set.intersection(*[arch.defines 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.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.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 # Deduplicate arch-dependent properties
for arch in self.arch.keys(): for arch in self.arch.keys():
@@ -214,6 +210,7 @@ class GnParser(object):
self.arch[arch].defines -= self.defines self.arch[arch].defines -= self.defines
self.arch[arch].include_dirs -= self.include_dirs self.arch[arch].include_dirs -= self.include_dirs
self.arch[arch].deps -= self.deps self.arch[arch].deps -= self.deps
self.arch[arch].source_set_deps -= self.source_set_deps
def __init__(self): def __init__(self):
@@ -352,8 +349,7 @@ class GnParser(object):
target.arch[arch].include_dirs.update(desc.get('include_dirs', [])) target.arch[arch].include_dirs.update(desc.get('include_dirs', []))
if "-frtti" in target.arch[arch].cflags: if "-frtti" in target.arch[arch].cflags:
target.rtti = True target.rtti = True
if target.type == "source_set":
target.type = "static_library"
# Recurse in dependencies. # Recurse in dependencies.
for gn_dep_name in desc.get('deps', []): for gn_dep_name in desc.get('deps', []):
dep = self.parse_gn_desc(gn_desc, gn_dep_name) dep = self.parse_gn_desc(gn_desc, gn_dep_name)
@@ -363,11 +359,8 @@ class GnParser(object):
target.proto_paths.update(dep.proto_paths) target.proto_paths.update(dep.proto_paths)
target.transitive_proto_deps.update(dep.transitive_proto_deps) target.transitive_proto_deps.update(dep.transitive_proto_deps)
elif dep.type == 'source_set': elif dep.type == 'source_set':
target.source_set_deps.add(dep.name) target.arch[arch].source_set_deps.add(dep.name)
if "-frtti" in target.arch[arch].cflags: target.arch[arch].source_set_deps.update(dep.arch[arch].source_set_deps)
# 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.
elif dep.type == 'group': elif dep.type == 'group':
target.update(dep, arch) # Bubble up groups's cflags/ldflags etc. target.update(dep, arch) # Bubble up groups's cflags/ldflags etc.
elif dep.type in ['action', 'action_foreach', 'copy']: elif dep.type in ['action', 'action_foreach', 'copy']:
@@ -382,6 +375,9 @@ class GnParser(object):
#print(dep.name, target.deps) #print(dep.name, target.deps)
pass 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': if dep.type == 'static_library':
# Bubble up static_libs. Necessary, since soong does not propagate # Bubble up static_libs. Necessary, since soong does not propagate
# static_libs up the build tree. # static_libs up the build tree.
@@ -403,7 +399,8 @@ class GnParser(object):
log.debug('Adding java sources for %s', dep.name) log.debug('Adding java sources for %s', dep.name)
java_srcs = [src for src in dep.inputs if _is_java_source(src)] java_srcs = [src for src in dep.inputs if _is_java_source(src)]
self.java_sources.update(java_srcs) 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 return target
def get_proto_exports(self, proto_desc): def get_proto_exports(self, proto_desc):