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