Add ApexModule interface for APEX-aware modules
ApexModule is the interface for APEX-aware modules. The module type apex
uses the interface to get APEX-specific information from other modules,
such as the list of APEXs that a module should be built for.
A module that is included in an APEX will be built specificaly for the
APEX. This is especially required for shared libraries; we shouldn't
just copy the artifacts built for platform, because they may be linking
against private (=unstable) symbols that are not available to APEXs
which are basically unbundled.
This CL, as a first step, makes cc.Module an APEX-aware module type.
Bug: 112672359
Test: m apex.test; the built apex has all the direct and transitive
shared lib dependencies of the libs and executables listed in Android.bp
Change-Id: I21f6a586654779984f0f5154b2a08b2adbf2168b
diff --git a/cc/cc.go b/cc/cc.go
index 5f3baea..6320b9c 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -320,6 +320,7 @@
type Module struct {
android.ModuleBase
android.DefaultableModuleBase
+ android.ApexModuleBase
Properties BaseProperties
VendorProperties VendorProperties
@@ -416,6 +417,8 @@
android.InitDefaultableModule(c)
+ android.InitApexModule(c)
+
return c
}
@@ -794,7 +797,7 @@
c.outputFile = android.OptionalPathForPath(outputFile)
}
- if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
+ if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
c.installer.install(ctx, c.outputFile.Path())
if ctx.Failed() {
return
@@ -1511,12 +1514,24 @@
}
}
+// Overrides ApexModule.IsInstallabeToApex()
+// Only shared libraries are installable to APEX.
+func (c *Module) IsInstallableToApex() bool {
+ if shared, ok := c.linker.(interface {
+ shared() bool
+ }); ok {
+ return shared.shared()
+ }
+ return false
+}
+
//
// Defaults
//
type Defaults struct {
android.ModuleBase
android.DefaultsModuleBase
+ android.ApexModuleBase
}
func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -1558,6 +1573,7 @@
)
android.InitDefaultsModule(module)
+ android.InitApexModule(module)
return module
}