From 91df2084ad34cc59df6abc95284338032c517c25 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Wed, 20 Nov 2019 01:49:42 +0900 Subject: [PATCH] Fix: install flattened apex on system_ext This build rule is specific to platform APEXes. For non-platform APEXes, MakeAsSystemExt() is not applied. This fixes the cases of "soc_specific: true" apexes which fails to build. Bug: 139053989 Test: m nothing (soong tests) Change-Id: I98d0257499647ab41cdaa62a3671d89addbdf833 Exempt-From-Owner-Approval: got +1 before rebasing --- android/module.go | 8 +++--- apex/apex.go | 2 +- apex/apex_test.go | 67 +++++++++++++++++++++++++++-------------------- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/android/module.go b/android/module.go index 891babc32..d5c8b98c0 100644 --- a/android/module.go +++ b/android/module.go @@ -1515,9 +1515,11 @@ func (m *ModuleBase) EnableNativeBridgeSupportByDefault() { } func (m *ModuleBase) MakeAsSystemExt() { - if !Bool(m.commonProperties.Vendor) && !Bool(m.commonProperties.Product_specific) { - m.commonProperties.System_ext_specific = boolPtr(true) - } + m.commonProperties.Vendor = boolPtr(false) + m.commonProperties.Proprietary = boolPtr(false) + m.commonProperties.Soc_specific = boolPtr(false) + m.commonProperties.Product_specific = boolPtr(false) + m.commonProperties.System_ext_specific = boolPtr(true) } // IsNativeBridgeSupported returns true if "native_bridge_supported" is explicitly set as "true" diff --git a/apex/apex.go b/apex/apex.go index b35b73e56..fe801ac5b 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -178,7 +178,7 @@ func apexFlattenedMutator(mctx android.BottomUpMutatorContext) { modules[i].(*apexBundle).properties.ApexType = zipApex case flattenedApexType: modules[i].(*apexBundle).properties.ApexType = flattenedApex - if !mctx.Config().FlattenApex() { + if !mctx.Config().FlattenApex() && ab.Platform() { modules[i].(*apexBundle).MakeAsSystemExt() } } diff --git a/apex/apex_test.go b/apex/apex_test.go index 8d62d2613..74c02507b 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -2144,38 +2144,47 @@ func TestApexWithShBinary(t *testing.T) { ensureContains(t, copyCmds, "image.apex/bin/script/myscript.sh") } -func TestApexInProductPartition(t *testing.T) { - ctx, _ := testApex(t, ` - apex { - name: "myapex", - key: "myapex.key", - native_shared_libs: ["mylib"], - product_specific: true, - file_contexts: "myapex_file_contexts", - } +func TestApexInVariousPartition(t *testing.T) { + testcases := []struct { + propName, parition, flattenedPartition string + }{ + {"", "system", "system_ext"}, + {"product_specific: true", "product", "product"}, + {"soc_specific: true", "vendor", "vendor"}, + {"proprietary: true", "vendor", "vendor"}, + {"vendor: true", "vendor", "vendor"}, + {"system_ext_specific: true", "system_ext", "system_ext"}, + } + for _, tc := range testcases { + t.Run(tc.propName+":"+tc.parition, func(t *testing.T) { + ctx, _ := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + `+tc.propName+` + } - apex_key { - name: "myapex.key", - public_key: "testkey.avbpubkey", - private_key: "testkey.pem", - product_specific: true, - } + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + `) - cc_library { - name: "mylib", - srcs: ["mylib.cpp"], - system_shared_libs: [], - stl: "none", - } - `, withFiles(map[string][]byte{ - "myapex_file_contexts": nil, - })) + apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) + expected := buildDir + "/target/product/test_device/" + tc.parition + "/apex" + actual := apex.installDir.String() + if actual != expected { + t.Errorf("wrong install path. expected %q. actual %q", expected, actual) + } - apex := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) - expected := buildDir + "/target/product/test_device/product/apex" - actual := apex.installDir.String() - if actual != expected { - t.Errorf("wrong install path. expected %q. actual %q", expected, actual) + flattened := ctx.ModuleForTests("myapex", "android_common_myapex_flattened").Module().(*apexBundle) + expected = buildDir + "/target/product/test_device/" + tc.flattenedPartition + "/apex" + actual = flattened.installDir.String() + if actual != expected { + t.Errorf("wrong install path. expected %q. actual %q", expected, actual) + } + }) } }