From a90ca0078626cb17b96c6e14452df9a8fd347ec4 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Mon, 7 Oct 2019 15:47:24 +0900 Subject: [PATCH] add [static|shared].apex_available to cc_library apex_available property can be appended differently per the linkage type. This will be used to restrict certain libs (e.g. libc_malloc_debug) to an APEX while allowing them to be statically linkable from platform for testing purpose. Test: m (apex_test amended) Change-Id: I6dec23129c5ac93a3ef06fea28f26f240c0ba410 --- android/apex.go | 14 +++++++++----- apex/apex_test.go | 30 ++++++++++++++++++++++++++++++ cc/cc.go | 10 ++++++++++ cc/library.go | 17 +++++++++++++++++ 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/android/apex.go b/android/apex.go index c54809547..d3c071056 100644 --- a/android/apex.go +++ b/android/apex.go @@ -140,14 +140,18 @@ const ( availableToAnyApex = "//apex_available:anyapex" ) -func (m *ApexModuleBase) AvailableFor(what string) bool { - if len(m.ApexProperties.Apex_available) == 0 { +func CheckAvailableForApex(what string, apex_available []string) bool { + if len(apex_available) == 0 { // apex_available defaults to ["//apex_available:platform", "//apex_available:anyapex"], // which means 'available to everybody'. return true } - return InList(what, m.ApexProperties.Apex_available) || - (what != availableToPlatform && InList(availableToAnyApex, m.ApexProperties.Apex_available)) + return InList(what, apex_available) || + (what != availableToPlatform && InList(availableToAnyApex, apex_available)) +} + +func (m *ApexModuleBase) AvailableFor(what string) bool { + return CheckAvailableForApex(what, m.ApexProperties.Apex_available) } func (m *ApexModuleBase) checkApexAvailableProperty(mctx BaseModuleContext) { @@ -166,7 +170,7 @@ func (m *ApexModuleBase) CreateApexVariations(mctx BottomUpMutatorContext) []blu m.checkApexAvailableProperty(mctx) sort.Strings(m.apexVariations) variations := []string{} - availableForPlatform := m.AvailableFor(availableToPlatform) + availableForPlatform := mctx.Module().(ApexModule).AvailableFor(availableToPlatform) if availableForPlatform { variations = append(variations, "") // Original variation for platform } diff --git a/apex/apex_test.go b/apex/apex_test.go index ae0ea7db6..d1cd9699d 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -2407,6 +2407,36 @@ func TestApexAvailable(t *testing.T) { // check that libfoo is created only for the platform ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex") ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared") + + ctx, _ = testApex(t, ` + apex { + name: "myapex", + key: "myapex.key", + native_shared_libs: ["libfoo"], + } + + apex_key { + name: "myapex.key", + public_key: "testkey.avbpubkey", + private_key: "testkey.pem", + } + + cc_library { + name: "libfoo", + stl: "none", + system_shared_libs: [], + apex_available: ["myapex"], + static: { + apex_available: ["//apex_available:platform"], + }, + }`) + + // shared variant of libfoo is only available to myapex + ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared_myapex") + ensureListNotContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_shared") + // but the static variant is available to both myapex and the platform + ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static_myapex") + ensureListContains(t, ctx.ModuleVariantsForTests("libfoo"), "android_arm64_armv8-a_core_static") } func TestMain(m *testing.M) { diff --git a/cc/cc.go b/cc/cc.go index 9031afec4..32d160eed 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -2152,6 +2152,16 @@ func (c *Module) IsInstallableToApex() bool { return false } +func (c *Module) AvailableFor(what string) bool { + if linker, ok := c.linker.(interface { + availableFor(string) bool + }); ok { + return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what) + } else { + return c.ApexModuleBase.AvailableFor(what) + } +} + func (c *Module) installable() bool { return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() } diff --git a/cc/library.go b/cc/library.go index 0fb3c7824..80dc76c18 100644 --- a/cc/library.go +++ b/cc/library.go @@ -131,6 +131,8 @@ type StaticOrSharedProperties struct { Export_shared_lib_headers []string `android:"arch_variant"` Export_static_lib_headers []string `android:"arch_variant"` + + Apex_available []string `android:"arch_variant"` } type LibraryMutatedProperties struct { @@ -573,6 +575,8 @@ type libraryInterface interface { // Write LOCAL_ADDITIONAL_DEPENDENCIES for ABI diff androidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) + + availableFor(string) bool } func (library *libraryDecorator) getLibName(ctx BaseModuleContext) string { @@ -1134,6 +1138,19 @@ func (library *libraryDecorator) stubsVersion() string { return library.MutatedProperties.StubsVersion } +func (library *libraryDecorator) availableFor(what string) bool { + var list []string + if library.static() { + list = library.StaticProperties.Static.Apex_available + } else if library.shared() { + list = library.SharedProperties.Shared.Apex_available + } + if len(list) == 0 { + return false + } + return android.CheckAvailableForApex(what, list) +} + var versioningMacroNamesListKey = android.NewOnceKey("versioningMacroNamesList") func versioningMacroNamesList(config android.Config) *map[string]string {