diff options
Diffstat (limited to 'apex/apex.go')
| -rw-r--r-- | apex/apex.go | 62 |
1 files changed, 50 insertions, 12 deletions
diff --git a/apex/apex.go b/apex/apex.go index 33b1be329..d908cd328 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -733,6 +733,30 @@ func (af *apexFile) Ok() bool { return af.builtFile != nil && af.builtFile.String() != "" } +// Path() returns path of this apex file relative to the APEX root +func (af *apexFile) Path() string { + return filepath.Join(af.installDir, af.builtFile.Base()) +} + +// SymlinkPaths() returns paths of the symlinks (if any) relative to the APEX root +func (af *apexFile) SymlinkPaths() []string { + var ret []string + for _, symlink := range af.symlinks { + ret = append(ret, filepath.Join(af.installDir, symlink)) + } + return ret +} + +func (af *apexFile) AvailableToPlatform() bool { + if af.module == nil { + return false + } + if am, ok := af.module.(android.ApexModule); ok { + return am.AvailableFor(android.AvailableToPlatform) + } + return false +} + type apexBundle struct { android.ModuleBase android.DefaultableModuleBase @@ -790,6 +814,10 @@ type apexBundle struct { suffix string installedFilesFile android.WritablePath + + // Whether to create symlink to the system file instead of having a file + // inside the apex or not + linkToSystemLib bool } func addDependenciesForNativeModules(ctx android.BottomUpMutatorContext, @@ -1414,7 +1442,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { // of the original test module (`depName`, shared by all `test_per_src` // variations of that module). af.moduleName = filepath.Base(af.builtFile.String()) - af.transitiveDep = true + // these are not considered transitive dep + af.transitiveDep = false filesInfo = append(filesInfo, af) return true // track transitive dependencies } @@ -1452,15 +1481,22 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { // remove duplicates in filesInfo removeDup := func(filesInfo []apexFile) []apexFile { - encountered := make(map[string]bool) - result := []apexFile{} + encountered := make(map[string]apexFile) for _, f := range filesInfo { dest := filepath.Join(f.installDir, f.builtFile.Base()) - if !encountered[dest] { - encountered[dest] = true - result = append(result, f) + if e, ok := encountered[dest]; !ok { + encountered[dest] = f + } else { + // If a module is directly included and also transitively depended on + // consider it as directly included. + e.transitiveDep = e.transitiveDep && f.transitiveDep + encountered[dest] = e } } + var result []apexFile + for _, v := range encountered { + result = append(result, v) + } return result } filesInfo = removeDup(filesInfo) @@ -1487,12 +1523,6 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { } } - // prepend the name of this APEX to the module names. These names will be the names of - // modules that will be defined if the APEX is flattened. - for i := range filesInfo { - filesInfo[i].moduleName = filesInfo[i].moduleName + "." + a.Name() + a.suffix - } - a.installDir = android.PathForModuleInstall(ctx, "apex") a.filesInfo = filesInfo @@ -1512,6 +1542,14 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { return } } + // Optimization. If we are building bundled APEX, for the files that are gathered due to the + // transitive dependencies, don't place them inside the APEX, but place a symlink pointing + // the same library in the system partition, thus effectively sharing the same libraries + // across the APEX boundary. For unbundled APEX, all the gathered files are actually placed + // in the APEX. + a.linkToSystemLib = !ctx.Config().UnbundledBuild() && + a.installable() && + !proptools.Bool(a.properties.Use_vendor) // prepare apex_manifest.json a.buildManifest(ctx, provideNativeLibs, requireNativeLibs) |