make ApexProperties defaultable
ApexPropreties are added in InitApexModule() and they are supposed to be
defaultable. To be defaultable, InitApexModule() should be called before
InitDefaultableModule().
Bug: 144332048
Test: m (soong test added)
Change-Id: I6c90ed3b66a086292a4c0ecb37c61f83769e62bd
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 614164d..39b7322 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -115,6 +115,9 @@
ctx.RegisterModuleType("cc_prebuilt_library_static", android.ModuleFactoryAdaptor(cc.PrebuiltStaticLibraryFactory))
ctx.RegisterModuleType("cc_binary", android.ModuleFactoryAdaptor(cc.BinaryFactory))
ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory))
+ ctx.RegisterModuleType("cc_defaults", android.ModuleFactoryAdaptor(func() android.Module {
+ return cc.DefaultsFactory()
+ }))
ctx.RegisterModuleType("cc_test", android.ModuleFactoryAdaptor(cc.TestFactory))
ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory))
ctx.RegisterModuleType("vndk_prebuilt_shared", android.ModuleFactoryAdaptor(cc.VndkPrebuiltSharedFactory))
@@ -2586,6 +2589,40 @@
ensureContains(t, copyCmds, "image.apex/priv-app/AppFooPrivPrebuilt/AppFooPrivPrebuilt.apk")
}
+func TestApexPropertiesShouldBeDefaultable(t *testing.T) {
+ // libfoo's apex_available comes from cc_defaults
+ testApexError(t, `"myapex" .*: requires "libfoo" that is not available for the APEX`, `
+ apex {
+ name: "myapex",
+ key: "myapex.key",
+ native_shared_libs: ["libfoo"],
+ }
+
+ apex_key {
+ name: "myapex.key",
+ public_key: "testkey.avbpubkey",
+ private_key: "testkey.pem",
+ }
+
+ apex {
+ name: "otherapex",
+ key: "myapex.key",
+ native_shared_libs: ["libfoo"],
+ }
+
+ cc_defaults {
+ name: "libfoo-defaults",
+ apex_available: ["otherapex"],
+ }
+
+ cc_library {
+ name: "libfoo",
+ defaults: ["libfoo-defaults"],
+ stl: "none",
+ system_shared_libs: [],
+ }`)
+}
+
func TestApexAvailable(t *testing.T) {
// libfoo is not available to myapex, but only to otherapex
testApexError(t, "requires \"libfoo\" that is not available for the APEX", `