Implement a feature that installs a cc_test's dependencies into a standalone folder.
This is the implementation of go/standalone-native-device-tests
This feature is disabled by default. To enable it, the `standalone_test` option needs to be added in the Android.bp file.
Example:
```
cc_test {
...
standalone_test: true,
...
}
```
Change-Id: I3bf1b0313e50d1018088123c40c7fd23dcb69553
Test: m bionic-unit-tests
Test: m libunwindstack_unit_test
diff --git a/cc/installer.go b/cc/installer.go
index 30f9612..d7d8c6d 100644
--- a/cc/installer.go
+++ b/cc/installer.go
@@ -107,6 +107,10 @@
installer.installDeps = append(installer.installDeps, installedData...)
}
+func (installer *baseInstaller) installStandaloneTestDep(ctx ModuleContext, standaloneTestDep android.PackagingSpec) {
+ installer.installTestData(ctx, []android.DataPath{{SrcPath: standaloneTestDep.ToGob().SrcPath, RelativeInstallPath: "standalone-libs"}})
+}
+
func (installer *baseInstaller) everInstallable() bool {
// Most cc modules are installable.
return true
diff --git a/cc/test.go b/cc/test.go
index dad4afa..9f86c7a 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -18,6 +18,7 @@
"path/filepath"
"strconv"
+ "github.com/google/blueprint/depset"
"github.com/google/blueprint/proptools"
"android/soong/android"
@@ -128,6 +129,13 @@
// Install the test into a folder named for the module in all test suites.
Per_testcase_directory *bool
+
+ // Install the test's dependencies into a folder named standalone-libs relative to the
+ // test's installation path. ld-library-path will be set to this path in the test's
+ // auto-generated config. This way the dependencies can be used by the test without having
+ // to manually install them to the device. See more details in
+ // go/standalone-native-device-tests.
+ Standalone_test *bool
}
func init() {
@@ -380,6 +388,7 @@
TestInstallBase: testInstallBase,
DeviceTemplate: "${NativeTestConfigTemplate}",
HostTemplate: "${NativeHostTestConfigTemplate}",
+ StandaloneTest: test.Properties.Standalone_test,
})
test.extraTestConfigs = android.PathsForModuleSrc(ctx, test.Properties.Test_options.Extra_test_configs)
@@ -421,6 +430,21 @@
test.binaryDecorator.baseInstaller.installTestData(ctx, test.data)
test.binaryDecorator.baseInstaller.install(ctx, file)
+ if Bool(test.Properties.Standalone_test) {
+ packagingSpecsBuilder := depset.NewBuilder[android.PackagingSpec](depset.TOPOLOGICAL)
+
+ ctx.VisitDirectDeps(func(dep android.Module) {
+ deps := android.OtherModuleProviderOrDefault(ctx, dep, android.InstallFilesProvider)
+ packagingSpecsBuilder.Transitive(deps.TransitivePackagingSpecs)
+ })
+
+ for _, standaloneTestDep := range packagingSpecsBuilder.Build().ToList() {
+ if standaloneTestDep.ToGob().SrcPath == nil {
+ continue
+ }
+ test.binaryDecorator.baseInstaller.installStandaloneTestDep(ctx, standaloneTestDep)
+ }
+ }
}
func getTestInstallBase(useVendor bool) string {