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
This commit is contained in:
parent
8785e55e1c
commit
a90ca00786
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
10
cc/cc.go
10
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()
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue