diff --git a/python/test.go b/python/test.go index 7de7af2de..6e23a447f 100644 --- a/python/test.go +++ b/python/test.go @@ -66,6 +66,10 @@ type TestProperties struct { // Test options. Test_options TestOptions + + // list of device binary modules that should be installed alongside the test + // This property adds 64bit AND 32bit variants of the dependency + Data_device_bins_both []string `android:"arch_variant"` } type TestOptions struct { @@ -98,12 +102,48 @@ func (p *PythonTestModule) init() android.Module { android.InitAndroidArchModule(p, p.hod, p.multilib) android.InitDefaultableModule(p) android.InitBazelModule(p) - if p.hod == android.HostSupported && p.testProperties.Test_options.Unit_test == nil { + if p.isTestHost() && p.testProperties.Test_options.Unit_test == nil { p.testProperties.Test_options.Unit_test = proptools.BoolPtr(true) } return p } +func (p *PythonTestModule) isTestHost() bool { + return p.hod == android.HostSupported +} + +var dataDeviceBinsTag = dependencyTag{name: "dataDeviceBins"} + +// python_test_host DepsMutator uses this method to add multilib dependencies of +// data_device_bin_both +func (p *PythonTestModule) addDataDeviceBinsDeps(ctx android.BottomUpMutatorContext, filter string) { + if len(p.testProperties.Data_device_bins_both) < 1 { + return + } + + var maybeAndroidTarget *android.Target + androidTargetList := android.FirstTarget(ctx.Config().Targets[android.Android], filter) + if len(androidTargetList) > 0 { + maybeAndroidTarget = &androidTargetList[0] + } + + if maybeAndroidTarget != nil { + ctx.AddFarVariationDependencies( + maybeAndroidTarget.Variations(), + dataDeviceBinsTag, + p.testProperties.Data_device_bins_both..., + ) + } +} + +func (p *PythonTestModule) DepsMutator(ctx android.BottomUpMutatorContext) { + p.PythonBinaryModule.DepsMutator(ctx) + if p.isTestHost() { + p.addDataDeviceBinsDeps(ctx, "lib32") + p.addDataDeviceBinsDeps(ctx, "lib64") + } +} + func (p *PythonTestModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { // We inherit from only the library's GenerateAndroidBuildActions, and then // just use buildBinary() so that the binary is not installed into the location @@ -153,6 +193,12 @@ func (p *PythonTestModule) GenerateAndroidBuildActions(ctx android.ModuleContext p.data = append(p.data, android.DataPath{SrcPath: dataSrcPath}) } + if p.isTestHost() && len(p.testProperties.Data_device_bins_both) > 0 { + ctx.VisitDirectDepsWithTag(dataDeviceBinsTag, func(dep android.Module) { + p.data = append(p.data, android.DataPath{SrcPath: android.OutputFileForModule(ctx, dep, "")}) + }) + } + // Emulate the data property for java_data dependencies. for _, javaData := range ctx.GetDirectDepsWithTag(javaDataTag) { for _, javaDataSrcPath := range android.OutputFilesForModule(ctx, javaData, "") {