gn2bp: add support for actions calling write_build_config.py
This is still incomplete, but should get us closer to what is needed.
A lot of the inputs to this genrule are generated by another genrule --
this will be a tough one.
Test: //base:jni_java__compile_java
Change-Id: Iae7e0d694a73deabed3f5f0592ed6ca0b17b09bd
diff --git a/tools/gn2bp/gen_android_bp b/tools/gn2bp/gen_android_bp
index 53b138b..97eeb4d 100755
--- a/tools/gn2bp/gen_android_bp
+++ b/tools/gn2bp/gen_android_bp
@@ -725,6 +725,59 @@
# fix target.output directory to match #include statements.
target.outputs = [re.sub('^jni_headers/', '', out) for out in target.outputs]
+ elif target.script == '//build/android/gyp/write_build_config.py':
+ for i, val in enumerate(target.args):
+ if val == '--depfile':
+ # Depfile is not used, so no need to generate it.
+ target.args[i] = ''
+ target.args[i + 1] = ''
+ elif val in ['--deps-configs', '--bundled-srcjars']:
+ args = target.args[i + 1]
+ if args == '[]':
+ continue
+ # strip surrounding [] and split by ", "
+ args = args.strip('[]').split(', ')
+ # strip surrounding ""
+ args = [arg.strip('"') for arg in args]
+ # remove leading gen/
+ args = [re.sub('^gen/', '', arg) for arg in args]
+ # wrap filename in \"$(location filename)\"
+ args = ['\"$(location %s)\"' % arg for arg in args]
+ # join args with ", " and wrap in []
+ target.args[i + 1] = '[%s]' % ', '.join(args)
+
+ elif val == '--public-deps-configs':
+ # TODO: implement.
+ pass
+
+ elif val == '--build-config':
+ # json output of this script
+ target.args[i + 1] = re.sub('^gen', '$(genDir)', target.args[i + 1])
+
+ elif val in ['--unprocessed-jar-path', '--interface-jar-path',
+ '--device-jar-path', '--host-jar-path']:
+ # jar path can be within sources (../../) or output generated by
+ # another genrule (obj/)
+ filename = re.sub('^\.\./\.\./', '', target.args[i + 1])
+ filename = re.sub('^obj/', '', target.args[i + 1])
+ target.args[i + 1] = '$(location %s)' % filename
+
+ elif val == '--proguard-configs':
+ args = target.args[i + 1]
+ if args == '[]':
+ continue
+ # TODO: consider adding helpers to deal with argument lists
+ # strip surrounding [] and split by ", ", then strip surrounding ""
+ args = args.strip('[]').split(', ')
+ args = [arg.strip('"') for arg in args]
+ # remove leading ../../
+ args = [re.sub('^\.\./\.\./', '', arg) for arg in args]
+ # add dependency on proguard config file, so a $(location) wrapper can be used.
+ module.tool_files.update(args)
+ # wrap filename in \"$(location filename)\"
+ args = ['$(location %s)' % arg for arg in args]
+ target.args[i + 1] = '[%s]' % ', '.join(args)
+
script = gn_utils.label_to_path(target.script)
module.tool_files.add(script)