rust: Add data_libs and data_bins to rust_test

Allows defining data binaries and libraries that should be installed
alongside a rust_test module, similar to cc_test.

This refactors cc_test as well so it can define rust_ffi_shared and
rust_binary modules as data.

Bug: 171710847
Test: New Soong tests pass.
Test: Example module installs data appropriately.
Change-Id: I0b56098fb475ec54f9b7a761220d260fe68cbee1
This commit is contained in:
Ivan Lozano
2021-11-04 14:09:38 -04:00
parent 8d10fc39af
commit 4e5f07d27b
5 changed files with 198 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ import (
"github.com/google/blueprint/proptools"
"android/soong/android"
"android/soong/cc"
"android/soong/tradefed"
)
@@ -49,6 +50,12 @@ type TestProperties struct {
// the test
Data []string `android:"path,arch_variant"`
// list of shared library modules that should be installed alongside the test
Data_libs []string `android:"arch_variant"`
// list of binary modules that should be installed alongside the test
Data_bins []string `android:"arch_variant"`
// Flag to indicate whether or not to create test config automatically. If AndroidTest.xml
// doesn't exist next to the Android.bp, this attribute doesn't need to be set to true
// explicitly.
@@ -137,6 +144,32 @@ func (test *testDecorator) install(ctx ModuleContext) {
dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data)
ctx.VisitDirectDepsWithTag(dataLibDepTag, func(dep android.Module) {
depName := ctx.OtherModuleName(dep)
linkableDep, ok := dep.(cc.LinkableInterface)
if !ok {
ctx.ModuleErrorf("data_lib %q is not a linkable module", depName)
}
if linkableDep.OutputFile().Valid() {
test.data = append(test.data,
android.DataPath{SrcPath: linkableDep.OutputFile().Path(),
RelativeInstallPath: linkableDep.RelativeInstallPath()})
}
})
ctx.VisitDirectDepsWithTag(dataBinDepTag, func(dep android.Module) {
depName := ctx.OtherModuleName(dep)
linkableDep, ok := dep.(cc.LinkableInterface)
if !ok {
ctx.ModuleErrorf("data_bin %q is not a linkable module", depName)
}
if linkableDep.OutputFile().Valid() {
test.data = append(test.data,
android.DataPath{SrcPath: linkableDep.OutputFile().Path(),
RelativeInstallPath: linkableDep.RelativeInstallPath()})
}
})
for _, dataSrcPath := range dataSrcPaths {
test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath})
}
@@ -194,5 +227,8 @@ func (test *testDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
deps.Rustlibs = append(deps.Rustlibs, "libtest")
deps.DataLibs = append(deps.DataLibs, test.Properties.Data_libs...)
deps.DataBins = append(deps.DataBins, test.Properties.Data_bins...)
return deps
}