Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 18 | "path/filepath" |
| 19 | "strings" |
| 20 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 21 | "android/soong/android" |
| 22 | "android/soong/dexpreopt" |
| 23 | ) |
| 24 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 25 | type DexpreopterInterface interface { |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 26 | IsInstallable() bool // Structs that embed dexpreopter must implement this. |
| 27 | dexpreoptDisabled(ctx android.BaseModuleContext) bool |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 28 | DexpreoptBuiltInstalledForApex() []dexpreopterInstall |
| 29 | AndroidMkEntriesForApex() []android.AndroidMkEntries |
| 30 | } |
| 31 | |
| 32 | type dexpreopterInstall struct { |
| 33 | // A unique name to distinguish an output from others for the same java library module. Usually in |
| 34 | // the form of `<arch>-<encoded-path>.odex/vdex/art`. |
| 35 | name string |
| 36 | |
| 37 | // The name of the input java module. |
| 38 | moduleName string |
| 39 | |
| 40 | // The path to the dexpreopt output on host. |
| 41 | outputPathOnHost android.Path |
| 42 | |
| 43 | // The directory on the device for the output to install to. |
| 44 | installDirOnDevice android.InstallPath |
| 45 | |
| 46 | // The basename (the last segment of the path) for the output to install as. |
| 47 | installFileOnDevice string |
| 48 | } |
| 49 | |
| 50 | // The full module name of the output in the makefile. |
| 51 | func (install *dexpreopterInstall) FullModuleName() string { |
| 52 | return install.moduleName + install.SubModuleName() |
| 53 | } |
| 54 | |
| 55 | // The sub-module name of the output in the makefile (the name excluding the java module name). |
| 56 | func (install *dexpreopterInstall) SubModuleName() string { |
| 57 | return "-dexpreopt-" + install.name |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 60 | type dexpreopter struct { |
| 61 | dexpreoptProperties DexpreoptProperties |
| 62 | |
Colin Cross | 70dda7e | 2019-10-01 22:05:35 -0700 | [diff] [blame] | 63 | installPath android.InstallPath |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 64 | uncompressedDex bool |
| 65 | isSDKLibrary bool |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 66 | isApp bool |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 67 | isTest bool |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 68 | isPresignedPrebuilt bool |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 69 | |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 70 | manifestFile android.Path |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 71 | statusFile android.WritablePath |
Ulya Trafimovich | 8cbc5d2 | 2020-11-03 15:15:46 +0000 | [diff] [blame] | 72 | enforceUsesLibs bool |
| 73 | classLoaderContexts dexpreopt.ClassLoaderContextMap |
Colin Cross | 50ddcc4 | 2019-05-16 12:28:22 -0700 | [diff] [blame] | 74 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 75 | // See the `dexpreopt` function for details. |
| 76 | builtInstalled string |
| 77 | builtInstalledForApex []dexpreopterInstall |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 78 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 79 | // The config is used for two purposes: |
| 80 | // - Passing dexpreopt information about libraries from Soong to Make. This is needed when |
| 81 | // a <uses-library> is defined in Android.bp, but used in Android.mk (see dex_preopt_config_merger.py). |
| 82 | // Note that dexpreopt.config might be needed even if dexpreopt is disabled for the library itself. |
| 83 | // - Dexpreopt post-processing (using dexpreopt artifacts from a prebuilt system image to incrementally |
| 84 | // dexpreopt another partition). |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 85 | configPath android.WritablePath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | type DexpreoptProperties struct { |
| 89 | Dex_preopt struct { |
Nicolas Geoffray | c1bf724 | 2019-10-18 14:51:38 +0100 | [diff] [blame] | 90 | // If false, prevent dexpreopting. Defaults to true. |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 91 | Enabled *bool |
| 92 | |
| 93 | // If true, generate an app image (.art file) for this module. |
| 94 | App_image *bool |
| 95 | |
| 96 | // If true, use a checked-in profile to guide optimization. Defaults to false unless |
| 97 | // a matching profile is set or a profile is found in PRODUCT_DEX_PREOPT_PROFILE_DIR |
| 98 | // that matches the name of this module, in which case it is defaulted to true. |
| 99 | Profile_guided *bool |
| 100 | |
| 101 | // If set, provides the path to profile relative to the Android.bp file. If not set, |
| 102 | // defaults to searching for a file that matches the name of this module in the default |
| 103 | // profile location set by PRODUCT_DEX_PREOPT_PROFILE_DIR, or empty if not found. |
Colin Cross | de4e4e6 | 2019-04-26 10:52:32 -0700 | [diff] [blame] | 104 | Profile *string `android:"path"` |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
Ulya Trafimovich | 6cf2c0c | 2020-04-24 12:15:20 +0100 | [diff] [blame] | 108 | func init() { |
| 109 | dexpreopt.DexpreoptRunningInSoong = true |
| 110 | } |
| 111 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 112 | func isApexVariant(ctx android.BaseModuleContext) bool { |
| 113 | apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo) |
| 114 | return !apexInfo.IsForPlatform() |
| 115 | } |
| 116 | |
| 117 | func moduleName(ctx android.BaseModuleContext) string { |
| 118 | // Remove the "prebuilt_" prefix if the module is from a prebuilt because the prefix is not |
| 119 | // expected by dexpreopter. |
| 120 | return android.RemoveOptionalPrebuiltPrefix(ctx.ModuleName()) |
| 121 | } |
| 122 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 123 | func (d *dexpreopter) dexpreoptDisabled(ctx android.BaseModuleContext) bool { |
Martin Stjernholm | 40f9f3c | 2020-01-20 18:12:23 +0000 | [diff] [blame] | 124 | global := dexpreopt.GetGlobalConfig(ctx) |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 125 | |
| 126 | if global.DisablePreopt { |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 127 | return true |
| 128 | } |
| 129 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 130 | if inList(moduleName(ctx), global.DisablePreoptModules) { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 131 | return true |
| 132 | } |
| 133 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 134 | if d.isTest { |
| 135 | return true |
| 136 | } |
| 137 | |
| 138 | if !BoolDefault(d.dexpreoptProperties.Dex_preopt.Enabled, true) { |
| 139 | return true |
| 140 | } |
| 141 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 142 | if !ctx.Module().(DexpreopterInterface).IsInstallable() { |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 143 | return true |
| 144 | } |
| 145 | |
| 146 | if ctx.Host() { |
Colin Cross | dc2da91 | 2019-01-05 22:13:05 -0800 | [diff] [blame] | 147 | return true |
| 148 | } |
| 149 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 150 | if isApexVariant(ctx) { |
| 151 | // Don't preopt APEX variant module unless the module is an APEX system server jar and we are |
| 152 | // building the entire system image. |
| 153 | if !global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) || ctx.Config().UnbundledBuild() { |
| 154 | return true |
| 155 | } |
| 156 | } else { |
| 157 | // Don't preopt the platform variant of an APEX system server jar to avoid conflicts. |
| 158 | if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { |
| 159 | return true |
| 160 | } |
Yo Chiang | dbdf8f9 | 2020-01-09 19:00:27 +0800 | [diff] [blame] | 161 | } |
| 162 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 163 | // TODO: contains no java code |
| 164 | |
| 165 | return false |
| 166 | } |
| 167 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 168 | func dexpreoptToolDepsMutator(ctx android.BottomUpMutatorContext) { |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 169 | if d, ok := ctx.Module().(DexpreopterInterface); !ok || d.dexpreoptDisabled(ctx) { |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 170 | return |
| 171 | } |
| 172 | dexpreopt.RegisterToolDeps(ctx) |
| 173 | } |
| 174 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 175 | func (d *dexpreopter) odexOnSystemOther(ctx android.ModuleContext, installPath android.InstallPath) bool { |
| 176 | return dexpreopt.OdexOnSystemOtherByName(moduleName(ctx), android.InstallPathToOnDevicePath(ctx, installPath), dexpreopt.GetGlobalConfig(ctx)) |
| 177 | } |
| 178 | |
| 179 | // Returns the install path of the dex jar of a module. |
| 180 | // |
| 181 | // Do not rely on `ApexInfo.ApexVariationName` because it can be something like "apex1000", rather |
| 182 | // than the `name` in the path `/apex/<name>` as suggested in its comment. |
| 183 | // |
| 184 | // This function is on a best-effort basis. It cannot handle the case where an APEX jar is not a |
| 185 | // system server jar, which is fine because we currently only preopt system server jars for APEXes. |
| 186 | func (d *dexpreopter) getInstallPath( |
| 187 | ctx android.ModuleContext, defaultInstallPath android.InstallPath) android.InstallPath { |
| 188 | global := dexpreopt.GetGlobalConfig(ctx) |
| 189 | if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { |
| 190 | dexLocation := dexpreopt.GetSystemServerDexLocation(global, moduleName(ctx)) |
| 191 | return android.PathForModuleInPartitionInstall(ctx, "", strings.TrimPrefix(dexLocation, "/")) |
| 192 | } |
| 193 | if !d.dexpreoptDisabled(ctx) && isApexVariant(ctx) && |
| 194 | filepath.Base(defaultInstallPath.PartitionDir()) != "apex" { |
| 195 | ctx.ModuleErrorf("unable to get the install path of the dex jar for dexpreopt") |
| 196 | } |
| 197 | return defaultInstallPath |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Paul Duffin | 612e610 | 2021-02-02 13:38:13 +0000 | [diff] [blame] | 200 | func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.WritablePath) { |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 201 | global := dexpreopt.GetGlobalConfig(ctx) |
| 202 | |
Martin Stjernholm | 6d41527 | 2020-01-31 17:10:36 +0000 | [diff] [blame] | 203 | // TODO(b/148690468): The check on d.installPath is to bail out in cases where |
| 204 | // the dexpreopter struct hasn't been fully initialized before we're called, |
| 205 | // e.g. in aar.go. This keeps the behaviour that dexpreopting is effectively |
| 206 | // disabled, even if installable is true. |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 207 | if d.installPath.Base() == "." { |
| 208 | return |
| 209 | } |
| 210 | |
| 211 | dexLocation := android.InstallPathToOnDevicePath(ctx, d.installPath) |
| 212 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 213 | providesUsesLib := moduleName(ctx) |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 214 | if ulib, ok := ctx.Module().(ProvidesUsesLib); ok { |
| 215 | name := ulib.ProvidesUsesLib() |
| 216 | if name != nil { |
| 217 | providesUsesLib = *name |
| 218 | } |
| 219 | } |
| 220 | |
Jeongik Cha | 4b073cd | 2021-06-08 11:35:00 +0900 | [diff] [blame] | 221 | // If it is test, make config files regardless of its dexpreopt setting. |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 222 | // The config files are required for apps defined in make which depend on the lib. |
Jeongik Cha | 4b073cd | 2021-06-08 11:35:00 +0900 | [diff] [blame] | 223 | if d.isTest && d.dexpreoptDisabled(ctx) { |
Jaewoong Jung | 4b97a56 | 2020-12-17 09:43:28 -0800 | [diff] [blame] | 224 | return |
Nicolas Geoffray | fa6e9ec | 2019-02-12 13:12:16 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 227 | isSystemServerJar := global.SystemServerJars.ContainsJar(moduleName(ctx)) || |
| 228 | global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 229 | |
Colin Cross | 44df581 | 2019-02-15 23:06:46 -0800 | [diff] [blame] | 230 | bootImage := defaultBootImageConfig(ctx) |
Vladimir Marko | 40139d6 | 2020-02-06 15:14:29 +0000 | [diff] [blame] | 231 | if global.UseArtImage { |
| 232 | bootImage = artBootImageConfig(ctx) |
| 233 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 234 | |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 235 | // System server jars are an exception: they are dexpreopted without updatable bootclasspath. |
| 236 | dexFiles, dexLocations := bcpForDexpreopt(ctx, global.PreoptWithUpdatableBcp && !isSystemServerJar) |
| 237 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 238 | targets := ctx.MultiTargets() |
| 239 | if len(targets) == 0 { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 240 | // assume this is a java library, dexpreopt for all arches for now |
| 241 | for _, target := range ctx.Config().Targets[android.Android] { |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 242 | if target.NativeBridge == android.NativeBridgeDisabled { |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 243 | targets = append(targets, target) |
dimitry | 1f33e40 | 2019-03-26 12:39:31 +0100 | [diff] [blame] | 244 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 245 | } |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 246 | if isSystemServerJar && !d.isSDKLibrary { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 247 | // If the module is not an SDK library and it's a system server jar, only preopt the primary arch. |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 248 | targets = targets[:1] |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 249 | } |
| 250 | } |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 251 | |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 252 | var archs []android.ArchType |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 253 | var images android.Paths |
Ulya Trafimovich | 4d2eeed | 2019-11-08 10:54:21 +0000 | [diff] [blame] | 254 | var imagesDeps []android.OutputPaths |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 255 | for _, target := range targets { |
| 256 | archs = append(archs, target.Arch.ArchType) |
| 257 | variant := bootImage.getVariant(target) |
Jeongik Cha | a596909 | 2021-05-07 18:53:21 +0900 | [diff] [blame] | 258 | images = append(images, variant.imagePathOnHost) |
David Srbecky | c177ebe | 2020-02-18 20:43:06 +0000 | [diff] [blame] | 259 | imagesDeps = append(imagesDeps, variant.imagesDeps) |
Colin Cross | c7e40aa | 2019-02-08 21:37:00 -0800 | [diff] [blame] | 260 | } |
David Srbecky | ab99498 | 2020-03-30 17:24:13 +0100 | [diff] [blame] | 261 | // The image locations for all Android variants are identical. |
Jeongik Cha | 4dda75e | 2021-04-27 23:56:44 +0900 | [diff] [blame] | 262 | hostImageLocations, deviceImageLocations := bootImage.getAnyAndroidVariant().imageLocations() |
Colin Cross | c7e40aa | 2019-02-08 21:37:00 -0800 | [diff] [blame] | 263 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 264 | var profileClassListing android.OptionalPath |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 265 | var profileBootListing android.OptionalPath |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 266 | profileIsTextListing := false |
| 267 | if BoolDefault(d.dexpreoptProperties.Dex_preopt.Profile_guided, true) { |
| 268 | // If dex_preopt.profile_guided is not set, default it based on the existence of the |
| 269 | // dexprepot.profile option or the profile class listing. |
| 270 | if String(d.dexpreoptProperties.Dex_preopt.Profile) != "" { |
| 271 | profileClassListing = android.OptionalPathForPath( |
| 272 | android.PathForModuleSrc(ctx, String(d.dexpreoptProperties.Dex_preopt.Profile))) |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 273 | profileBootListing = android.ExistentPathForSource(ctx, |
| 274 | ctx.ModuleDir(), String(d.dexpreoptProperties.Dex_preopt.Profile)+"-boot") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 275 | profileIsTextListing = true |
Dan Willemsen | 78d51b0 | 2020-06-24 16:33:31 -0700 | [diff] [blame] | 276 | } else if global.ProfileDir != "" { |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 277 | profileClassListing = android.ExistentPathForSource(ctx, |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 278 | global.ProfileDir, moduleName(ctx)+".prof") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Ulya Trafimovich | 76b0852 | 2021-01-14 17:52:43 +0000 | [diff] [blame] | 282 | // Full dexpreopt config, used to create dexpreopt build rules. |
Martin Stjernholm | 8d80cee | 2020-01-31 17:44:54 +0000 | [diff] [blame] | 283 | dexpreoptConfig := &dexpreopt.ModuleConfig{ |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 284 | Name: moduleName(ctx), |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 285 | DexLocation: dexLocation, |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 286 | BuildPath: android.PathForModuleOut(ctx, "dexpreopt", moduleName(ctx)+".jar").OutputPath, |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 287 | DexPath: dexJarFile, |
Jeongik Cha | 33a3a81 | 2021-04-15 09:12:49 +0900 | [diff] [blame] | 288 | ManifestPath: android.OptionalPathForPath(d.manifestFile), |
Victor Hsieh | d181c8b | 2019-01-29 13:00:33 -0800 | [diff] [blame] | 289 | UncompressedDex: d.uncompressedDex, |
| 290 | HasApkLibraries: false, |
| 291 | PreoptFlags: nil, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 292 | |
Colin Cross | 69f59a3 | 2019-02-15 10:39:37 -0800 | [diff] [blame] | 293 | ProfileClassListing: profileClassListing, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 294 | ProfileIsTextListing: profileIsTextListing, |
Nicolas Geoffray | e710242 | 2019-07-24 13:19:29 +0100 | [diff] [blame] | 295 | ProfileBootListing: profileBootListing, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 296 | |
Ulya Trafimovich | 8c35fcf | 2021-02-17 16:23:28 +0000 | [diff] [blame] | 297 | EnforceUsesLibrariesStatusFile: dexpreopt.UsesLibrariesStatusFile(ctx), |
| 298 | EnforceUsesLibraries: d.enforceUsesLibs, |
| 299 | ProvidesUsesLibrary: providesUsesLib, |
| 300 | ClassLoaderContexts: d.classLoaderContexts, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 301 | |
Jeongik Cha | 4dda75e | 2021-04-27 23:56:44 +0900 | [diff] [blame] | 302 | Archs: archs, |
| 303 | DexPreoptImagesDeps: imagesDeps, |
| 304 | DexPreoptImageLocationsOnHost: hostImageLocations, |
| 305 | DexPreoptImageLocationsOnDevice: deviceImageLocations, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 306 | |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame] | 307 | PreoptBootClassPathDexFiles: dexFiles.Paths(), |
Vladimir Marko | 40139d6 | 2020-02-06 15:14:29 +0000 | [diff] [blame] | 308 | PreoptBootClassPathDexLocations: dexLocations, |
Colin Cross | 800fe13 | 2019-02-11 14:21:24 -0800 | [diff] [blame] | 309 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 310 | PreoptExtractedApk: false, |
| 311 | |
| 312 | NoCreateAppImage: !BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, true), |
| 313 | ForceCreateAppImage: BoolDefault(d.dexpreoptProperties.Dex_preopt.App_image, false), |
| 314 | |
Jaewoong Jung | ccbb393 | 2019-04-15 09:48:31 -0700 | [diff] [blame] | 315 | PresignedPrebuilt: d.isPresignedPrebuilt, |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Jeongik Cha | c624667 | 2021-04-08 00:00:19 +0900 | [diff] [blame] | 318 | d.configPath = android.PathForModuleOut(ctx, "dexpreopt", "dexpreopt.config") |
| 319 | dexpreopt.WriteModuleConfig(ctx, dexpreoptConfig, d.configPath) |
| 320 | |
| 321 | if d.dexpreoptDisabled(ctx) { |
| 322 | return |
| 323 | } |
| 324 | |
| 325 | globalSoong := dexpreopt.GetGlobalSoongConfig(ctx) |
| 326 | |
Martin Stjernholm | 75a48d8 | 2020-01-10 20:32:59 +0000 | [diff] [blame] | 327 | dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, dexpreoptConfig) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 328 | if err != nil { |
| 329 | ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error()) |
Jaewoong Jung | 4b97a56 | 2020-12-17 09:43:28 -0800 | [diff] [blame] | 330 | return |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 333 | dexpreoptRule.Build("dexpreopt", "dexpreopt") |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 334 | |
Jiakai Zhang | ca9bc98 | 2021-09-09 08:09:41 +0000 | [diff] [blame^] | 335 | if global.ApexSystemServerJars.ContainsJar(moduleName(ctx)) { |
| 336 | // APEX variants of java libraries are hidden from Make, so their dexpreopt outputs need special |
| 337 | // handling. Currently, for APEX variants of java libraries, only those in the system server |
| 338 | // classpath are handled here. Preopting of boot classpath jars in the ART APEX are handled in |
| 339 | // java/dexpreopt_bootjars.go, and other APEX jars are not preopted. |
| 340 | for _, install := range dexpreoptRule.Installs() { |
| 341 | // Remove the "/" prefix because the path should be relative to $ANDROID_PRODUCT_OUT. |
| 342 | installDir := strings.TrimPrefix(filepath.Dir(install.To), "/") |
| 343 | installBase := filepath.Base(install.To) |
| 344 | arch := filepath.Base(installDir) |
| 345 | installPath := android.PathForModuleInPartitionInstall(ctx, "", installDir) |
| 346 | // The installs will be handled by Make as sub-modules of the java library. |
| 347 | d.builtInstalledForApex = append(d.builtInstalledForApex, dexpreopterInstall{ |
| 348 | name: arch + "-" + installBase, |
| 349 | moduleName: moduleName(ctx), |
| 350 | outputPathOnHost: install.From, |
| 351 | installDirOnDevice: installPath, |
| 352 | installFileOnDevice: installBase, |
| 353 | }) |
| 354 | } |
| 355 | } else { |
| 356 | // The installs will be handled by Make as LOCAL_SOONG_BUILT_INSTALLED of the java library |
| 357 | // module. |
| 358 | d.builtInstalled = dexpreoptRule.Installs().String() |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | func (d *dexpreopter) DexpreoptBuiltInstalledForApex() []dexpreopterInstall { |
| 363 | return d.builtInstalledForApex |
| 364 | } |
| 365 | |
| 366 | func (d *dexpreopter) AndroidMkEntriesForApex() []android.AndroidMkEntries { |
| 367 | var entries []android.AndroidMkEntries |
| 368 | for _, install := range d.builtInstalledForApex { |
| 369 | install := install |
| 370 | entries = append(entries, android.AndroidMkEntries{ |
| 371 | Class: "ETC", |
| 372 | SubName: install.SubModuleName(), |
| 373 | OutputFile: android.OptionalPathForPath(install.outputPathOnHost), |
| 374 | ExtraEntries: []android.AndroidMkExtraEntriesFunc{ |
| 375 | func(ctx android.AndroidMkExtraEntriesContext, entries *android.AndroidMkEntries) { |
| 376 | entries.SetString("LOCAL_MODULE_PATH", install.installDirOnDevice.ToMakePath().String()) |
| 377 | entries.SetString("LOCAL_INSTALLED_MODULE_STEM", install.installFileOnDevice) |
| 378 | entries.SetString("LOCAL_NOT_AVAILABLE_FOR_PLATFORM", "false") |
| 379 | }, |
| 380 | }, |
| 381 | }) |
| 382 | } |
| 383 | return entries |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 384 | } |