Revert "gn2bp: Convert cc_objects to cc_static_library"
This reverts commit 379d79d1b0984187ec05f370e87e8bc17ae2a33d.
Reason for revert: This is breaking the symbols of test library.
Test: None
Change-Id: I3a2e8a9a6ec6ce04038ed34489ece6a1ca053cef
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index b48a05b..e4ba0a6 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -569,13 +569,7 @@
return self.type == "cc_genrule"
def has_input_files(self):
- 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
+ return len(self.srcs) > 0 or any([len(target.srcs) > 0 for target in self.target.values()])
def merge_attribute(self, key, source_module, allowed_archs, source_key = None):
"""
@@ -617,8 +611,8 @@
def to_string(self, output):
for m in sorted(self.modules.values(), key=lambda m: m.name):
- if m.type != "cc_library_static" or m.has_input_files():
- # Don't print cc_library_static with empty srcs. These attributes are already
+ if m.type != "cc_object" or m.has_input_files():
+ # Don't print cc_object 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.
@@ -1371,9 +1365,10 @@
def set_module_flags(module, module_type, cflags, defines, ldflags, libs):
module.cflags.update(_get_cflags(cflags, defines))
- module.ldflags.update({flag for flag in ldflags
- if flag in ldflag_allowlist or flag.startswith("-Wl,-wrap,")})
- _set_linker_script(module, libs)
+ 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)
# TODO: implement proper cflag parsing.
for flag in cflags:
if '-std=' in flag:
@@ -1422,10 +1417,12 @@
# 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 in ['static_library', 'source_set']:
+ elif target.type == 'static_library':
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.
@@ -1548,21 +1545,27 @@
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:
@@ -1580,13 +1583,20 @@
# 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':
- if dep_module.has_input_files():
- module.target[arch_name].static_libs.add(dep_module.name)
+ 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))