gn2bp: pass response_file_contents into script via /dev/stdin
This might break on windows where the maximum command-line length is
less than 8k. But since Android does not support building on windows, that
should not be a problem.
Test: //base:base
Change-Id: I7e2c800b500ff95f2180c34186cf9e32f84fd105
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 1422b69..66ba104 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -674,9 +674,21 @@
script = gn_utils.label_to_path(target.script)
module.tool_files = [script]
+ # Handle passing parameters via response file by piping them into the script
+ # and reading them from /dev/stdin.
+ response_file = '{{response_file_name}}'
+ use_response_file = response_file in target.args
+ if use_response_file:
+ # Replace {{response_file_contents}} with /dev/stdin
+ target.args = ['/dev/stdin' if it == response_file else it for it in target.args]
+
arg_string = ' '.join(target.args)
module.cmd = '$(location %s) %s' % (script, arg_string)
+ if use_response_file:
+ # Pipe response file contents into script
+ module.cmd = 'echo \'%s\' | %s' % (target.response_file_contents, module.cmd)
+
if all(os.path.splitext(it)[1] == '.h' for it in target.outputs):
module.genrule_headers.add(bp_module_name)