Extract generateUpdatableBcpPackagesRule from updatableBcpPackagesRule

This simplifies the process of moving the updatableBcpPackagesRule to
the platform_bootclasspath by separating the gathering of the list of
updatable modules (which differs between the singleton and the
platform_bootclasspath module) from the gathering of the permitted
packages list and generation of the rule which are generally common.

Bug: 177892522
Test: lunch art_module_arm64
      m out/soong/module_arm64/dex_bootjars/updatable-bcp-packages.txt
      - make sure it is not affected by this change
Change-Id: I3cb64310f618059758a32cfe00d3745d52388e49
This commit is contained in:
Paul Duffin 2021-04-26 19:45:11 +01:00
parent 2ac45f019b
commit 44d1594081
1 changed files with 25 additions and 15 deletions

View File

@ -893,28 +893,38 @@ func updatableBcpPackagesRule(ctx android.SingletonContext, image *bootImageConf
}
global := dexpreopt.GetGlobalConfig(ctx)
var modules []android.Module
updatableModules := global.UpdatableBootJars.CopyOfJars()
// Collect `permitted_packages` for updatable boot jars.
var updatablePackages []string
ctx.VisitAllModules(func(module android.Module) {
if !isActiveModule(module) {
return
}
if j, ok := module.(PermittedPackagesForUpdatableBootJars); ok {
name := ctx.ModuleName(module)
if i := android.IndexList(name, updatableModules); i != -1 {
modules = append(modules, module)
// Do not match the same library repeatedly.
updatableModules = append(updatableModules[:i], updatableModules[i+1:]...)
}
})
return generateUpdatableBcpPackagesRule(ctx, image, modules)
}
// generateUpdatableBcpPackagesRule generates the rule to create the updatable-bcp-packages.txt file
// and returns a path to the generated file.
func generateUpdatableBcpPackagesRule(ctx android.SingletonContext, image *bootImageConfig, updatableModules []android.Module) android.WritablePath {
// Collect `permitted_packages` for updatable boot jars.
var updatablePackages []string
for _, module := range updatableModules {
if j, ok := module.(PermittedPackagesForUpdatableBootJars); ok {
pp := j.PermittedPackagesForUpdatableBootJars()
if len(pp) > 0 {
updatablePackages = append(updatablePackages, pp...)
} else {
ctx.Errorf("Missing permitted_packages for %s", name)
}
// Do not match the same library repeatedly.
updatableModules = append(updatableModules[:i], updatableModules[i+1:]...)
ctx.Errorf("Missing permitted_packages for %s", ctx.ModuleName(module))
}
}
}
})
// Sort updatable packages to ensure deterministic ordering.
sort.Strings(updatablePackages)