gn2bp: create multiple genrule for a single action_foreach
* create_action_foreach_modules replaces the args template with the appropriate source file and outputs. It unrolls the action_foreach cmd into a single long genrule cmd. Both are equivalent, then is delegated to create_action_module
Test: m cronet_aml_net_net
Change-Id: I49d36b00138aff00965fff1c31614e7c8e6543f8
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index f0eb1d8..7487287 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -697,6 +697,38 @@
module.cmd = NEWLINE.join(cmd)
return module
+def create_action_foreach_modules(blueprint, target):
+ """ The following assumes that rebase_path exists in the args.
+ The args of an action_foreach contains hints about which output files are generated
+ by which source files.
+ This is copied directly from the args
+ "gen/net/base/registry_controlled_domains/{{source_name_part}}-reversed-inc.cc"
+ So each source file will generate an output whose name is the {source_name-reversed-inc.cc}
+ """
+ new_args = []
+ for i, src in enumerate(target.sources):
+ # don't add script arg for the first source -- create_action_module
+ # already does this.
+ if i != 0:
+ new_args.append('&& python3 $(location %s)' %
+ gn_utils.label_to_path(target.script))
+ for arg in target.args:
+ if '{{source}}' in arg:
+ new_args.append('$(location %s)' % (gn_utils.label_to_path(src)))
+ elif '{{source_name_part}}' in arg:
+ source_name_part = src.split("/")[-1] # Get the file name only
+ source_name_part = source_name_part.split(".")[0] # Remove the extension (Ex: .cc)
+ file_name = arg.replace('{{source_name_part}}', source_name_part).split("/")[-1]
+ # file_name represent the output file name. But we need the whole path
+ # This can be found from target.outputs.
+ for out in target.outputs:
+ if out.endswith(file_name):
+ new_args.append('$(location %s)' % out)
+ else:
+ new_args.append(arg)
+
+ target.args = new_args
+ return create_action_module(blueprint, target)
def create_action_module(blueprint, target):
bp_module_name = label_to_module_name(target.name)
@@ -937,8 +969,7 @@
else:
module = create_action_module(blueprint, target)
elif target.type == 'action_foreach':
- return None
- # Add basic support for action_foreach
+ module = create_action_foreach_modules(blueprint, target)
elif target.type == 'copy':
# TODO: careful now! copy targets are not supported yet, but this will stop
# traversing the dependency tree. For //base:base, this is not a big