gn2bp: Duplicate modules reachable from test targets
* The current testing situation for Cronet is dire due to the presence of Cronet on the platform,
As cronet is on the platform, we can't run any unit-tests as they'll link against the platform version
and not the statically-linked cronet. We could avoid this by jarjaring the code however this is impossible.
* It's impossible to jar-jar the code as the C++ code which does JNI expects jar-jared java classes. So the
only possible solution here would be to duplicate the C++ modules, one for testing(with no jarjar) and another
for platform(with jarjar)
* Java sources/actions are not collected for testing modules until a proper solution has been figured out.
Test: None
Change-Id: I20bbad13d83e9e3c7956f028f3f0493b24d0f8bc
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 32c9a2b..ab74962 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -217,12 +217,20 @@
builtin_deps = {
'//buildtools/third_party/libunwind:libunwind':
lambda m, a: None, # disable libunwind
+ '//buildtools/third_party/libunwind:libunwind__testing':
+ lambda m, a: None, # disable libunwind
'//net/data/ssl/chrome_root_store:gen_root_store_inc':
lambda m, a: None,
+ '//net/data/ssl/chrome_root_store:gen_root_store_inc__testing':
+ lambda m, a: None,
'//net/tools/root_store_tool:root_store_tool':
lambda m, a: None,
+ '//net/tools/root_store_tool:root_store_tool__testing':
+ lambda m, a: None,
'//third_party/zlib:zlib':
enable_zlib,
+ '//third_party/zlib:zlib__testing':
+ enable_zlib,
}
experimental_android_deps = {
@@ -1283,7 +1291,8 @@
'''
# TODO: Handle this target correctly, this target generates java_genrule but this target has
# different value for cpu-family arg between archs
- if target.name == '//build/android:native_libraries_gen':
+ if target.name in ['//build/android:native_libraries_gen',
+ '//build/android:native_libraries_gen__testing']:
module = create_action_module_internal(target, genrule_type, target.arch['android_arm'])
blueprint.add_module(module)
return module
@@ -1336,7 +1345,7 @@
if d not in local_include_dirs_denylist]
-def create_modules_from_target(blueprint, gn, gn_target_name):
+def create_modules_from_target(blueprint, gn, gn_target_name, is_test_target):
"""Generate module(s) for a given GN target.
Given a GN target name, generate one or more corresponding modules into a
@@ -1462,7 +1471,7 @@
builtin_deps[dep_name](module, None)
continue
- dep_module = create_modules_from_target(blueprint, gn, dep_name)
+ dep_module = create_modules_from_target(blueprint, gn, dep_name, is_test_target)
if dep_module is None:
continue
@@ -1517,7 +1526,7 @@
if dep_name in builtin_deps:
builtin_deps[dep_name](module, arch_name)
continue
- dep_module = create_modules_from_target(blueprint, gn, dep_name)
+ dep_module = create_modules_from_target(blueprint, gn, dep_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':
@@ -1660,7 +1669,7 @@
for source in get_non_api_java_sources(gn)
if source.endswith('.java')])
-def create_blueprint_for_targets(gn, targets):
+def create_blueprint_for_targets(gn, targets, test_targets):
"""Generate a blueprint for a list of GN targets."""
blueprint = Blueprint()
@@ -1704,7 +1713,10 @@
blueprint.add_module(defaults)
for target in targets:
- create_modules_from_target(blueprint, gn, target)
+ create_modules_from_target(blueprint, gn, target, is_test_target=False)
+
+ for test_target in test_targets:
+ create_modules_from_target(blueprint, gn, test_target + gn_utils.TESTING_SUFFIX, is_test_target=True)
java_api_module = create_java_api_module(blueprint, gn)
java_module = create_java_module(blueprint, gn)
@@ -1819,14 +1831,16 @@
if args.verbose:
log.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s', level=log.DEBUG)
- targets = args.targets or DEFAULT_TARGETS + DEFAULT_TESTS
+ targets = args.targets or DEFAULT_TARGETS
gn = gn_utils.GnParser(builtin_deps)
for desc_file in args.desc:
with open(desc_file) as f:
desc = json.load(f)
for target in targets:
- gn.parse_gn_desc(desc, target, is_test_target=target in DEFAULT_TESTS)
- blueprint = create_blueprint_for_targets(gn, targets)
+ gn.parse_gn_desc(desc, target)
+ for test_target in DEFAULT_TESTS:
+ gn.parse_gn_desc(desc, test_target, is_test_target=True)
+ blueprint = create_blueprint_for_targets(gn, targets, DEFAULT_TESTS)
project_root = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
tool_name = os.path.relpath(os.path.abspath(__file__), project_root)