diff options
Diffstat (limited to 'java/dexpreopt.go')
-rw-r--r-- | java/dexpreopt.go | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/java/dexpreopt.go b/java/dexpreopt.go index b5830c744..ac00592a7 100644 --- a/java/dexpreopt.go +++ b/java/dexpreopt.go @@ -30,6 +30,7 @@ type dexpreopter struct { installPath android.InstallPath uncompressedDex bool isSDKLibrary bool + isApp bool isTest bool isPresignedPrebuilt bool @@ -38,6 +39,11 @@ type dexpreopter struct { classLoaderContexts dexpreopt.ClassLoaderContextMap builtInstalled string + + // A path to a dexpreopt.config file generated by Soong for libraries that may be used as a + // <uses-library> by Make modules. The path is passed to Make via LOCAL_SOONG_DEXPREOPT_CONFIG + // variable. If the path is nil, no config is generated (which is the case for apps and tests). + configPath android.WritablePath } type DexpreoptProperties struct { @@ -117,7 +123,40 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo // the dexpreopter struct hasn't been fully initialized before we're called, // e.g. in aar.go. This keeps the behaviour that dexpreopting is effectively // disabled, even if installable is true. - if d.dexpreoptDisabled(ctx) || d.installPath.Base() == "." { + if d.installPath.Base() == "." { + return + } + + dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath) + + buildPath := android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").OutputPath + + providesUsesLib := ctx.ModuleName() + if ulib, ok := ctx.Module().(ProvidesUsesLib); ok { + name := ulib.ProvidesUsesLib() + if name != nil { + providesUsesLib = *name + } + } + + if !d.isApp && !d.isTest { + // Slim dexpreopt config is serialized to dexpreopt.config files and used by + // dex_preopt_config_merger.py to get information about <uses-library> dependencies. + // Note that it might be needed even if dexpreopt is disabled for this module. + slimDexpreoptConfig := &dexpreopt.ModuleConfig{ + Name: ctx.ModuleName(), + DexLocation: dexLocation, + BuildPath: buildPath, + EnforceUsesLibraries: d.enforceUsesLibs, + ProvidesUsesLibrary: providesUsesLib, + ClassLoaderContexts: d.classLoaderContexts, + // The rest of the fields are not needed. + } + d.configPath = android.PathForModuleOut(ctx, "dexpreopt", "dexpreopt.config") + dexpreopt.WriteSlimModuleConfigForMake(ctx, slimDexpreoptConfig, d.configPath) + } + + if d.dexpreoptDisabled(ctx) { return } @@ -157,8 +196,6 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo // The image locations for all Android variants are identical. imageLocations := bootImage.getAnyAndroidVariant().imageLocations() - dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath) - var profileClassListing android.OptionalPath var profileBootListing android.OptionalPath profileIsTextListing := false @@ -177,10 +214,11 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo } } + // Full dexpreopt config, used to create dexpreopt build rules. dexpreoptConfig := &dexpreopt.ModuleConfig{ Name: ctx.ModuleName(), DexLocation: dexLocation, - BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").OutputPath, + BuildPath: buildPath, DexPath: dexJarFile, ManifestPath: d.manifestFile, UncompressedDex: d.uncompressedDex, @@ -192,6 +230,7 @@ func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.Mo ProfileBootListing: profileBootListing, EnforceUsesLibraries: d.enforceUsesLibs, + ProvidesUsesLibrary: providesUsesLib, ClassLoaderContexts: d.classLoaderContexts, Archs: archs, |