summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2025-02-21 15:31:29 -0800
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2025-02-21 15:31:29 -0800
commitff5a9c36f906accadb520cd479f876daf1d4587d (patch)
tree5f55e2d0b02a90ddc9f598ec33bd1f7a54f196c2
parent2cb77e066ae2548db00cfaba95665141aa3cfc02 (diff)
parentb361442aa66c644efba22c6c3da846ac0644d86a (diff)
Merge "Implement host_common_data property for cc, java, rust and sh test modules" into main
-rw-r--r--android/path_properties.go9
-rw-r--r--cc/fuzz.go1
-rw-r--r--cc/test.go6
-rw-r--r--fuzz/fuzz_common.go6
-rw-r--r--java/app.go1
-rw-r--r--java/java.go6
-rw-r--r--java/java_test.go23
-rw-r--r--java/robolectric.go1
-rw-r--r--rust/test.go10
-rw-r--r--sh/sh_binary.go6
10 files changed, 68 insertions, 1 deletions
diff --git a/android/path_properties.go b/android/path_properties.go
index 55a4dc066..d769d58c4 100644
--- a/android/path_properties.go
+++ b/android/path_properties.go
@@ -54,12 +54,14 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) {
var pathDeviceFirstPrefer32Properties []string
var pathDeviceCommonProperties []string
var pathCommonOsProperties []string
+ var pathHostCommonProperties []string
for _, ps := range props {
pathProperties = append(pathProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path")...)
pathDeviceFirstProperties = append(pathDeviceFirstProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_first")...)
pathDeviceFirstPrefer32Properties = append(pathDeviceFirstPrefer32Properties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_first_prefer32")...)
pathDeviceCommonProperties = append(pathDeviceCommonProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_device_common")...)
pathCommonOsProperties = append(pathCommonOsProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_common_os")...)
+ pathHostCommonProperties = append(pathHostCommonProperties, taggedPropertiesForPropertyStruct(ctx, ps, "path_host_common")...)
}
// Remove duplicates to avoid multiple dependencies.
@@ -68,6 +70,7 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) {
pathDeviceFirstPrefer32Properties = FirstUniqueStrings(pathDeviceFirstPrefer32Properties)
pathDeviceCommonProperties = FirstUniqueStrings(pathDeviceCommonProperties)
pathCommonOsProperties = FirstUniqueStrings(pathCommonOsProperties)
+ pathHostCommonProperties = FirstUniqueStrings(pathHostCommonProperties)
// Add dependencies to anything that is a module reference.
for _, s := range pathProperties {
@@ -108,6 +111,12 @@ func addPathDepsForProps(ctx BottomUpMutatorContext, props []interface{}) {
ctx.AddVariationDependencies(ctx.Config().AndroidCommonTarget.Variations(), sourceOrOutputDepTag(m, t), m)
}
}
+ // properties tagged "path_host_common" get the host common variant
+ for _, s := range pathHostCommonProperties {
+ if m, t := SrcIsModuleWithTag(s); m != "" {
+ ctx.AddVariationDependencies(ctx.Config().BuildOSCommonTarget.Variations(), sourceOrOutputDepTag(m, t), m)
+ }
+ }
// properties tagged "path_common_os" get the CommonOs variant
for _, s := range pathCommonOsProperties {
if m, t := SrcIsModuleWithTag(s); m != "" {
diff --git a/cc/fuzz.go b/cc/fuzz.go
index a8e4cb70a..bd3d8e431 100644
--- a/cc/fuzz.go
+++ b/cc/fuzz.go
@@ -353,6 +353,7 @@ func PackageFuzzModule(ctx android.ModuleContext, fuzzPackagedModule fuzz.FuzzPa
fuzzPackagedModule.Data = android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Data)
fuzzPackagedModule.Data = append(fuzzPackagedModule.Data, android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Device_common_data)...)
fuzzPackagedModule.Data = append(fuzzPackagedModule.Data, android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Device_first_data)...)
+ fuzzPackagedModule.Data = append(fuzzPackagedModule.Data, android.PathsForModuleSrc(ctx, fuzzPackagedModule.FuzzProperties.Host_common_data)...)
if fuzzPackagedModule.FuzzProperties.Dictionary != nil {
fuzzPackagedModule.Dictionary = android.PathForModuleSrc(ctx, *fuzzPackagedModule.FuzzProperties.Dictionary)
diff --git a/cc/test.go b/cc/test.go
index 2c5c36eac..d2c4b28e8 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -94,6 +94,11 @@ type TestBinaryProperties struct {
// of a host test.
Device_first_data []string `android:"path_device_first"`
+ // Same as data, but will add dependencies on modules using the host's os variation and
+ // the common arch variation. Useful for a device test that wants to depend on a host
+ // module, for example to include a custom Tradefed test runner.
+ Host_common_data []string `android:"path_host_common"`
+
// list of shared library modules that should be installed alongside the test
Data_libs []string `android:"arch_variant"`
@@ -345,6 +350,7 @@ func (test *testBinary) install(ctx ModuleContext, file android.Path) {
dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data)
dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Device_common_data)...)
dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Device_first_data)...)
+ dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Host_common_data)...)
for _, dataSrcPath := range dataSrcPaths {
test.data = append(test.data, android.DataPath{SrcPath: dataSrcPath})
diff --git a/fuzz/fuzz_common.go b/fuzz/fuzz_common.go
index 3fd79a719..83ccd89ae 100644
--- a/fuzz/fuzz_common.go
+++ b/fuzz/fuzz_common.go
@@ -427,6 +427,12 @@ type FuzzProperties struct {
// device's first architecture's variant. Can be useful to add device-built apps to the data
// of a host test.
Device_first_data []string `android:"path_device_first"`
+
+ // Same as data, but will add dependencies on modules using the host's os variation and
+ // the common arch variation. Useful for a device test that wants to depend on a host
+ // module, for example to include a custom Tradefed test runner.
+ Host_common_data []string `android:"path_host_common"`
+
// Optional dictionary to be installed to the fuzz target's output directory.
Dictionary *string `android:"path"`
// Define the fuzzing frameworks this fuzz target can be built for. If
diff --git a/java/app.go b/java/app.go
index 7580db4c6..17548e74a 100644
--- a/java/app.go
+++ b/java/app.go
@@ -1646,6 +1646,7 @@ func (a *AndroidTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_common_data)...)
a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_data)...)
a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Device_first_prefer32_data)...)
+ a.data = append(a.data, android.PathsForModuleSrc(ctx, a.testProperties.Host_common_data)...)
// Install test deps
if !ctx.Config().KatiEnabled() {
diff --git a/java/java.go b/java/java.go
index 505612031..b18c56130 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1549,6 +1549,11 @@ type testProperties struct {
// host test.
Device_first_prefer32_data []string `android:"path_device_first_prefer32"`
+ // Same as data, but will add dependencies on modules using the host's os variation and
+ // the common arch variation. Useful for a device test that wants to depend on a host
+ // module, for example to include a custom Tradefed test runner.
+ Host_common_data []string `android:"path_host_common"`
+
// 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.
@@ -1847,6 +1852,7 @@ func (j *Test) generateAndroidBuildActionsWithConfig(ctx android.ModuleContext,
j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_common_data)...)
j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_first_data)...)
j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Device_first_prefer32_data)...)
+ j.data = append(j.data, android.PathsForModuleSrc(ctx, j.testProperties.Host_common_data)...)
j.extraTestConfigs = android.PathsForModuleSrc(ctx, j.testProperties.Test_options.Extra_test_configs)
diff --git a/java/java_test.go b/java/java_test.go
index 636a0c891..a6290a628 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -585,6 +585,29 @@ func TestTest(t *testing.T) {
}
}
+func TestHostCommonData(t *testing.T) {
+ t.Parallel()
+ ctx, _ := testJava(t, `
+ java_library_host {
+ name: "host",
+ srcs: ["a.java"],
+ }
+
+ java_test {
+ name: "foo",
+ srcs: ["a.java"],
+ host_common_data: [":host"],
+ }
+ `)
+
+ foo := ctx.ModuleForTests(t, "foo", "android_common").Module().(*Test)
+ host := ctx.ModuleForTests(t, "host", ctx.Config().BuildOSCommonTarget.String()).Module().(*Library)
+
+ if g, w := foo.data.RelativeToTop().Strings(), []string{host.outputFile.RelativeToTop().String()}; !slices.Equal(g, w) {
+ t.Errorf("expected test data %q, got %q\n", w, g)
+ }
+}
+
func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) {
t.Parallel()
bp := `
diff --git a/java/robolectric.go b/java/robolectric.go
index 5dcc7dd81..be369f780 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -168,6 +168,7 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext)
r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_common_data)...)
r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_first_data)...)
r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_first_prefer32_data)...)
+ r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Host_common_data)...)
var ok bool
var instrumentedApp *JavaInfo
diff --git a/rust/test.go b/rust/test.go
index 5c183bc67..9833ffdb6 100644
--- a/rust/test.go
+++ b/rust/test.go
@@ -46,9 +46,16 @@ type TestProperties struct {
// the test
Data []string `android:"path,arch_variant"`
- // Same as data, but will add dependencies on the device's
+ // Same as data, but adds dependencies on modules using the device's os variant, and common
+ // architecture's variant. Can be useful to add device-built apps to the data of a host
+ // test.
Device_common_data []string `android:"path_device_common"`
+ // Same as data, but will add dependencies on modules using the host's os variation and
+ // the common arch variation. Useful for a device test that wants to depend on a host
+ // module, for example to include a custom Tradefed test runner.
+ Host_common_data []string `android:"path_host_common"`
+
// list of shared library modules that should be installed alongside the test
Data_libs []string `android:"arch_variant"`
@@ -147,6 +154,7 @@ func (test *testDecorator) install(ctx ModuleContext) {
dataSrcPaths := android.PathsForModuleSrc(ctx, test.Properties.Data)
dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Device_common_data)...)
+ dataSrcPaths = append(dataSrcPaths, android.PathsForModuleSrc(ctx, test.Properties.Host_common_data)...)
ctx.VisitDirectDepsProxyWithTag(dataLibDepTag, func(dep android.ModuleProxy) {
depName := ctx.OtherModuleName(dep)
diff --git a/sh/sh_binary.go b/sh/sh_binary.go
index c0c6ff2ae..f8d1ce523 100644
--- a/sh/sh_binary.go
+++ b/sh/sh_binary.go
@@ -138,6 +138,11 @@ type TestProperties struct {
// host test.
Device_first_data []string `android:"path_device_first"`
+ // Same as data, but will add dependencies on modules using the host's os variation and
+ // the common arch variation. Useful for a device test that wants to depend on a host
+ // module, for example to include a custom Tradefed test runner.
+ Host_common_data []string `android:"path_host_common"`
+
// Add RootTargetPreparer to auto generated test config. This guarantees the test to run
// with root permission.
Require_root *bool
@@ -436,6 +441,7 @@ func (s *ShTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
expandedData := android.PathsForModuleSrc(ctx, s.testProperties.Data)
expandedData = append(expandedData, android.PathsForModuleSrc(ctx, s.testProperties.Device_common_data)...)
expandedData = append(expandedData, android.PathsForModuleSrc(ctx, s.testProperties.Device_first_data)...)
+ expandedData = append(expandedData, android.PathsForModuleSrc(ctx, s.testProperties.Host_common_data)...)
// Emulate the data property for java_data dependencies.
for _, javaData := range ctx.GetDirectDepsProxyWithTag(shTestJavaDataTag) {
expandedData = append(expandedData, android.OutputFilesForModule(ctx, javaData, "")...)