summaryrefslogtreecommitdiff
path: root/apex/apex.go
diff options
context:
space:
mode:
author Treehugger Robot <treehugger-gerrit@google.com> 2019-09-17 17:14:48 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2019-09-17 17:14:48 +0000
commit1f6c94a3ac5cc86c81a3a8e9ed5561d0e1e9c5fc (patch)
treeab7a4ef7ef80c556858c92a67881f6365558b777 /apex/apex.go
parentb204303b35f36a21d38ef042cde8d122a539ed05 (diff)
parent344d5439c145baddbe85297a5c435da28ee6fcff (diff)
Merge "Add "apex_vndk" module type"
Diffstat (limited to 'apex/apex.go')
-rw-r--r--apex/apex.go116
1 files changed, 103 insertions, 13 deletions
diff --git a/apex/apex.go b/apex/apex.go
index 1b5cbe5d9..4f79c4227 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -21,6 +21,7 @@ import (
"runtime"
"sort"
"strings"
+ "sync"
"android/soong/android"
"android/soong/cc"
@@ -153,6 +154,7 @@ var (
"com.android.media": []string{"libbinder"},
"com.android.media.swcodec": []string{"libbinder"},
"test_com.android.media.swcodec": []string{"libbinder"},
+ "com.android.vndk": []string{"libbinder"},
}
)
@@ -185,9 +187,14 @@ func init() {
android.RegisterModuleType("apex", apexBundleFactory)
android.RegisterModuleType("apex_test", testApexBundleFactory)
+ android.RegisterModuleType("apex_vndk", vndkApexBundleFactory)
android.RegisterModuleType("apex_defaults", defaultsFactory)
android.RegisterModuleType("prebuilt_apex", PrebuiltFactory)
+ android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
+ ctx.TopDown("apex_vndk_gather", apexVndkGatherMutator).Parallel()
+ ctx.BottomUp("apex_vndk_add_deps", apexVndkAddDepsMutator).Parallel()
+ })
android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
ctx.TopDown("apex_deps", apexDepsMutator)
ctx.BottomUp("apex", apexMutator).Parallel()
@@ -196,6 +203,51 @@ func init() {
})
}
+var (
+ vndkApexListKey = android.NewOnceKey("vndkApexList")
+ vndkApexListMutex sync.Mutex
+)
+
+func vndkApexList(config android.Config) map[string]*apexBundle {
+ return config.Once(vndkApexListKey, func() interface{} {
+ return map[string]*apexBundle{}
+ }).(map[string]*apexBundle)
+}
+
+// apexVndkGatherMutator gathers "apex_vndk" modules and puts them in a map with vndk_version as a key.
+func apexVndkGatherMutator(mctx android.TopDownMutatorContext) {
+ if ab, ok := mctx.Module().(*apexBundle); ok && ab.vndkApex {
+ if ab.IsNativeBridgeSupported() {
+ mctx.PropertyErrorf("native_bridge_supported", "%q doesn't support native bridge binary.", mctx.ModuleType())
+ }
+ vndkVersion := proptools.StringDefault(ab.vndkProperties.Vndk_version, mctx.DeviceConfig().PlatformVndkVersion())
+ vndkApexListMutex.Lock()
+ defer vndkApexListMutex.Unlock()
+ vndkApexList := vndkApexList(mctx.Config())
+ if other, ok := vndkApexList[vndkVersion]; ok {
+ mctx.PropertyErrorf("vndk_version", "%v is already defined in %q", vndkVersion, other.Name())
+ }
+ vndkApexList[vndkVersion] = ab
+ }
+}
+
+// apexVndkAddDepsMutator adds (reverse) dependencies from vndk libs to apex_vndk modules.
+// It filters only libs with matching targets.
+func apexVndkAddDepsMutator(mctx android.BottomUpMutatorContext) {
+ if cc, ok := mctx.Module().(*cc.Module); ok && cc.IsVndkOnSystem() {
+ vndkApexList := vndkApexList(mctx.Config())
+ if ab, ok := vndkApexList[cc.VndkVersion()]; ok {
+ targetArch := cc.Target().String()
+ for _, target := range ab.MultiTargets() {
+ if target.String() == targetArch {
+ mctx.AddReverseDependency(mctx.Module(), sharedLibTag, ab.Name())
+ break
+ }
+ }
+ }
+ }
+}
+
// Mark the direct and transitive dependencies of apex bundles so that they
// can be built for the apex bundles.
func apexDepsMutator(mctx android.TopDownMutatorContext) {
@@ -253,11 +305,14 @@ func apexUsesMutator(mctx android.BottomUpMutatorContext) {
type apexNativeDependencies struct {
// List of native libraries
Native_shared_libs []string
+
// List of native executables
Binaries []string
+
// List of native tests
Tests []string
}
+
type apexMultilibProperties struct {
// Native dependencies whose compile_multilib is "first"
First apexNativeDependencies
@@ -362,14 +417,17 @@ type apexTargetBundleProperties struct {
Android struct {
Multilib apexMultilibProperties
}
+
// Multilib properties only for host.
Host struct {
Multilib apexMultilibProperties
}
+
// Multilib properties only for host linux_bionic.
Linux_bionic struct {
Multilib apexMultilibProperties
}
+
// Multilib properties only for host linux_glibc.
Linux_glibc struct {
Multilib apexMultilibProperties
@@ -377,6 +435,11 @@ type apexTargetBundleProperties struct {
}
}
+type apexVndkProperties struct {
+ // Indicates VNDK version of which this VNDK APEX bundles VNDK libs. Default is Platform VNDK Version.
+ Vndk_version *string
+}
+
type apexFileClass int
const (
@@ -475,6 +538,7 @@ type apexBundle struct {
properties apexBundleProperties
targetProperties apexTargetBundleProperties
+ vndkProperties apexVndkProperties
apexTypes apexPackaging
@@ -498,6 +562,7 @@ type apexBundle struct {
externalDeps []string
testApex bool
+ vndkApex bool
// intermediate path for apex_manifest.json
manifestOut android.WritablePath
@@ -1086,11 +1151,12 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// remove duplicates in filesInfo
removeDup := func(filesInfo []apexFile) []apexFile {
- encountered := make(map[android.Path]bool)
+ encountered := make(map[string]bool)
result := []apexFile{}
for _, f := range filesInfo {
- if !encountered[f.builtFile] {
- encountered[f.builtFile] = true
+ dest := filepath.Join(f.installDir, f.builtFile.Base())
+ if !encountered[dest] {
+ encountered[dest] = true
result = append(result, f)
}
}
@@ -1629,18 +1695,9 @@ func (a *apexBundle) androidMkForType(apexType apexPackaging) android.AndroidMkD
}}
}
-func testApexBundleFactory() android.Module {
- return ApexBundleFactory(true /*testApex*/)
-}
-
-func apexBundleFactory() android.Module {
- return ApexBundleFactory(false /*testApex*/)
-}
-
-func ApexBundleFactory(testApex bool) android.Module {
+func newApexBundle() *apexBundle {
module := &apexBundle{
outputFiles: map[apexPackaging]android.WritablePath{},
- testApex: testApex,
}
module.AddProperties(&module.properties)
module.AddProperties(&module.targetProperties)
@@ -1652,6 +1709,39 @@ func ApexBundleFactory(testApex bool) android.Module {
return module
}
+func ApexBundleFactory(testApex bool) android.Module {
+ bundle := newApexBundle()
+ bundle.testApex = testApex
+ return bundle
+}
+
+func testApexBundleFactory() android.Module {
+ bundle := newApexBundle()
+ bundle.testApex = true
+ return bundle
+}
+
+func apexBundleFactory() android.Module {
+ return newApexBundle()
+}
+
+// apex_vndk creates a special variant of apex modules which contains only VNDK libraries.
+// If `vndk_version` is specified, the VNDK libraries of the specified VNDK version are gathered automatically.
+// If not specified, then the "current" versions are gathered.
+func vndkApexBundleFactory() android.Module {
+ bundle := newApexBundle()
+ bundle.vndkApex = true
+ bundle.AddProperties(&bundle.vndkProperties)
+ android.AddLoadHook(bundle, func(ctx android.LoadHookContext) {
+ ctx.AppendProperties(&struct {
+ Compile_multilib *string
+ }{
+ proptools.StringPtr("both"),
+ })
+ })
+ return bundle
+}
+
//
// Defaults
//