gn2bp: Fix actionSanitizer for gn_run_binary
* This is a python script that runs a binary on files to generate output files for testing.
* The python script is not really needed as we can run the binary right away.
Test: m
Change-Id: I3be64e7f51380f2c028dec3168c924451076db95
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 8ef3647..eb9064b 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -938,6 +938,9 @@
files = self.target.sources.union(self.target.inputs)
return {gn_utils.label_to_path(file) for file in files if is_supported_source_file(file)}
+ def get_tools(self):
+ return set()
+
def get_tool_files(self):
# gn treats inputs and sources for actions equally.
# soong only supports source files inside srcs, non-source files are added as
@@ -984,6 +987,35 @@
self._set_value_arg('--output', '$(out)')
super()._sanitize_args()
+class GnRunBinary(BaseActionSanitizer):
+ def __init__(self, target, arch):
+ super().__init__(target, arch)
+ self.binary_to_target = {
+ "clang_x64/transport_security_state_generator":
+ "cronet_aml_net_tools_transport_security_state_generator_transport_security_state_generator__testing",
+ }
+ self.binary = self.binary_to_target[self.target.args[0]]
+
+ def _replace_gen_with_location_tag(self, arg):
+ if arg.startswith("gen/"):
+ return "$(location %s)" % arg.replace("gen/", "")
+ return 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)
+ super()._sanitize_args()
+
+ def get_tools(self):
+ tools = super().get_tools()
+ tools.add(self.binary)
+ return tools
+
+ def get_cmd(self):
+ # Remove the script and use the binary right away
+ return NEWLINE.join(self.target.args)
+
class JniGeneratorSanitizer(BaseActionSanitizer):
def _add_location_tag_to_filepath(self, arg):
if not arg.endswith('.class'):
@@ -1132,6 +1164,8 @@
return JavaCppStringSanitizer(target, arch)
elif target.script == '//build/android/gyp/write_native_libraries_java.py':
return WriteNativeLibrariesJavaSanitizer(target, arch)
+ elif target.script == '//build/gn_run_binary.py':
+ return GnRunBinary(target, arch)
else:
# TODO: throw exception here once all script hacks have been converted.
return BaseActionSanitizer(target, arch)
@@ -1180,6 +1214,7 @@
module.genrule_headers.add(module.name)
module.srcs = sanitizer.get_srcs()
module.tool_files = sanitizer.get_tool_files()
+ module.tools = sanitizer.get_tools()
return module