From 5664f2af26210507a816841a87b5a7d3c6d010f1 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Thu, 10 Jun 2021 10:13:49 -0700 Subject: [PATCH] Allow adding blocks of texts to the Android.bp file. You can either add the blocks to the toplevel of the file or into the main module. The blocks are given in separate files. Test: Use both for some crates. Change-Id: I74204867d4e348c83c7adc2a833be166956bfb7e --- scripts/cargo2android.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/cargo2android.py b/scripts/cargo2android.py index 908caf5da..1b6d3a2c6 100755 --- a/scripts/cargo2android.py +++ b/scripts/cargo2android.py @@ -659,6 +659,9 @@ class Crate(object): self.write(' ],') if self.runner.args.min_sdk_version and crate_type == 'lib': self.write(' min_sdk_version: "%s",' % self.runner.args.min_sdk_version) + if self.runner.args.add_module_block: + with open(self.runner.args.add_module_block, 'r') as f: + self.write(' %s,' % f.read().replace('\n', '\n ')) self.write('}') def dump_android_flags(self): @@ -1377,6 +1380,9 @@ class Runner(object): if lib_name not in dumped_libs: dumped_libs.add(lib_name) lib.dump() + if self.args.add_toplevel_block: + with open(self.args.add_toplevel_block, 'r') as f: + self.append_to_bp('\n' + f.read() + '\n') if self.args.dependencies and self.dependencies: self.dump_dependencies() if self.errors: @@ -1635,6 +1641,14 @@ def get_parser(): nargs='*', default=[], help='Do not emit the given cfg.') + parser.add_argument( + '--add-toplevel-block', + type=str, + help='Add the contents of the given file to the top level of the Android.bp.') + parser.add_argument( + '--add-module-block', + type=str, + help='Add the contents of the given file to the main module.') parser.add_argument( '--no-test-mapping', action='store_true',