gn2bp: Convert cc_objects to cc_static_library
* cc_objects are more like source-sets. However, they are not commonly used in AOSP which makes it risky to rely on them. * Clang native code coverage is not working for cc_objects. Which is needed for the dashboard. Size Delta to .SO x64: -0.1MB x86: 0MB arm: 0MB arm64: 0MB Test: m Bug: 270027426 Change-Id: I1d74e0293dac91334bded73b0e89465b7af7480c
This commit is contained in:
parent
5d17632032
commit
379d79d1b0
3 changed files with 5650 additions and 946 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -549,7 +549,13 @@ class Module(object):
|
|||
return self.type == "cc_genrule"
|
||||
|
||||
def has_input_files(self):
|
||||
return len(self.srcs) > 0 or any([len(target.srcs) > 0 for target in self.target.values()])
|
||||
if len(self.srcs) > 0:
|
||||
return True
|
||||
if any([len(target.srcs) > 0 for target in self.target.values()]):
|
||||
return True
|
||||
# Allow cc_static_library with export_generated_headers as those are crucial for
|
||||
# the depending modules
|
||||
return len(self.export_generated_headers) > 0
|
||||
|
||||
def merge_attribute(self, key, source_module, allowed_archs, source_key = None):
|
||||
"""
|
||||
|
|
@ -591,8 +597,8 @@ class Blueprint(object):
|
|||
|
||||
def to_string(self, output):
|
||||
for m in sorted(self.modules.values(), key=lambda m: m.name):
|
||||
if m.type != "cc_object" or m.has_input_files():
|
||||
# Don't print cc_object with empty srcs. These attributes are already
|
||||
if m.type != "cc_library_static" or m.has_input_files():
|
||||
# Don't print cc_library_static with empty srcs. These attributes are already
|
||||
# propagated up the tree. Printing them messes the presubmits because
|
||||
# every module is compiled while those targets are not reachable in
|
||||
# a normal compilation path.
|
||||
|
|
@ -1345,10 +1351,9 @@ def _set_linker_script(module, libs):
|
|||
|
||||
def set_module_flags(module, module_type, cflags, defines, ldflags, libs):
|
||||
module.cflags.update(_get_cflags(cflags, defines))
|
||||
if module_type != 'cc_object':
|
||||
module.ldflags.update({flag for flag in ldflags
|
||||
if flag in ldflag_allowlist or flag.startswith("-Wl,-wrap,")})
|
||||
_set_linker_script(module, libs)
|
||||
module.ldflags.update({flag for flag in ldflags
|
||||
if flag in ldflag_allowlist or flag.startswith("-Wl,-wrap,")})
|
||||
_set_linker_script(module, libs)
|
||||
# TODO: implement proper cflag parsing.
|
||||
for flag in cflags:
|
||||
if '-std=' in flag:
|
||||
|
|
@ -1397,12 +1402,10 @@ def create_modules_from_target(blueprint, gn, gn_target_name, is_test_target):
|
|||
# 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':
|
||||
elif target.type in ['static_library', 'source_set']:
|
||||
module = Module('cc_library_static', bp_module_name, gn_target_name)
|
||||
elif target.type == 'shared_library':
|
||||
module = Module('cc_library_shared', bp_module_name, gn_target_name)
|
||||
elif target.type == 'source_set':
|
||||
module = Module('cc_object', bp_module_name, gn_target_name)
|
||||
elif target.type == 'group':
|
||||
# "group" targets are resolved recursively by gn_utils.get_target().
|
||||
# There's nothing we need to do at this level for them.
|
||||
|
|
@ -1525,27 +1528,21 @@ def create_modules_from_target(blueprint, gn, gn_target_name, is_test_target):
|
|||
if not module.is_compiled() or module.is_genrule():
|
||||
continue
|
||||
|
||||
# Drop compiled modules that doesn't provide any benefit. This is mostly
|
||||
# applicable to source_sets when converted to cc_static_library, sometimes
|
||||
# the source set only has header files which are dropped so the module becomes empty.
|
||||
if dep_module.is_compiled() and not dep_module.has_input_files():
|
||||
continue
|
||||
|
||||
if dep_module.type == 'cc_library_shared':
|
||||
module.shared_libs.add(dep_module.name)
|
||||
elif dep_module.type == 'cc_library_static':
|
||||
module.static_libs.add(dep_module.name)
|
||||
elif dep_module.type == 'cc_object':
|
||||
module.merge_attribute('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_attribute('export_generated_headers', dep_module,
|
||||
target.arch.keys(), 'generated_headers')
|
||||
elif dep_module.type == 'cc_genrule':
|
||||
module.merge_attribute('generated_headers', dep_module, [], 'genrule_headers')
|
||||
module.merge_attribute('srcs', dep_module, [], 'genrule_srcs')
|
||||
module.merge_attribute('shared_libs', dep_module, [], 'genrule_shared_libs')
|
||||
module.merge_attribute('header_libs', dep_module, [], 'genrule_header_libs')
|
||||
if module.type not in ["cc_object"]:
|
||||
module.merge_attribute('export_generated_headers', dep_module, [],
|
||||
'genrule_headers')
|
||||
elif dep_module.type == 'cc_binary':
|
||||
continue # Ignore executables deps (used by cmdline integration tests).
|
||||
else:
|
||||
|
|
@ -1563,20 +1560,13 @@ def create_modules_from_target(blueprint, gn, gn_target_name, is_test_target):
|
|||
# Arch-specific dependencies currently only include cc_library_static.
|
||||
# Revisit this approach once we need to support more target types.
|
||||
if dep_module.type == 'cc_library_static':
|
||||
module.target[arch_name].static_libs.add(dep_module.name)
|
||||
if dep_module.has_input_files():
|
||||
module.target[arch_name].static_libs.add(dep_module.name)
|
||||
elif dep_module.type == 'cc_genrule':
|
||||
module.target[arch_name].generated_headers.update(dep_module.genrule_headers)
|
||||
module.target[arch_name].srcs.update(dep_module.genrule_srcs)
|
||||
module.target[arch_name].shared_libs.update(dep_module.genrule_shared_libs)
|
||||
module.target[arch_name].header_libs.update(dep_module.genrule_header_libs)
|
||||
if module.type not in ["cc_object"]:
|
||||
module.target[arch_name].export_generated_headers.update(
|
||||
dep_module.genrule_headers)
|
||||
elif dep_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.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))
|
||||
|
|
|
|||
|
|
@ -429,14 +429,6 @@ class GnParser(object):
|
|||
target.transitive_proto_deps.add(dep.name)
|
||||
target.proto_paths.update(dep.proto_paths)
|
||||
target.transitive_proto_deps.update(dep.transitive_proto_deps)
|
||||
elif dep.type == 'source_set':
|
||||
target.arch[arch].source_set_deps.add(dep.name)
|
||||
target.arch[arch].source_set_deps.update(dep.arch[arch].source_set_deps)
|
||||
# flatten source_set deps
|
||||
if target.is_linker_unit_type():
|
||||
# This ensure that all transitive source set dependencies are
|
||||
# propagated upward to the linker units.
|
||||
target.arch[arch].deps.update(target.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']:
|
||||
|
|
@ -450,12 +442,11 @@ class GnParser(object):
|
|||
# java_library.
|
||||
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
|
||||
if dep.type in ['static_library', 'source_set']:
|
||||
# Bubble up static_libs and source_set. Necessary, since soong does not propagate
|
||||
# static_libs up the build tree.
|
||||
# Source sets are later translated to static_libraries, so it makes sense
|
||||
# to reuse transitive_static_libs_deps.
|
||||
target.arch[arch].transitive_static_libs_deps.add(dep.name)
|
||||
|
||||
if arch in dep.arch:
|
||||
|
|
|
|||
Loading…
Reference in a new issue