Merge "add multilib data_device_bins properties" am: a22e2c982d am: 88fa2f6a6a

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2113524

Change-Id: Id91e9272c91768dd95cd549d9860667f8fe30a0a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Sam Delmerico 2022-06-08 14:53:22 +00:00 committed by Automerger Merge Worker
commit b0837c2fe2
4 changed files with 284 additions and 59 deletions

View file

@ -1832,10 +1832,10 @@ func getCommonTargets(targets []Target) []Target {
return ret
}
// firstTarget takes a list of Targets and a list of multilib values and returns a list of Targets
// FirstTarget takes a list of Targets and a list of multilib values and returns a list of Targets
// that contains zero or one Target for each OsType, selecting the one that matches the earliest
// filter.
func firstTarget(targets []Target, filters ...string) []Target {
func FirstTarget(targets []Target, filters ...string) []Target {
// find the first target from each OS
var ret []Target
hasHost := false
@ -1865,9 +1865,9 @@ func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]
case "common_first":
buildTargets = getCommonTargets(targets)
if prefer32 {
buildTargets = append(buildTargets, firstTarget(targets, "lib32", "lib64")...)
buildTargets = append(buildTargets, FirstTarget(targets, "lib32", "lib64")...)
} else {
buildTargets = append(buildTargets, firstTarget(targets, "lib64", "lib32")...)
buildTargets = append(buildTargets, FirstTarget(targets, "lib64", "lib32")...)
}
case "both":
if prefer32 {
@ -1883,12 +1883,12 @@ func decodeMultilibTargets(multilib string, targets []Target, prefer32 bool) ([]
buildTargets = filterMultilibTargets(targets, "lib64")
case "first":
if prefer32 {
buildTargets = firstTarget(targets, "lib32", "lib64")
buildTargets = FirstTarget(targets, "lib32", "lib64")
} else {
buildTargets = firstTarget(targets, "lib64", "lib32")
buildTargets = FirstTarget(targets, "lib64", "lib32")
}
case "first_prefer32":
buildTargets = firstTarget(targets, "lib32", "lib64")
buildTargets = FirstTarget(targets, "lib32", "lib64")
case "prefer32":
buildTargets = filterMultilibTargets(targets, "lib32")
if len(buildTargets) == 0 {

View file

@ -416,7 +416,7 @@ func modifyTestConfigToSupportArchMutator(testConfig Config) {
config.BuildOSTarget = config.Targets[config.BuildOS][0]
config.BuildOSCommonTarget = getCommonTargets(config.Targets[config.BuildOS])[0]
config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0]
config.TestProductVariables.DeviceArch = proptools.StringPtr("arm64")
config.TestProductVariables.DeviceArchVariant = proptools.StringPtr("armv8-a")
config.TestProductVariables.DeviceSecondaryArch = proptools.StringPtr("arm")
@ -554,7 +554,7 @@ func NewConfig(moduleListFile string, runGoTests bool, outDir, soongOutDir strin
// Compilation targets for Android.
if len(config.Targets[Android]) > 0 {
config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0]
config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0]
config.AndroidFirstDeviceTarget = FirstTarget(config.Targets[Android], "lib64", "lib32")[0]
}
config.BazelContext, err = NewBazelContext(config)

View file

@ -864,7 +864,25 @@ type hostTestProperties struct {
Data_native_bins []string `android:"arch_variant"`
// list of device binary modules that should be installed alongside the test
Data_device_bins []string `android:"arch_variant"`
// This property only adds the first variant of the dependency
Data_device_bins_first []string `android:"arch_variant"`
// 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"`
// list of device binary modules that should be installed alongside the test
// This property only adds 64bit variants of the dependency
Data_device_bins_64 []string `android:"arch_variant"`
// list of device binary modules that should be installed alongside the test
// This property adds 32bit variants of the dependency if available, or else
// defaults to the 64bit variant
Data_device_bins_prefer32 []string `android:"arch_variant"`
// list of device binary modules that should be installed alongside the test
// This property only adds 32bit variants of the dependency
Data_device_bins_32 []string `android:"arch_variant"`
}
type testHelperLibraryProperties struct {
@ -931,6 +949,83 @@ func (j *JavaTestImport) InstallInTestcases() bool {
return true
}
func (j *TestHost) addDataDeviceBinsDeps(ctx android.BottomUpMutatorContext) {
if len(j.testHostProperties.Data_device_bins_first) > 0 {
deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_first...)
}
var maybeAndroid32Target *android.Target
var maybeAndroid64Target *android.Target
android32TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib32")
android64TargetList := android.FirstTarget(ctx.Config().Targets[android.Android], "lib64")
if len(android32TargetList) > 0 {
maybeAndroid32Target = &android32TargetList[0]
}
if len(android64TargetList) > 0 {
maybeAndroid64Target = &android64TargetList[0]
}
if len(j.testHostProperties.Data_device_bins_both) > 0 {
if maybeAndroid32Target == nil && maybeAndroid64Target == nil {
ctx.PropertyErrorf("data_device_bins_both", "no device targets available. Targets: %q", ctx.Config().Targets)
return
}
if maybeAndroid32Target != nil {
ctx.AddFarVariationDependencies(
maybeAndroid32Target.Variations(),
dataDeviceBinsTag,
j.testHostProperties.Data_device_bins_both...,
)
}
if maybeAndroid64Target != nil {
ctx.AddFarVariationDependencies(
maybeAndroid64Target.Variations(),
dataDeviceBinsTag,
j.testHostProperties.Data_device_bins_both...,
)
}
}
if len(j.testHostProperties.Data_device_bins_prefer32) > 0 {
if maybeAndroid32Target != nil {
ctx.AddFarVariationDependencies(
maybeAndroid32Target.Variations(),
dataDeviceBinsTag,
j.testHostProperties.Data_device_bins_prefer32...,
)
} else {
if maybeAndroid64Target == nil {
ctx.PropertyErrorf("data_device_bins_prefer32", "no device targets available. Targets: %q", ctx.Config().Targets)
return
}
ctx.AddFarVariationDependencies(
maybeAndroid64Target.Variations(),
dataDeviceBinsTag,
j.testHostProperties.Data_device_bins_prefer32...,
)
}
}
if len(j.testHostProperties.Data_device_bins_32) > 0 {
if maybeAndroid32Target == nil {
ctx.PropertyErrorf("data_device_bins_32", "cannot find 32bit device target. Targets: %q", ctx.Config().Targets)
return
}
deviceVariations := maybeAndroid32Target.Variations()
ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_32...)
}
if len(j.testHostProperties.Data_device_bins_64) > 0 {
if maybeAndroid64Target == nil {
ctx.PropertyErrorf("data_device_bins_64", "cannot find 64bit device target. Targets: %q", ctx.Config().Targets)
return
}
deviceVariations := maybeAndroid64Target.Variations()
ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins_64...)
}
}
func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
if len(j.testHostProperties.Data_native_bins) > 0 {
for _, target := range ctx.MultiTargets() {
@ -938,11 +1033,6 @@ func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
}
}
if len(j.testHostProperties.Data_device_bins) > 0 {
deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations()
ctx.AddFarVariationDependencies(deviceVariations, dataDeviceBinsTag, j.testHostProperties.Data_device_bins...)
}
if len(j.testProperties.Jni_libs) > 0 {
for _, target := range ctx.MultiTargets() {
sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"})
@ -950,6 +1040,8 @@ func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) {
}
}
j.addDataDeviceBinsDeps(ctx)
j.deps(ctx)
}
@ -957,17 +1049,40 @@ func (j *TestHost) AddExtraResource(p android.Path) {
j.extraResources = append(j.extraResources, p)
}
func (j *TestHost) dataDeviceBins() []string {
ret := make([]string, 0,
len(j.testHostProperties.Data_device_bins_first)+
len(j.testHostProperties.Data_device_bins_both)+
len(j.testHostProperties.Data_device_bins_prefer32)+
len(j.testHostProperties.Data_device_bins_32)+
len(j.testHostProperties.Data_device_bins_64),
)
ret = append(ret, j.testHostProperties.Data_device_bins_first...)
ret = append(ret, j.testHostProperties.Data_device_bins_both...)
ret = append(ret, j.testHostProperties.Data_device_bins_prefer32...)
ret = append(ret, j.testHostProperties.Data_device_bins_32...)
ret = append(ret, j.testHostProperties.Data_device_bins_64...)
return ret
}
func (j *TestHost) GenerateAndroidBuildActions(ctx android.ModuleContext) {
var configs []tradefed.Config
if len(j.testHostProperties.Data_device_bins) > 0 {
dataDeviceBins := j.dataDeviceBins()
if len(dataDeviceBins) > 0 {
// add Tradefed configuration to push device bins to device for testing
remoteDir := filepath.Join("/data/local/tests/unrestricted/", j.Name())
options := []tradefed.Option{{Name: "cleanup", Value: "true"}}
for _, bin := range j.testHostProperties.Data_device_bins {
for _, bin := range dataDeviceBins {
fullPath := filepath.Join(remoteDir, bin)
options = append(options, tradefed.Option{Name: "push-file", Key: bin, Value: fullPath})
}
configs = append(configs, tradefed.Object{"target_preparer", "com.android.tradefed.targetprep.PushFilePreparer", options})
configs = append(configs, tradefed.Object{
Type: "target_preparer",
Class: "com.android.tradefed.targetprep.PushFilePreparer",
Options: options,
})
}
j.Test.generateAndroidBuildActionsWithConfig(ctx, configs)

View file

@ -1498,62 +1498,172 @@ func TestErrorproneEnabledOnlyByEnvironmentVariable(t *testing.T) {
}
func TestDataDeviceBinsBuildsDeviceBinary(t *testing.T) {
bp := `
testCases := []struct {
dataDeviceBinType string
depCompileMultilib string
variants []string
expectedError string
}{
{
dataDeviceBinType: "first",
depCompileMultilib: "first",
variants: []string{"android_arm64_armv8-a"},
},
{
dataDeviceBinType: "first",
depCompileMultilib: "both",
variants: []string{"android_arm64_armv8-a"},
},
{
// this is true because our testing framework is set up with
// Targets ~ [<64bit target>, <32bit target>], where 64bit is "first"
dataDeviceBinType: "first",
depCompileMultilib: "32",
expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
},
{
dataDeviceBinType: "first",
depCompileMultilib: "64",
variants: []string{"android_arm64_armv8-a"},
},
{
dataDeviceBinType: "both",
depCompileMultilib: "both",
variants: []string{
"android_arm_armv7-a-neon",
"android_arm64_armv8-a",
},
},
{
dataDeviceBinType: "both",
depCompileMultilib: "32",
expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
},
{
dataDeviceBinType: "both",
depCompileMultilib: "64",
expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
},
{
dataDeviceBinType: "both",
depCompileMultilib: "first",
expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
},
{
dataDeviceBinType: "32",
depCompileMultilib: "32",
variants: []string{"android_arm_armv7-a-neon"},
},
{
dataDeviceBinType: "32",
depCompileMultilib: "first",
expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
},
{
dataDeviceBinType: "32",
depCompileMultilib: "both",
variants: []string{"android_arm_armv7-a-neon"},
},
{
dataDeviceBinType: "32",
depCompileMultilib: "64",
expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
},
{
dataDeviceBinType: "64",
depCompileMultilib: "64",
variants: []string{"android_arm64_armv8-a"},
},
{
dataDeviceBinType: "64",
depCompileMultilib: "both",
variants: []string{"android_arm64_armv8-a"},
},
{
dataDeviceBinType: "64",
depCompileMultilib: "first",
variants: []string{"android_arm64_armv8-a"},
},
{
dataDeviceBinType: "64",
depCompileMultilib: "32",
expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
},
{
dataDeviceBinType: "prefer32",
depCompileMultilib: "32",
variants: []string{"android_arm_armv7-a-neon"},
},
{
dataDeviceBinType: "prefer32",
depCompileMultilib: "both",
variants: []string{"android_arm_armv7-a-neon"},
},
{
dataDeviceBinType: "prefer32",
depCompileMultilib: "first",
expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
},
{
dataDeviceBinType: "prefer32",
depCompileMultilib: "64",
expectedError: `Android.bp:2:3: dependency "bar" of "foo" missing variant`,
},
}
bpTemplate := `
java_test_host {
name: "foo",
srcs: ["test.java"],
data_device_bins: ["bar"],
data_device_bins_%s: ["bar"],
}
cc_binary {
name: "bar",
compile_multilib: "%s",
}
`
ctx := android.GroupFixturePreparers(
PrepareForIntegrationTestWithJava,
).RunTestWithBp(t, bp)
for _, tc := range testCases {
bp := fmt.Sprintf(bpTemplate, tc.dataDeviceBinType, tc.depCompileMultilib)
buildOS := ctx.Config.BuildOS.String()
fooVariant := ctx.ModuleForTests("foo", buildOS+"_common")
barVariant := ctx.ModuleForTests("bar", "android_arm64_armv8-a")
fooMod := fooVariant.Module().(*TestHost)
relocated := barVariant.Output("bar")
expectedInput := "out/soong/.intermediates/bar/android_arm64_armv8-a/unstripped/bar"
android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, fooMod)[0]
expectedData := []string{
"out/soong/.intermediates/bar/android_arm64_armv8-a/bar:bar",
}
actualData := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", ctx.Config, expectedData, actualData)
}
func TestDataDeviceBinsAutogenTradefedConfig(t *testing.T) {
bp := `
java_test_host {
name: "foo",
srcs: ["test.java"],
data_device_bins: ["bar"],
errorHandler := android.FixtureExpectsNoErrors
if tc.expectedError != "" {
errorHandler = android.FixtureExpectsAtLeastOneErrorMatchingPattern(tc.expectedError)
}
cc_binary {
name: "bar",
}
`
testName := fmt.Sprintf(`data_device_bins_%s with compile_multilib:"%s"`, tc.dataDeviceBinType, tc.depCompileMultilib)
t.Run(testName, func(t *testing.T) {
ctx := android.GroupFixturePreparers(PrepareForIntegrationTestWithJava).
ExtendWithErrorHandler(errorHandler).
RunTestWithBp(t, bp)
if tc.expectedError != "" {
return
}
ctx := android.GroupFixturePreparers(
PrepareForIntegrationTestWithJava,
).RunTestWithBp(t, bp)
buildOS := ctx.Config.BuildOS.String()
fooVariant := ctx.ModuleForTests("foo", buildOS+"_common")
fooMod := fooVariant.Module().(*TestHost)
entries := android.AndroidMkEntriesForTest(t, ctx.TestContext, fooMod)[0]
buildOS := ctx.Config.BuildOS.String()
fooModule := ctx.ModuleForTests("foo", buildOS+"_common")
expectedAutogenConfig := `<option name="push-file" key="bar" value="/data/local/tests/unrestricted/foo/bar" />`
expectedAutogenConfig := `<option name="push-file" key="bar" value="/data/local/tests/unrestricted/foo/bar" />`
autogen := fooVariant.Rule("autogen")
if !strings.Contains(autogen.Args["extraConfigs"], expectedAutogenConfig) {
t.Errorf("foo extraConfigs %v does not contain %q", autogen.Args["extraConfigs"], expectedAutogenConfig)
}
autogen := fooModule.Rule("autogen")
if !strings.Contains(autogen.Args["extraConfigs"], expectedAutogenConfig) {
t.Errorf("foo extraConfigs %v does not contain %q", autogen.Args["extraConfigs"], expectedAutogenConfig)
expectedData := []string{}
for _, variant := range tc.variants {
barVariant := ctx.ModuleForTests("bar", variant)
relocated := barVariant.Output("bar")
expectedInput := fmt.Sprintf("out/soong/.intermediates/bar/%s/unstripped/bar", variant)
android.AssertPathRelativeToTopEquals(t, "relocation input", expectedInput, relocated.Input)
expectedData = append(expectedData, fmt.Sprintf("out/soong/.intermediates/bar/%s/bar:bar", variant))
}
actualData := entries.EntryMap["LOCAL_COMPATIBILITY_SUPPORT_FILES"]
android.AssertStringPathsRelativeToTopEquals(t, "LOCAL_TEST_DATA", ctx.Config, expectedData, actualData)
})
}
}