From 7afd1077b8b86e51a3eb421b578c221a4a9d3fbf Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 30 Dec 2019 16:56:33 +0900 Subject: [PATCH] APEX carries required properties of its dependencies When a module is included in an APEX and the module is not directly installed to the system partition, the 'required' property of the module is lost. The APEX containing the module now carries the property from its dependencies. Bug: 146549048 Test: m Change-Id: Ie21cc7b8420c6126c855e66c2363644de4a7ef42 --- apex/androidmk.go | 23 +++++++++++++++++++++++ apex/apex.go | 7 +++++++ apex/apex_test.go | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/apex/androidmk.go b/apex/androidmk.go index c42b3484e..9aa089436 100644 --- a/apex/androidmk.go +++ b/apex/androidmk.go @@ -152,6 +152,27 @@ func (a *apexBundle) androidMkForFiles(w io.Writer, apexName, moduleDir string) return moduleNames } +func (a *apexBundle) writeRequiredModules(w io.Writer) { + var required []string + var targetRequired []string + var hostRequired []string + for _, fi := range a.filesInfo { + required = append(required, fi.requiredModuleNames...) + targetRequired = append(targetRequired, fi.targetRequiredModuleNames...) + hostRequired = append(hostRequired, fi.hostRequiredModuleNames...) + } + + if len(required) > 0 { + fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(required, " ")) + } + if len(targetRequired) > 0 { + fmt.Fprintln(w, "LOCAL_TARGET_REQUIRED_MODULES +=", strings.Join(targetRequired, " ")) + } + if len(hostRequired) > 0 { + fmt.Fprintln(w, "LOCAL_HOST_REQUIRED_MODULES +=", strings.Join(hostRequired, " ")) + } +} + func (a *apexBundle) androidMkForType() android.AndroidMkData { return android.AndroidMkData{ Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { @@ -170,6 +191,7 @@ func (a *apexBundle) androidMkForType() android.AndroidMkData { if len(moduleNames) > 0 { fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES :=", strings.Join(moduleNames, " ")) } + a.writeRequiredModules(w) fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") } else { @@ -188,6 +210,7 @@ func (a *apexBundle) androidMkForType() android.AndroidMkData { if len(a.externalDeps) > 0 { fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES +=", strings.Join(a.externalDeps, " ")) } + a.writeRequiredModules(w) var postInstallCommands []string if a.prebuiltFileToDelete != "" { postInstallCommands = append(postInstallCommands, "rm -rf "+ diff --git a/apex/apex.go b/apex/apex.go index b27b54e3e..9867a7a81 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -461,6 +461,10 @@ type apexFile struct { symlinks []string transitiveDep bool moduleDir string + + requiredModuleNames []string + targetRequiredModuleNames []string + hostRequiredModuleNames []string } func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleName string, installDir string, class apexFileClass, module android.Module) apexFile { @@ -473,6 +477,9 @@ func newApexFile(ctx android.BaseModuleContext, builtFile android.Path, moduleNa } if module != nil { ret.moduleDir = ctx.OtherModuleDir(module) + ret.requiredModuleNames = module.RequiredModuleNames() + ret.targetRequiredModuleNames = module.TargetRequiredModuleNames() + ret.hostRequiredModuleNames = module.HostRequiredModuleNames() } return ret } diff --git a/apex/apex_test.go b/apex/apex_test.go index 0d929ed2a..cc346e99b 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -3328,6 +3328,43 @@ func TestRejectNonInstallableJavaLibrary(t *testing.T) { `) } +func TestCarryRequiredModuleNames(t *testing.T) { + ctx, config := testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + native_shared_libs: ["mylib"], + } + + 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", + required: ["a", "b"], + host_required: ["c", "d"], + target_required: ["e", "f"], + } + `) + + apexBundle := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(*apexBundle) + data := android.AndroidMkDataForTest(t, config, "", apexBundle) + name := apexBundle.BaseModuleName() + prefix := "TARGET_" + var builder strings.Builder + data.Custom(&builder, name, prefix, "", data) + androidMk := builder.String() + ensureContains(t, androidMk, "LOCAL_REQUIRED_MODULES += a b\n") + ensureContains(t, androidMk, "LOCAL_HOST_REQUIRED_MODULES += c d\n") + ensureContains(t, androidMk, "LOCAL_TARGET_REQUIRED_MODULES += e f\n") +} + func TestMain(m *testing.M) { run := func() int { setUp()