gn2bp: Fix action_foreach with GnRunBinary
* Remove the python3 calls and replace them with the binary right away.
* Fix action_foreach where sources can be used with {{source_file_name}}
Test: None
Change-Id: I0c2e6fd5135de70339168b9ba5d3b7f3a6866fdc
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 4970fb9..df12d42 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -1041,10 +1041,19 @@
return "$(location %s)" % arg.replace("gen/", "")
return arg
+ def _replace_binary(self, arg):
+ if arg in self.binary_to_target:
+ return '$(location %s)' % self.binary
+ return arg
+
+ def _remove_python_args(self):
+ self.target.args = [arg for arg in self.target.args if "python3" not in arg]
+
def _sanitize_args(self):
self._update_all_args(self._sanitize_filepath_with_location_tag)
self._update_all_args(self._replace_gen_with_location_tag)
- self._set_arg_at(0, '$(location %s)' % self.binary)
+ self._update_all_args(self._replace_binary)
+ self._remove_python_args()
super()._sanitize_args()
def get_tools(self):
@@ -1238,7 +1247,8 @@
# don't add script arg for the first source -- create_action_module
# already does this.
if i != 0:
- new_args.append('&& python3 $(location %s)' %
+ new_args.append('&&')
+ new_args.append('python3 $(location %s)' %
gn_utils.label_to_path(target.script))
for arg in target.args:
if '{{source}}' in arg:
@@ -1252,6 +1262,10 @@
for out in target.outputs:
if out.endswith(file_name):
new_args.append('$(location %s)' % out)
+
+ for file in target.sources:
+ if file.endswith(file_name):
+ new_args.append('$(location %s)' % gn_utils.label_to_path(file))
else:
new_args.append(arg)