diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/aar.go | 1 | ||||
-rw-r--r-- | java/androidmk.go | 29 | ||||
-rw-r--r-- | java/app.go | 64 | ||||
-rw-r--r-- | java/builder.go | 20 | ||||
-rw-r--r-- | java/config/config.go | 3 | ||||
-rw-r--r-- | java/config/makevars.go | 1 | ||||
-rw-r--r-- | java/dexpreopt.go | 246 | ||||
-rw-r--r-- | java/java.go | 45 | ||||
-rw-r--r-- | java/sdk_library.go | 13 |
9 files changed, 78 insertions, 344 deletions
diff --git a/java/aar.go b/java/aar.go index 89517fed..99e9136d 100644 --- a/java/aar.go +++ b/java/aar.go @@ -357,7 +357,6 @@ func AndroidLibraryFactory() android.Module { module.AddProperties( &module.Module.properties, &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, &module.Module.protoProperties, &module.aaptProperties, &module.androidLibraryProperties) diff --git a/java/androidmk.go b/java/androidmk.go index 70d0f7f9..0700b587 100644 --- a/java/androidmk.go +++ b/java/androidmk.go @@ -25,7 +25,7 @@ import ( func (library *Library) AndroidMk() android.AndroidMkData { return android.AndroidMkData{ Class: "JAVA_LIBRARIES", - OutputFile: android.OptionalPathForPath(library.outputFile), + OutputFile: android.OptionalPathForPath(library.implementationAndResourcesJar), Include: "$(BUILD_SYSTEM)/soong_java_prebuilt.mk", Extra: []android.AndroidMkExtraFunc{ func(w io.Writer, outputFile android.Path) { @@ -42,12 +42,21 @@ func (library *Library) AndroidMk() android.AndroidMkData { } if library.dexJarFile != nil { fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String()) - } - if len(library.dexpreopter.builtInstalled) > 0 { - fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", strings.Join(library.dexpreopter.builtInstalled, " ")) + if library.deviceProperties.Dex_preopt.Enabled != nil { + fmt.Fprintln(w, "LOCAL_DEX_PREOPT :=", *library.deviceProperties.Dex_preopt.Enabled) + } + if library.deviceProperties.Dex_preopt.App_image != nil { + fmt.Fprintln(w, "LOCAL_DEX_PREOPT_APP_IMAGE :=", *library.deviceProperties.Dex_preopt.App_image) + } + if library.deviceProperties.Dex_preopt.Profile_guided != nil { + fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE :=", *library.deviceProperties.Dex_preopt.Profile_guided) + } + if library.deviceProperties.Dex_preopt.Profile != nil { + fmt.Fprintln(w, "LOCAL_DEX_PREOPT_GENERATE_PROFILE := true") + fmt.Fprintln(w, "LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := $(LOCAL_PATH)/"+*library.deviceProperties.Dex_preopt.Profile) + } } fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", library.sdkVersion()) - fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String()) fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String()) if library.jacocoReportClassesFile != nil { @@ -75,6 +84,7 @@ func (library *Library) AndroidMk() android.AndroidMkData { fmt.Fprintln(w, "LOCAL_MODULE := "+name+"-hostdex") fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") fmt.Fprintln(w, "LOCAL_MODULE_CLASS := JAVA_LIBRARIES") + fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", library.implementationAndResourcesJar.String()) if library.installFile == nil { fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") } @@ -82,7 +92,6 @@ func (library *Library) AndroidMk() android.AndroidMkData { fmt.Fprintln(w, "LOCAL_SOONG_DEX_JAR :=", library.dexJarFile.String()) } fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", library.headerJarFile.String()) - fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", library.implementationAndResourcesJar.String()) fmt.Fprintln(w, "LOCAL_REQUIRED_MODULES := "+strings.Join(data.Required, " ")) fmt.Fprintln(w, "include $(BUILD_SYSTEM)/soong_java_prebuilt.mk") } @@ -119,7 +128,6 @@ func (prebuilt *Import) AndroidMk() android.AndroidMkData { func(w io.Writer, outputFile android.Path) { fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := ", !Bool(prebuilt.properties.Installable)) fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.combinedClasspathFile.String()) - fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.combinedClasspathFile.String()) fmt.Fprintln(w, "LOCAL_SDK_VERSION :=", prebuilt.sdkVersion()) }, }, @@ -134,8 +142,8 @@ func (prebuilt *AARImport) AndroidMk() android.AndroidMkData { Extra: []android.AndroidMkExtraFunc{ func(w io.Writer, outputFile android.Path) { fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") + fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", prebuilt.classpathFile.String()) - fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", prebuilt.classpathFile.String()) fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", prebuilt.exportPackage.String()) fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", prebuilt.proguardFlags.String()) fmt.Fprintln(w, "LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES :=", prebuilt.extraAaptPackagesFile.String()) @@ -156,7 +164,6 @@ func (binary *Binary) AndroidMk() android.AndroidMkData { Extra: []android.AndroidMkExtraFunc{ func(w io.Writer, outputFile android.Path) { fmt.Fprintln(w, "LOCAL_SOONG_HEADER_JAR :=", binary.headerJarFile.String()) - fmt.Fprintln(w, "LOCAL_SOONG_CLASSES_JAR :=", binary.implementationAndResourcesJar.String()) }, }, Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { @@ -243,9 +250,6 @@ func (app *AndroidApp) AndroidMk() android.AndroidMkData { for _, jniLib := range app.installJniLibs { fmt.Fprintln(w, "LOCAL_SOONG_JNI_LIBS_"+jniLib.target.Arch.ArchType.String(), "+=", jniLib.name) } - if len(app.dexpreopter.builtInstalled) > 0 { - fmt.Fprintln(w, "LOCAL_SOONG_BUILT_INSTALLED :=", strings.Join(app.dexpreopter.builtInstalled, " ")) - } }, }, } @@ -309,6 +313,7 @@ func (a *AndroidLibrary) AndroidMk() android.AndroidMkData { fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", strings.Join(a.exportedProguardFlagFiles.Strings(), " ")) fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true") + fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false") }) return data diff --git a/java/app.go b/java/app.go index b44fc344..392ad3fc 100644 --- a/java/app.go +++ b/java/app.go @@ -17,7 +17,6 @@ package java // This file contains the module types for compiling Android apps. import ( - "path/filepath" "strings" "github.com/google/blueprint" @@ -70,6 +69,7 @@ type appProperties struct { AllowDexPreopt bool `blueprint:"mutated"` EmbedJNI bool `blueprint:"mutated"` + StripDex bool `blueprint:"mutated"` } type AndroidApp struct { @@ -143,16 +143,42 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.generateAndroidBuildActions(ctx) } -// Returns whether this module should have the dex file stored uncompressed in the APK. -func (a *AndroidApp) shouldUncompressDex(ctx android.ModuleContext) bool { +// Returns whether this module should have the dex file stored uncompressed in the APK, or stripped completely. If +// stripped, the code will still be present on the device in the dexpreopted files. +// This is only necessary for APKs, and not jars, because APKs are signed and the dex file should not be uncompressed +// or removed after the signature has been generated. For jars, which are not signed, the dex file is uncompressed +// or removed at installation time in Make. +func (a *AndroidApp) uncompressOrStripDex(ctx android.ModuleContext) (uncompress, strip bool) { if ctx.Config().UnbundledBuild() { - return false + return false, false } + strip = ctx.Config().DefaultStripDex() + // TODO(ccross): don't strip dex installed on partitions that may be updated separately (like vendor) + // TODO(ccross): don't strip dex on modules with LOCAL_APK_LIBRARIES equivalent + // Uncompress dex in APKs of privileged apps, and modules used by privileged apps. - return ctx.Config().UncompressPrivAppDex() && + if ctx.Config().UncompressPrivAppDex() && (Bool(a.appProperties.Privileged) || - inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) + inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) { + + uncompress = true + // If the dex files is store uncompressed, don't strip it, we will reuse the uncompressed dex from the APK + // instead of copying it into the odex file. + strip = false + } + + // If dexpreopt is disabled, don't strip the dex file + if !a.appProperties.AllowDexPreopt || + !BoolDefault(a.deviceProperties.Dex_preopt.Enabled, true) || + ctx.Config().DisableDexPreopt(ctx.ModuleName()) { + strip = false + } + + // TODO(ccross): strip dexpropted modules that are not propted to system_other + strip = false + + return uncompress, strip } func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { @@ -202,25 +228,16 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...) a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile) - a.deviceProperties.UncompressDex = a.shouldUncompressDex(ctx) - - var installDir string - if ctx.ModuleName() == "framework-res" { - // framework-res.apk is installed as system/framework/framework-res.apk - installDir = "framework" - } else if Bool(a.appProperties.Privileged) { - installDir = filepath.Join("priv-app", ctx.ModuleName()) - } else { - installDir = filepath.Join("app", ctx.ModuleName()) - } - a.dexpreopter.installPath = android.PathForModuleInstall(ctx, installDir, ctx.ModuleName()+".apk") - a.dexpreopter.isPrivApp = Bool(a.appProperties.Privileged) + a.deviceProperties.UncompressDex, a.appProperties.StripDex = a.uncompressOrStripDex(ctx) if ctx.ModuleName() != "framework-res" { a.Module.compile(ctx, a.aaptSrcJar) } + dexJarFile := a.dexJarFile - dexJarFile := a.maybeStrippedDexJarFile + if a.appProperties.StripDex { + dexJarFile = nil + } var certificates []Certificate @@ -270,9 +287,9 @@ func (a *AndroidApp) generateAndroidBuildActions(ctx android.ModuleContext) { // framework-res.apk is installed as system/framework/framework-res.apk ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".apk", a.outputFile) } else if Bool(a.appProperties.Privileged) { - ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app", ctx.ModuleName()), ctx.ModuleName()+".apk", a.outputFile) + ctx.InstallFile(android.PathForModuleInstall(ctx, "priv-app"), ctx.ModuleName()+".apk", a.outputFile) } else { - ctx.InstallFile(android.PathForModuleInstall(ctx, "app", ctx.ModuleName()), ctx.ModuleName()+".apk", a.outputFile) + ctx.InstallFile(android.PathForModuleInstall(ctx, "app"), ctx.ModuleName()+".apk", a.outputFile) } } @@ -325,7 +342,6 @@ func AndroidAppFactory() android.Module { module.AddProperties( &module.Module.properties, &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, &module.Module.protoProperties, &module.aaptProperties, &module.appProperties) @@ -388,7 +404,6 @@ func AndroidTestFactory() android.Module { module.AddProperties( &module.Module.properties, &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, &module.Module.protoProperties, &module.aaptProperties, &module.appProperties, @@ -424,7 +439,6 @@ func AndroidTestHelperAppFactory() android.Module { module.AddProperties( &module.Module.properties, &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, &module.Module.protoProperties, &module.aaptProperties, &module.appProperties, diff --git a/java/builder.go b/java/builder.go index 86156649..cefb916d 100644 --- a/java/builder.go +++ b/java/builder.go @@ -138,17 +138,6 @@ var ( CommandDeps: []string{"${config.JavaCmd}", "${config.JetifierJar}"}, }, ) - - zipalign = pctx.AndroidStaticRule("zipalign", - blueprint.RuleParams{ - Command: "if ! ${config.ZipAlign} -c 4 $in > /dev/null; then " + - "${config.ZipAlign} -f 4 $in $out; " + - "else " + - "cp -f $in $out; " + - "fi", - CommandDeps: []string{"${config.ZipAlign}"}, - }, - ) ) func init() { @@ -421,15 +410,6 @@ func GenerateMainClassManifest(ctx android.ModuleContext, outputFile android.Wri }) } -func TransformZipAlign(ctx android.ModuleContext, outputFile android.WritablePath, inputFile android.Path) { - ctx.Build(pctx, android.BuildParams{ - Rule: zipalign, - Description: "align", - Input: inputFile, - Output: outputFile, - }) -} - type classpath []android.Path func (x *classpath) FormJavaClassPath(optName string) string { diff --git a/java/config/config.go b/java/config/config.go index da4eed7b..d2a8c467 100644 --- a/java/config/config.go +++ b/java/config/config.go @@ -126,7 +126,6 @@ func init() { pctx.HostJavaToolVariable("JetifierJar", "jetifier.jar") pctx.HostBinToolVariable("SoongJavacWrapper", "soong_javac_wrapper") - pctx.HostBinToolVariable("DexpreoptGen", "dexpreopt_gen") pctx.VariableFunc("JavacWrapper", func(ctx android.PackageVarContext) string { if override := ctx.Config().Getenv("JAVAC_WRAPPER"); override != "" { @@ -153,6 +152,4 @@ func init() { pctx.SourcePathsVariable("ManifestMergerJars", " ", ManifestMergerClasspath...) pctx.SourcePathsVariable("ManifestMergerClasspath", ":", ManifestMergerClasspath...) - - pctx.HostBinToolVariable("ZipAlign", "zipalign") } diff --git a/java/config/makevars.go b/java/config/makevars.go index 01adaa7d..275f4966 100644 --- a/java/config/makevars.go +++ b/java/config/makevars.go @@ -65,7 +65,6 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("JMOD", "${JmodCmd}") ctx.Strict("SOONG_JAVAC_WRAPPER", "${SoongJavacWrapper}") - ctx.Strict("DEXPREOPT_GEN", "${DexpreoptGen}") ctx.Strict("ZIPSYNC", "${ZipSyncCmd}") ctx.Strict("JACOCO_CLI_JAR", "${JacocoCLIJar}") diff --git a/java/dexpreopt.go b/java/dexpreopt.go deleted file mode 100644 index 3ee1205e..00000000 --- a/java/dexpreopt.go +++ /dev/null @@ -1,246 +0,0 @@ -// Copyright 2018 Google Inc. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package java - -import ( - "path/filepath" - "strings" - - "github.com/google/blueprint" - "github.com/google/blueprint/proptools" - - "android/soong/android" - "android/soong/dexpreopt" -) - -type dexpreopter struct { - dexpreoptProperties DexpreoptProperties - - installPath android.OutputPath - isPrivApp bool - isSDKLibrary bool - - builtInstalled []string -} - -type DexpreoptProperties struct { - Dex_preopt struct { - // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to - // true. - Enabled *bool - - // If true, generate an app image (.art file) for this module. - App_image *bool - - // If true, use a checked-in profile to guide optimization. Defaults to false unless - // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR - // that matches the name of this module, in which case it is defaulted to true. - Profile_guided *bool - - // If set, provides the path to profile relative to the Android.bp file. If not set, - // defaults to searching for a file that matches the name of this module in the default - // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found. - Profile *string - } -} - -func (d *dexpreopter) dexpreoptDisabled(ctx android.ModuleContext) bool { - if ctx.Config().DisableDexPreopt(ctx.ModuleName()) { - return true - } - - if ctx.Config().UnbundledBuild() { - return true - } - - if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) { - return true - } - - // TODO: contains no java code - // TODO: is test - - return false -} - -func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.ModuleOutPath) android.ModuleOutPath { - if d.dexpreoptDisabled(ctx) { - return dexJarFile - } - - globalConfig := ctx.Config().Once("DexpreoptGlobalConfig", func() interface{} { - if f := ctx.Config().DexpreoptGlobalConfig(); f != "" { - ctx.AddNinjaFileDeps(f) - globalConfig, err := dexpreopt.LoadGlobalConfig(f) - if err != nil { - panic(err) - } - return globalConfig - } - return dexpreopt.GlobalConfig{} - }).(dexpreopt.GlobalConfig) - - var archs []string - for _, a := range ctx.MultiTargets() { - archs = append(archs, a.Arch.ArchType.String()) - } - if len(archs) == 0 { - // assume this is a java library, dexpreopt for all arches for now - for _, target := range ctx.Config().Targets[android.Android] { - archs = append(archs, target.Arch.ArchType.String()) - } - if inList(ctx.ModuleName(), globalConfig.SystemServerJars) && !d.isSDKLibrary { - // If the module is not an SDK library and it's a system server jar, only preopt the primary arch. - archs = archs[:1] - } - } - if ctx.Config().SecondArchIsTranslated() { - // Only preopt primary arch for translated arch since there is only an image there. - archs = archs[:1] - } - - dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath) - - strippedDexJarFile := android.PathForModuleOut(ctx, "dexpreopt", dexJarFile.Base()) - - deps := android.Paths{dexJarFile} - - var profileClassListing android.OptionalPath - profileIsTextListing := false - if BoolDefault(d.dexpreoptProperties.Dex_preopt.Profile_guided, true) { - // If dex_preopt.profile_guided is not set, default it based on the existence of the - // dexprepot.profile option or the profile class listing. - if String(d.dexpreoptProperties.Dex_preopt.Profile) != "" { - profileClassListing = android.OptionalPathForPath( - android.PathForModuleSrc(ctx, String(d.dexpreoptProperties.Dex_preopt.Profile))) - profileIsTextListing = true - } else { - profileClassListing = android.ExistentPathForSource(ctx, - ctx.Config().DexPreoptProfileDir(), ctx.ModuleName()+".prof") - } - } - - if profileClassListing.Valid() { - deps = append(deps, profileClassListing.Path()) - } - - uncompressedDex := false - if ctx.Config().UncompressPrivAppDex() && - (d.isPrivApp || inList(ctx.ModuleName(), ctx.Config().ModulesLoadedByPrivilegedModules())) { - uncompressedDex = true - } - - dexpreoptConfig := dexpreopt.ModuleConfig{ - Name: ctx.ModuleName(), - DexLocation: dexLocation, - BuildPath: android.PathForModuleOut(ctx, "dexpreopt", ctx.ModuleName()+".jar").String(), - DexPath: dexJarFile.String(), - PreferIntegrity: false, - UncompressedDex: uncompressedDex, - HasApkLibraries: false, - PreoptFlags: nil, - - ProfileClassListing: profileClassListing.String(), - ProfileIsTextListing: profileIsTextListing, - - EnforceUsesLibraries: false, - OptionalUsesLibraries: nil, - UsesLibraries: nil, - LibraryPaths: nil, - - Archs: archs, - DexPreoptImageLocation: "", - - PreoptExtractedApk: false, - - NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true), - ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false), - - StripInputPath: dexJarFile.String(), - StripOutputPath: strippedDexJarFile.String(), - } - - dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(globalConfig, dexpreoptConfig) - if err != nil { - ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error()) - return dexJarFile - } - - var inputs android.Paths - for _, input := range dexpreoptRule.Inputs() { - if input == "" { - // Tests sometimes have empty configuration values that lead to empty inputs - continue - } - rel, isRel := android.MaybeRel(ctx, android.PathForModuleOut(ctx).String(), input) - if isRel { - inputs = append(inputs, android.PathForModuleOut(ctx, rel)) - } else { - // TODO: use PathForOutput once boot image is moved to where PathForOutput can find it. - inputs = append(inputs, &bootImagePath{input}) - } - } - - var outputs android.WritablePaths - for _, output := range dexpreoptRule.Outputs() { - rel := android.Rel(ctx, android.PathForModuleOut(ctx).String(), output) - outputs = append(outputs, android.PathForModuleOut(ctx, rel)) - } - - for _, install := range dexpreoptRule.Installs() { - d.builtInstalled = append(d.builtInstalled, install.From+":"+install.To) - } - - if len(dexpreoptRule.Commands()) > 0 { - ctx.Build(pctx, android.BuildParams{ - Rule: ctx.Rule(pctx, "dexpreopt", blueprint.RuleParams{ - Command: strings.Join(proptools.NinjaEscape(dexpreoptRule.Commands()), " && "), - CommandDeps: dexpreoptRule.Tools(), - }), - Implicits: inputs, - Outputs: outputs, - Description: "dexpreopt", - }) - } - - stripRule, err := dexpreopt.GenerateStripRule(globalConfig, dexpreoptConfig) - if err != nil { - ctx.ModuleErrorf("error generating dexpreopt strip rule: %s", err.Error()) - return dexJarFile - } - - ctx.Build(pctx, android.BuildParams{ - Rule: ctx.Rule(pctx, "dexpreopt_strip", blueprint.RuleParams{ - Command: strings.Join(proptools.NinjaEscape(stripRule.Commands()), " && "), - CommandDeps: stripRule.Tools(), - }), - Input: dexJarFile, - Output: strippedDexJarFile, - Description: "dexpreopt strip", - }) - - return strippedDexJarFile -} - -type bootImagePath struct { - path string -} - -var _ android.Path = (*bootImagePath)(nil) - -func (p *bootImagePath) String() string { return p.path } -func (p *bootImagePath) Ext() string { return filepath.Ext(p.path) } -func (p *bootImagePath) Base() string { return filepath.Base(p.path) } -func (p *bootImagePath) Rel() string { return p.path } diff --git a/java/java.go b/java/java.go index aea1ef90..5ed99f7e 100644 --- a/java/java.go +++ b/java/java.go @@ -217,6 +217,25 @@ type CompilerDeviceProperties struct { // If set to true, compile dex regardless of installable. Defaults to false. Compile_dex *bool + Dex_preopt struct { + // If false, prevent dexpreopting and stripping the dex file from the final jar. Defaults to + // true. + Enabled *bool + + // If true, generate an app image (.art file) for this module. + App_image *bool + + // If true, use a checked-in profile to guide optimization. Defaults to false unless + // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR + // that matches the name of this module, in which case it is defaulted to true. + Profile_guided *bool + + // If set, provides the path to profile relative to the Android.bp file. If not set, + // defaults to searching for a file that matches the name of this module in the default + // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found. + Profile *string + } + Optimize struct { // If false, disable all optimization. Defaults to true for android_app and android_test // modules, false for java_library and java_test modules. @@ -247,7 +266,6 @@ type CompilerDeviceProperties struct { System_modules *string UncompressDex bool `blueprint:"mutated"` - IsSDKLibrary bool `blueprint:"mutated"` } // Module contains the properties and members used by all java module types @@ -277,9 +295,6 @@ type Module struct { // output file containing classes.dex and resources dexJarFile android.Path - // output file that contains classes.dex if it should be in the output file - maybeStrippedDexJarFile android.Path - // output file containing uninstrumented classes that will be instrumented by jacoco jacocoReportClassesFile android.Path @@ -312,8 +327,6 @@ type Module struct { // list of source files, collected from compiledJavaSrcs and compiledSrcJars // filter out Exclude_srcs, will be used by android.IDEInfo struct expandIDEInfoCompiledSrcs []string - - dexpreopter } func (j *Module) Srcs() android.Paths { @@ -1319,15 +1332,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path j.dexJarFile = dexOutputFile - dexOutputFile = j.dexpreopt(ctx, dexOutputFile) - - j.maybeStrippedDexJarFile = dexOutputFile - outputFile = dexOutputFile - - if ctx.Failed() { - return - } } else { outputFile = implementationAndResourcesJar } @@ -1481,17 +1486,9 @@ type Library struct { } func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) { - j.dexpreopter.installPath = android.PathForModuleInstall(ctx, "framework", ctx.ModuleName()+".jar") - j.dexpreopter.isSDKLibrary = j.deviceProperties.IsSDKLibrary j.compile(ctx) if Bool(j.properties.Installable) || ctx.Host() { - if j.deviceProperties.UncompressDex { - alignedOutputFile := android.PathForModuleOut(ctx, "aligned", ctx.ModuleName()+".jar") - TransformZipAlign(ctx, alignedOutputFile, j.outputFile) - j.outputFile = alignedOutputFile - } - j.installFile = ctx.InstallFile(android.PathForModuleInstall(ctx, "framework"), ctx.ModuleName()+".jar", j.outputFile) } @@ -1507,7 +1504,6 @@ func LibraryFactory() android.Module { module.AddProperties( &module.Module.properties, &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, &module.Module.protoProperties) InitJavaModule(module, android.HostAndDeviceSupported) @@ -1578,7 +1574,6 @@ func TestFactory() android.Module { module.AddProperties( &module.Module.properties, &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, &module.Module.protoProperties, &module.testProperties) @@ -1675,7 +1670,6 @@ func BinaryFactory() android.Module { module.AddProperties( &module.Module.properties, &module.Module.deviceProperties, - &module.Module.dexpreoptProperties, &module.Module.protoProperties, &module.binaryProperties) @@ -1895,7 +1889,6 @@ func DefaultsFactory(props ...interface{}) android.Module { module.AddProperties( &CompilerProperties{}, &CompilerDeviceProperties{}, - &DexpreoptProperties{}, &android.ProtoProperties{}, &aaptProperties{}, &androidLibraryProperties{}, diff --git a/java/sdk_library.go b/java/sdk_library.go index 877abe48..fdbf19d2 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -141,9 +141,8 @@ type sdkLibrary struct { android.ModuleBase android.DefaultableModuleBase - properties sdkLibraryProperties - deviceProperties CompilerDeviceProperties - dexpreoptProperties DexpreoptProperties + properties sdkLibraryProperties + deviceProperties CompilerDeviceProperties publicApiStubsPath android.Paths systemApiStubsPath android.Paths @@ -565,7 +564,6 @@ func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext) Errorprone struct { Javacflags []string } - IsSDKLibrary bool }{} props.Name = proptools.StringPtr(module.implName()) @@ -576,7 +574,6 @@ func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext) // XML file is installed along with the impl lib props.Required = []string{module.xmlFileName()} props.Errorprone.Javacflags = module.properties.Errorprone.Javacflags - props.IsSDKLibrary = true if module.SocSpecific() { props.Soc_specific = proptools.BoolPtr(true) @@ -586,10 +583,7 @@ func (module *sdkLibrary) createImplLibrary(mctx android.TopDownMutatorContext) props.Product_specific = proptools.BoolPtr(true) } - mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), - &props, - &module.deviceProperties, - &module.dexpreoptProperties) + mctx.CreateModule(android.ModuleFactoryAdaptor(LibraryFactory), &props, &module.deviceProperties) } // Creates the xml file that publicizes the runtime library @@ -722,7 +716,6 @@ func sdkLibraryFactory() android.Module { module := &sdkLibrary{} module.AddProperties(&module.properties) module.AddProperties(&module.deviceProperties) - module.AddProperties(&module.dexpreoptProperties) InitJavaModule(module, android.DeviceSupported) return module } |