gn2bp: apply additional_args after creating soong modules
This allows applying additional_args for targets that may not be
accessible from within create_modules_from_target, such as proto header
modules.
Test: //net:net
Change-Id: I9360ac1bd128796ecb6364534914f860c38668e6
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 336215e..1b7bec0 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -1074,23 +1074,6 @@
if module.type == 'cc_library_static':
module.export_generated_headers = module.generated_headers
- # Merge in additional hardcoded arguments.
- for key, add_val in additional_args.get(module.name, []):
- curr = getattr(module, key)
- if add_val and isinstance(add_val, set) and isinstance(curr, set):
- curr.update(add_val)
- elif isinstance(add_val, str) and (not curr or isinstance(curr, str)):
- setattr(module, key, add_val)
- elif isinstance(add_val, bool) and (not curr or isinstance(curr, bool)):
- setattr(module, key, add_val)
- elif isinstance(add_val, dict) and isinstance(curr, dict):
- curr.update(add_val)
- elif isinstance(add_val, dict) and isinstance(curr, Target):
- curr.__dict__.update(add_val)
- else:
- raise Error('Unimplemented type %r of additional_args: %r' %
- (type(add_val), key))
-
# dep_name is an unmangled GN target name (e.g. //foo:bar(toolchain)).
# Currently, only one module is generated from target even target has multiple toolchains.
# And module is generated based on the first visited target.
@@ -1171,6 +1154,25 @@
create_modules_from_target(blueprint, gn, target)
create_java_module(blueprint, gn)
+
+ # Merge in additional hardcoded arguments.
+ for module in blueprint.modules.values():
+ for key, add_val in additional_args.get(module.name, []):
+ curr = getattr(module, key)
+ if add_val and isinstance(add_val, set) and isinstance(curr, set):
+ curr.update(add_val)
+ elif isinstance(add_val, str) and (not curr or isinstance(curr, str)):
+ setattr(module, key, add_val)
+ elif isinstance(add_val, bool) and (not curr or isinstance(curr, bool)):
+ setattr(module, key, add_val)
+ elif isinstance(add_val, dict) and isinstance(curr, dict):
+ curr.update(add_val)
+ elif isinstance(add_val, dict) and isinstance(curr, Target):
+ curr.__dict__.update(add_val)
+ else:
+ raise Error('Unimplemented type %r of additional_args: %r' %
+ (type(add_val), key))
+
return blueprint