From df298b3bed98232773a99c8ba5b913e221525c64 Mon Sep 17 00:00:00 2001 From: Martin Stjernholm Date: Fri, 21 May 2021 20:57:29 +0100 Subject: [PATCH] Fix indexing bug when config.Arches() returns an empty array. This happens when com.android.art.host is not disabled in prebuilts/build-tools/build-prebuilts.sh. Test: m nothing Test: env OUT_DIR=out prebuilts/build-tools/build-prebuilts.sh on the aosp-build-tools branch Bug: 188922057 Change-Id: Ib21d17bb627e4cf7faee320febe65e1bb4566d4e --- apex/apex.go | 26 ++++++++++++++------------ apex/apex_test.go | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/apex/apex.go b/apex/apex.go index da4f472d1..34483272e 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -741,20 +741,22 @@ func (a *apexBundle) DepsMutator(ctx android.BottomUpMutatorContext) { } } - // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device) - // regardless of the TARGET_PREFER_* setting. See b/144532908 - archForPrebuiltEtc := config.Arches()[0] - for _, arch := range config.Arches() { - // Prefer 64-bit arch if there is any - if arch.ArchType.Multilib == "lib64" { - archForPrebuiltEtc = arch - break + if prebuilts := a.properties.Prebuilts; len(prebuilts) > 0 { + // For prebuilt_etc, use the first variant (64 on 64/32bit device, 32 on 32bit device) + // regardless of the TARGET_PREFER_* setting. See b/144532908 + archForPrebuiltEtc := config.Arches()[0] + for _, arch := range config.Arches() { + // Prefer 64-bit arch if there is any + if arch.ArchType.Multilib == "lib64" { + archForPrebuiltEtc = arch + break + } } + ctx.AddFarVariationDependencies([]blueprint.Variation{ + {Mutator: "os", Variation: ctx.Os().String()}, + {Mutator: "arch", Variation: archForPrebuiltEtc.String()}, + }, prebuiltTag, prebuilts...) } - ctx.AddFarVariationDependencies([]blueprint.Variation{ - {Mutator: "os", Variation: ctx.Os().String()}, - {Mutator: "arch", Variation: archForPrebuiltEtc.String()}, - }, prebuiltTag, a.properties.Prebuilts...) // Common-arch dependencies come next commonVariation := ctx.Config().AndroidCommonTarget.Variations() diff --git a/apex/apex_test.go b/apex/apex_test.go index 68182a712..364013fbe 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -7589,6 +7589,28 @@ func TestPrebuiltStubLibDep(t *testing.T) { } } +func TestHostApexInHostOnlyBuild(t *testing.T) { + testApex(t, ` + apex { + name: "myapex", + host_supported: true, + key: "myapex.key", + updatable: false, + payload_type: "zip", + } + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + `, + android.FixtureModifyConfig(func(config android.Config) { + // We may not have device targets in all builds, e.g. in + // prebuilts/build-tools/build-prebuilts.sh + config.Targets[android.Android] = []android.Target{} + })) +} + func TestMain(m *testing.M) { os.Exit(m.Run()) }