Merge changes Ie84b8777,I90148d83,If85f8a12,Id8932aaa,I7e2c800b, ...
* changes:
gn2bp: add .java to supported source files
gn2bp: properly split sources and tool_files
gn2bp: change tool_files to set
gn2bp: remove another perfetto-specific hack
gn2bp: pass response_file_contents into script via /dev/stdin
gn2bp: store response_file_contents for action targets
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 1422b69..ee092db 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -339,7 +339,7 @@
self.local_include_dirs = set()
self.header_libs = set()
self.required = set()
- self.tool_files = []
+ self.tool_files = set()
self.android = Target('android')
self.host = Target('host')
self.stl = None
@@ -467,7 +467,7 @@
def is_supported_source_file(name):
"""Returns True if |name| can appear in a 'srcs' list."""
- return os.path.splitext(name)[1] in ['.c', '.cc', '.proto']
+ return os.path.splitext(name)[1] in ['.c', '.cc', '.java', '.proto']
def create_proto_modules(blueprint, gn, target):
@@ -598,9 +598,7 @@
def create_amalgamated_sql_metrics_module(blueprint, target):
bp_module_name = label_to_module_name(target.name)
module = Module('genrule', bp_module_name, target.name)
- module.tool_files = [
- 'tools/gen_amalgamated_sql_metrics.py',
- ]
+ module.tool_files.add('tools/gen_amalgamated_sql_metrics.py')
module.cmd = ' '.join([
'$(location tools/gen_amalgamated_sql_metrics.py)',
'--cpp_out=$(out)',
@@ -616,9 +614,7 @@
def create_cc_proto_descriptor_module(blueprint, target):
bp_module_name = label_to_module_name(target.name)
module = Module('genrule', bp_module_name, target.name)
- module.tool_files = [
- 'tools/gen_cc_proto_descriptor.py',
- ]
+ module.tool_files.add('tools/gen_cc_proto_descriptor.py')
module.cmd = ' '.join([
'$(location tools/gen_cc_proto_descriptor.py)', '--gen_dir=$(genDir)',
'--cpp_out=$(out)', '$(in)'
@@ -639,7 +635,7 @@
module = Module('genrule', bp_module_name, gn_utils.GEN_VERSION_TARGET)
script_path = gn_utils.label_to_path(target.script)
module.genrule_headers.add(bp_module_name)
- module.tool_files = [script_path]
+ module.tool_files.add(script_path)
module.out.update(target.outputs)
module.srcs.update(gn_utils.label_to_path(src) for src in target.inputs)
module.cmd = ' '.join([
@@ -668,22 +664,39 @@
blueprint.add_module(module)
+
def create_action_module(blueprint, target):
bp_module_name = label_to_module_name(target.name)
module = Module('genrule', bp_module_name, target.name)
script = gn_utils.label_to_path(target.script)
- module.tool_files = [script]
+ module.tool_files.add(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)
- # For gn actions, sources and inputs are treated equally.
- # TODO: there should be a label_to_path function that takes a set / list.
- module.srcs.update(gn_utils.label_to_path(it) for it in target.inputs)
- module.srcs.update(gn_utils.label_to_path(it) for it in target.sources)
+ # gn treats inputs and sources for actions equally.
+ # soong only supports source files inside srcs, non-source files are added as
+ # tool_files dependency.
+ for it in target.sources or target.inputs:
+ if is_supported_source_file(it):
+ module.srcs.add(gn_utils.label_to_path(it))
+ else:
+ module.tool_files.add(gn_utils.label_to_path(it))
# Actions using template "action_with_pydeps" also put script inside inputs.
# TODO: it might make sense to filter inputs inside GnParser.
@@ -826,11 +839,6 @@
if not module_is_compiled:
continue
-
- # Don't recurse in any other //gn dep if not handled by builtin_deps.
- if dep_name.startswith('//gn:'):
- continue
-
if dep_module is None:
continue
if dep_module.type == 'cc_library_shared':
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index 6cf5b7d..ef3bf55 100644
--- a/tools/gn2bp/gn_utils.py
+++ b/tools/gn2bp/gn_utils.py
@@ -120,6 +120,7 @@
self.outputs = set()
self.script = None
self.args = []
+ self.response_file_contents = None
# These variables are propagated up when encountering a dependency
# on a source_set target.
@@ -169,6 +170,13 @@
self.actions = {}
self.proto_libs = {}
+ def _get_response_file_contents(self, action_desc):
+ contents = ' '.join(action_desc.get('response_file_contents', []))
+ # escape both single and double quotes.
+ contents.replace('"', '\"')
+ contents.replace("'", '\'')
+ return contents
+
def get_target(self, gn_target_name):
"""Returns a Target object from the fully qualified GN target name.
@@ -225,6 +233,7 @@
# Args are typically relative to the root build dir (../../xxx)
# because root build dir is typically out/xxx/).
target.args = [re.sub('^../../', '//', x) for x in desc['args']]
+ target.response_file_contents = self._get_response_file_contents(desc)
elif target.type == 'copy':
# TODO: copy rules are not currently implemented.
self.actions[gn_target_name] = target