From 642916f20aa4a37cad49d9f2cc2a66831b09772a Mon Sep 17 00:00:00 2001 From: Jaewoong Jung Date: Fri, 9 Oct 2020 17:25:15 -0700 Subject: [PATCH] Add config.AndroidFirstDeviceTarget. Targets[Android][0] is not always the first, preferred target. Add a new field to config to provide the correct target and begin to use it. Test: m nothing Test: build/soong/scripts/build-ndk-prebuilts.sh Fixes: 156980228 Change-Id: Ib56f52424ebf47f3eee6ac62b9fd9eca2919d63a --- android/config.go | 11 +++++++---- java/app.go | 4 ++-- rust/project_json.go | 2 +- sh/sh_binary.go | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/android/config.go b/android/config.go index 8df65f720..ebe6c3fbb 100644 --- a/android/config.go +++ b/android/config.go @@ -89,10 +89,11 @@ type config struct { ConfigFileName string ProductVariablesFileName string - Targets map[OsType][]Target - BuildOSTarget Target // the Target for tools run on the build machine - BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine - AndroidCommonTarget Target // the Target for common modules for the Android device + Targets map[OsType][]Target + BuildOSTarget Target // the Target for tools run on the build machine + BuildOSCommonTarget Target // the Target for common (java) tools run on the build machine + AndroidCommonTarget Target // the Target for common modules for the Android device + AndroidFirstDeviceTarget Target // the first Target for modules for the Android device // multilibConflicts for an ArchType is true if there is earlier configured device architecture with the same // multilib value. @@ -316,6 +317,7 @@ func TestArchConfig(buildDir string, env map[string]string, bp string, fs map[st config.BuildOSTarget = config.Targets[BuildOs][0] config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0] config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[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") @@ -411,6 +413,7 @@ func NewConfig(srcDir, buildDir string, moduleListFile string) (Config, error) { config.BuildOSCommonTarget = getCommonTargets(config.Targets[BuildOs])[0] if len(config.Targets[Android]) > 0 { config.AndroidCommonTarget = getCommonTargets(config.Targets[Android])[0] + config.AndroidFirstDeviceTarget = firstTarget(config.Targets[Android], "lib64", "lib32")[0] } if err := config.fromEnv(); err != nil { diff --git a/java/app.go b/java/app.go index 13d08b94a..13953adcd 100755 --- a/java/app.go +++ b/java/app.go @@ -641,7 +641,7 @@ func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext // Work with the team to come up with a new format that handles multilib modules properly // and change this. if len(ctx.Config().Targets[android.Android]) == 1 || - ctx.Config().Targets[android.Android][0].Arch.ArchType == jni.target.Arch.ArchType { + ctx.Config().AndroidFirstDeviceTarget.Arch.ArchType == jni.target.Arch.ArchType { a.jniCoverageOutputs = append(a.jniCoverageOutputs, jni.coverageFile.Path()) } } @@ -1392,7 +1392,7 @@ func (a *AndroidAppImport) processVariants(ctx android.LoadHookContext) { } archProps := reflect.ValueOf(a.archVariants).Elem().FieldByName("Arch") - archType := ctx.Config().Targets[android.Android][0].Arch.ArchType + archType := ctx.Config().AndroidFirstDeviceTarget.Arch.ArchType MergePropertiesFromVariant(ctx, &a.properties, archProps, archType.Name) } diff --git a/rust/project_json.go b/rust/project_json.go index 8d161b2d7..569740831 100644 --- a/rust/project_json.go +++ b/rust/project_json.go @@ -93,7 +93,7 @@ func librarySource(ctx android.SingletonContext, rModule *Module, rustLib *libra return "", false } default: - if rModule.Target().String() != ctx.Config().Targets[android.Android][0].String() { + if rModule.Target().String() != ctx.Config().AndroidFirstDeviceTarget.String() { return "", false } } diff --git a/sh/sh_binary.go b/sh/sh_binary.go index 7c3cdbdbb..e8078776c 100644 --- a/sh/sh_binary.go +++ b/sh/sh_binary.go @@ -261,7 +261,7 @@ func (s *ShTest) DepsMutator(ctx android.BottomUpMutatorContext) { ctx.AddFarVariationDependencies(append(ctx.Target().Variations(), sharedLibVariations...), shTestDataLibsTag, s.testProperties.Data_libs...) if ctx.Target().Os.Class == android.Host && len(ctx.Config().Targets[android.Android]) > 0 { - deviceVariations := ctx.Config().Targets[android.Android][0].Variations() + deviceVariations := ctx.Config().AndroidFirstDeviceTarget.Variations() ctx.AddFarVariationDependencies(deviceVariations, shTestDataDeviceBinsTag, s.testProperties.Data_device_bins...) ctx.AddFarVariationDependencies(append(deviceVariations, sharedLibVariations...), shTestDataDeviceLibsTag, s.testProperties.Data_device_libs...)