Let cargo2android.py generate data properties for tests.
Some tests load data from files. These files thus need to be copied
to the correct location on the host/device so that the tests can
access them. This adds an option to cargo2android.py so that it can
generate these data properties.
Bug: 171710847
Test: Use for a crate.
Change-Id: I14a1ad8aca4625cc5f09807d19ffd7499fcf3689
diff --git a/scripts/cargo2android.py b/scripts/cargo2android.py
index 12c982f..f6ab3ac 100755
--- a/scripts/cargo2android.py
+++ b/scripts/cargo2android.py
@@ -603,6 +603,8 @@
self.write(' test_suites: ["general-tests"],')
self.write(' auto_gen_config: true,')
self.dump_edition_flags_libs()
+ if 'test' in self.crate_types and len(self.srcs) == 1:
+ self.dump_test_data()
self.write('}')
def dump_single_type_android_module(self):
@@ -665,6 +667,8 @@
self.write(' vendor_ramdisk_available: true,')
if self.runner.args.min_sdk_version and crate_type == 'lib':
self.write(' min_sdk_version: "%s",' % self.runner.args.min_sdk_version)
+ if crate_type == 'test' and not self.default_srcs:
+ self.dump_test_data()
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 '))
@@ -698,6 +702,12 @@
shared_libs = [lib for lib in self.shared_libs if not lib in self.runner.args.lib_blocklist]
self.dump_android_property_list('shared_libs', '"lib%s"', shared_libs)
+ def dump_test_data(self):
+ data = [data for (name, data) in map(lambda kv: kv.split('=', 1), self.runner.args.test_data)
+ if self.srcs == [name]]
+ if data:
+ self.dump_android_property_list('data', '"%s"', data)
+
def main_src_basename_path(self):
return re.sub('/', '_', re.sub('.rs$', '', self.main_src))
@@ -1633,6 +1643,12 @@
default=[],
help='Make the given libraries (without lib prefixes) whole_static_libs.')
parser.add_argument(
+ '--test-data',
+ nargs='*',
+ default=[],
+ help=('Add the given file to the given test\'s data property. ' +
+ 'Usage: test-path=data-path'))
+ parser.add_argument(
'--dependency-blocklist',
nargs='*',
default=[],